Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github actions, pre-commit #43

Merged
merged 3 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ optional_value = stable
values =
dev
stable

17 changes: 17 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[flake8]
# Ignore style and complexity
# E: style errors
# W: style warnings
# C: complexity
# F401: module imported but unused
# F403: import *
# F811: redefinition of unused `name` from line `N`
# F841: local variable assigned but never used
# E402: module level import not at top of file
# I100: Import statements are in the wrong order
# I101: Imported names are in the wrong order
ignore = E, C, W, F401, F403, F811, F841, E402, I100, I101, D400
exclude =
.cache,
.github,
build
35 changes: 35 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Build releases and (on tags) publish to PyPI
name: Release

# always build releases (to make sure wheel-building works)
# but only publish to PyPI on tags
on:
push:
pull_request:

jobs:
build-release:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8

- name: install build package
run: |
pip install --upgrade pip
pip install build
pip freeze

- name: build release
run: |
python -m build --sdist --wheel .
ls -l dist

- name: publish to pypi
uses: pypa/[email protected]
if: startsWith(github.ref, 'refs/tags/')
with:
user: __token__
password: ${{ secrets.pypi_password }}
64 changes: 64 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Test

on:
pull_request:
push:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]

test:
runs-on: ${{ matrix.os }}

strategy:
# Keep running even if one variation of the job fail
fail-fast: false
matrix:
os:
- ubuntu-20.04
python:
- "2.7"
- "3.6"
- "3.7"
- "3.8"
- "3.9"
include:
- os: macos-latest
python: 3.8

steps:
- uses: actions/checkout@v2

- name: Install Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

# preserve pip cache to speed up installation
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('*requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install Python dependencies
run: |
pip install --upgrade pip
pip install --upgrade --pre -r dev-requirements.txt .
pip freeze

- name: Run tests
run: |
pytest -v --color=yes --cov=wurlitzer test.py

- name: Submit codecov report
run: |
codecov
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 5.6.3
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.2.1
hooks:
- id: prettier
- repo: https://gitlab.com/pycqa/flake8
rev: "3.8.4"
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: requirements-txt-fixer
43 changes: 0 additions & 43 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

> 13 June 2019

- PR: Add thread lock [`#30`](https://github.com/minrk/wurlitzer/pull/30)
- PR: Add thread lock [`#30`](https://github.com/minrk/wurlitzer/pull/30)
- update packages on travis [`#31`](https://github.com/minrk/wurlitzer/pull/31)
- test on mac [`#25`](https://github.com/minrk/wurlitzer/pull/25)
- select.poll timeout is in milliseconds [`#26`](https://github.com/minrk/wurlitzer/pull/26)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Capture C-level stdout/stderr pipes in Python via `os.dup2`.

For more details on why this is needed, please read [this blog post]( https://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/ ).
For more details on why this is needed, please read [this blog post](https://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/).

## Install

Expand Down
4 changes: 2 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
codecov
pytest-cov
mock # python_version < '3.0'
pytest>=2.8
mock
pytest-cov
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tool.isort]
profile = "black"

[tool.black]
skip-string-normalization = true
target_version = [
"py27",
"py36",
"py37",
"py38",
]
5 changes: 1 addition & 4 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@
set -e

bumpversion release --tag
py.test test.py
python setup.py sdist bdist_wheel
twine upload dist/*
bumpversion patch

git push --follow-tags
32 changes: 26 additions & 6 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,38 @@

import io
import os
from tempfile import TemporaryFile
import time
from tempfile import TemporaryFile

import mock
try:
from unitest import mock
except ImportError:
import mock

from wurlitzer import (
libc, pipes, STDOUT, PIPE, c_stderr_p, c_stdout_p,
sys_pipes, sys_pipes_forever,
stop_sys_pipes,
PIPE,
STDOUT,
Wurlitzer,
c_stderr_p,
c_stdout_p,
libc,
pipes,
stop_sys_pipes,
sys_pipes,
sys_pipes_forever,
)


def printf(msg):
"""Call C printf"""
libc.printf((msg + '\n').encode('utf8'))


def printf_err(msg):
"""Cal C fprintf on stderr"""
libc.fprintf(c_stderr_p, (msg + '\n').encode('utf8'))


def test_pipes():
with pipes(stdout=PIPE, stderr=PIPE) as (stdout, stderr):
printf(u"Hellø")
Expand All @@ -31,6 +43,7 @@ def test_pipes():
assert stdout.read() == u"Hellø\n"
assert stderr.read() == u"Hi, stdérr\n"


def test_pipe_bytes():
with pipes(encoding=None) as (stdout, stderr):
printf(u"Hellø")
Expand All @@ -39,6 +52,7 @@ def test_pipe_bytes():
assert stdout.read() == u"Hellø\n".encode('utf8')
assert stderr.read() == u"Hi, stdérr\n".encode('utf8')


def test_forward():
stdout = io.StringIO()
stderr = io.StringIO()
Expand All @@ -51,6 +65,7 @@ def test_forward():
assert stdout.getvalue() == u"Hellø\n"
assert stderr.getvalue() == u"Hi, stdérr\n"


def test_pipes_stderr():
stdout = io.StringIO()
with pipes(stdout=stdout, stderr=STDOUT) as (_stdout, _stderr):
Expand All @@ -63,6 +78,7 @@ def test_pipes_stderr():

assert stdout.getvalue() == u"Hellø\nHi, stdérr\n"


def test_flush():
stdout = io.StringIO()
w = Wurlitzer(stdout=stdout, stderr=STDOUT)
Expand All @@ -71,16 +87,20 @@ def test_flush():
time.sleep(0.5)
assert stdout.getvalue().strip() == u"Hellø"


def test_sys_pipes():
stdout = io.StringIO()
stderr = io.StringIO()
with mock.patch('sys.stdout', stdout), mock.patch('sys.stderr', stderr), sys_pipes():
with mock.patch('sys.stdout', stdout), mock.patch(
'sys.stderr', stderr
), sys_pipes():
printf(u"Hellø")
printf_err(u"Hi, stdérr")

assert stdout.getvalue() == u"Hellø\n"
assert stderr.getvalue() == u"Hi, stdérr\n"


def test_redirect_everything():
stdout = io.StringIO()
stderr = io.StringIO()
Expand Down
Loading