Skip to content

Commit 723eb35

Browse files
committed
Add CI, linting, and automatic versioning
1 parent 23e36c2 commit 723eb35

File tree

9 files changed

+219
-15
lines changed

9 files changed

+219
-15
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: ci
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
schedule:
8+
- cron: "0 0 * * *"
9+
jobs:
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [
15+
ubuntu-latest,
16+
# macos-latest,
17+
# windows-latest
18+
]
19+
python-version: ["3.6", "3.7", "3.8", "3.9"]
20+
steps:
21+
- uses: actions/checkout@v2
22+
with:
23+
lfs: true
24+
submodules: true
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v2
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
- name: Install tox
30+
run: |
31+
pip install --upgrade pip
32+
pip install tox
33+
- name: Run linting tests
34+
if: ${{ matrix.os == 'ubuntu-latest' }}
35+
run: |
36+
tox -e lint,type
37+
- name: Run pytest tests
38+
run: |
39+
tox -e test

.github/workflows/release.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: release
2+
on:
3+
release:
4+
types: [published]
5+
jobs:
6+
publish:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
matrix:
10+
os: [ubuntu-latest, macos-latest, windows-latest]
11+
python-version: ["3.6", "3.7", "3.8", "3.9"]
12+
# Linux builds don't need to run across different Python versions,
13+
# they will all be installed under the manylinux action
14+
exclude:
15+
- os: ubuntu-latest
16+
python-version: "3.6"
17+
- os: ubuntu-latest
18+
python-version: "3.7"
19+
- os: ubuntu-latest
20+
python-version: "3.8"
21+
- os: ubuntu-latest
22+
python-version: "3.9"
23+
# Use the latest Python version as a base for Linux builds
24+
include:
25+
- os: ubuntu-latest
26+
python-version: "3.x"
27+
steps:
28+
- uses: actions/checkout@v2
29+
with:
30+
lfs: true
31+
submodules: true
32+
# Tags are needed to compute the current version number
33+
fetch-depth: 0
34+
- name: Set up Python ${{ matrix.python-version }}
35+
uses: actions/setup-python@v2
36+
with:
37+
python-version: ${{ matrix.python-version }}
38+
- name: Install tox and pypa-build
39+
run: |
40+
pip install --upgrade pip
41+
pip install tox build
42+
- name: Build sdist
43+
# Do this before the manylinux build, so the output directory doesn't get created by Docker
44+
if: ${{ matrix.os == 'ubuntu-latest' }}
45+
run: |
46+
pyproject-build --sdist
47+
- name: Build manylinux wheels
48+
if: ${{ matrix.os == 'ubuntu-latest' }}
49+
uses: RalfG/[email protected]_x86_64
50+
with:
51+
python-versions: 'cp36-cp36m cp37-cp37m cp38-cp38 cp39-cp39'
52+
# Necessary for setuptools_scm to read the version from Git
53+
system-packages: 'git-lfs'
54+
- name: Remove non-manylinux wheels
55+
if: ${{ matrix.os == 'ubuntu-latest' }}
56+
# Those are built as intermediate artifacts, but should not be published
57+
# Since these are built by Docker, they must be removed with sudo
58+
run: |
59+
sudo rm -f dist/*-linux*.whl
60+
- name: Build non-Linux wheels
61+
if: ${{ matrix.os != 'ubuntu-latest' }}
62+
run: |
63+
pyproject-build --wheel
64+
- name: Publish to PyPI
65+
env:
66+
TWINE_USERNAME: "__token__"
67+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
68+
TWINE_NON_INTERACTIVE: "true"
69+
run: |
70+
tox -e release

MANIFEST.in

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
prune test/
1+
# Reset the auto-include from setuptools_scm
2+
exclude *
3+
prune *
4+
5+
# Re-include files which setuptools auto-includes
6+
include MANIFEST.in pyproject.toml README.md setup.py
7+
graft *.egg-info
8+
9+
# Include the module
10+
graft hashstate

hashstate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from ._hashstate import *
1+
from ._hashstate import * # noqa: F401, F403

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mypy]
2+
ignore_missing_imports = True
3+
show_error_codes = True

pyproject.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[build-system]
2+
requires = ["setuptools >= 42", "wheel", "setuptools-scm[toml]>=3.4"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.setuptools_scm]
6+
7+
[tool.black]
8+
line-length = 100
9+
skip-string-normalization = true
10+
target-version = ["py38"]
11+
exclude='\.eggs|\.git|\.mypy_cache|\.tox|\.venv|_build|buck-out|build|dist'
12+
13+
[tool.isort]
14+
profile = "black"
15+
line_length = 100
16+
# Sort by name, don't cluster "from" vs "import"
17+
force_sort_within_sections = true
18+
# Combines "as" imports on the same line
19+
combine_as_imports = true

setup.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
from setuptools import setup, Extension
1+
from setuptools import Extension, setup
22

33
with open('README.md') as f:
44
readme = f.read()
55

6-
c_ext = Extension(
7-
'hashstate._hashstate',
8-
sources=['hashstate/_hashstate.c'],
9-
libraries=['ssl']
10-
)
6+
c_ext = Extension('hashstate._hashstate', sources=['hashstate/_hashstate.c'], libraries=['ssl'])
117

128
setup(
139
name='hashstate',
14-
version='0.2.1',
1510
description='Serializable hash objects',
1611
url='https://github.com/zachmullen/hashstate',
1712
license='MIT',
@@ -25,6 +20,6 @@
2520
'Intended Audience :: Developers',
2621
'Operating System :: OS Independent',
2722
'Programming Language :: Python',
28-
'Programming Language :: Python :: 3'
29-
]
23+
'Programming Language :: Python :: 3',
24+
],
3025
)

test/test_hashstate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import hashstate
21
import pytest
32

3+
import hashstate
4+
45
ALGS = {'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512'}
56

67

tox.ini

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,75 @@
11
[tox]
2-
envlist = py
2+
# Build in an environment which respects PEP 518
3+
isolated_build = true
4+
envlist =
5+
lint,
6+
type,
7+
test,
38

4-
[testenv]
5-
deps = pytest
9+
[testenv:lint]
10+
skipsdist = true
11+
skip_install = true
12+
deps =
13+
flake8
14+
flake8-black
15+
flake8-bugbear
16+
flake8-docstrings
17+
flake8-isort
18+
flake8-quotes
19+
pep8-naming
620
commands =
21+
flake8 {posargs:.}
22+
23+
[testenv:type]
24+
skipsdist = true
25+
skip_install = true
26+
deps =
27+
mypy
28+
commands =
29+
mypy {posargs:.}
30+
31+
[testenv:format]
32+
skipsdist = true
33+
skip_install = true
34+
deps =
35+
black
36+
isort
37+
commands =
38+
isort {posargs:.}
39+
black {posargs:.}
40+
41+
[testenv:test]
42+
deps =
743
pytest
44+
commands =
45+
pytest {posargs}
46+
47+
[testenv:release]
48+
skipsdist = true
49+
skip_install = true
50+
passenv =
51+
TWINE_USERNAME
52+
TWINE_PASSWORD
53+
TWINE_NON_INTERACTIVE
54+
deps =
55+
twine
56+
commands =
57+
# Don't build any packages, that's done in a more particular way by CI
58+
twine check dist/*
59+
twine upload --skip-existing dist/*
60+
61+
[flake8]
62+
max-line-length = 100
63+
show-source = True
64+
ignore =
65+
# closing bracket does not match indentation of opening bracket’s line
66+
E123
67+
# whitespace before ':'
68+
E203,
69+
# line break before binary operator
70+
W503,
71+
# Missing docstring in *
72+
D10,
73+
74+
[pytest]
75+
addopts = --strict-markers --showlocals --verbose

0 commit comments

Comments
 (0)