Skip to content

Commit

Permalink
chg: dev: move metadata to pyproject.toml, switch build system to hatch
Browse files Browse the repository at this point in the history
* update CI workflow to use hatch cmds
* add (optional) hatch env config to run tests
* fix test discovery in pytest config, add fallback version

Signed-off-by: Steve Arnold <[email protected]>
  • Loading branch information
sarnold committed Apr 14, 2024
1 parent d612b5a commit dbab737
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 11 deletions.
47 changes: 47 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[flake8]
exclude =
.git,
__pycache__,
examples,
build,
dist

max-line-length = 250
max-complexity = 10
addons = file,open,basestring,xrange,unicode,long,cmp
ignore =
# line break before binary operator
W503,
# imported but unused
F401,
# star import used; unable to detect undefined names
F403,
# may be undefined, or defined from star imports
F405,
# too many leading '#' for block comment
E266,
# whitespace before ':'
E203,
# multiple spaces before operator
E221,
# multiple spaces after operator
E222,
# multiple spaces after ','
E241,
# at least two spaces before inline comment
E261,
# multiple spaces after keyword
E271,
# multiple spaces before keyword
E272,
# too many blank lines
E303,
# expected 2 blank lines, found 1
E302,
# expected 2 blank lines after class or function definition
E305,
# do not assign a lambda expression, use a def
E731,
# allow over/under indenting for now
E126,
E121,
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
git config --global core.eol lf
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
Expand All @@ -41,13 +43,13 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine construct
pip install hatch hatch-vcs twine
- name: Run tests
run: |
python -m unittest discover -f -s .
hatch run cov
- name: Build pkgs
run: |
python -m build .
hatch build
twine check dist/*
20 changes: 20 additions & 0 deletions hatch.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[envs.default]
dependencies = [
"coverage[toml]",
"pytest",
"hatch-vcs",
]
[envs.default.scripts]
test = "pytest {args:usb_protocol}"
test-cov = "coverage run -m pytest {args:usb_protocol}"
cov-report = [
"- coverage combine",
"coverage report --show-missing",
]
cov = [
"test-cov",
"cov-report",
]

[[envs.all.matrix]]
python = ["3.7", "3.8", "3.9", "3.10", "3.11"]
87 changes: 79 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,83 @@
[build-system] # these versions are valid on python 3.7 and up
requires = [
"setuptools>=61",
"setuptools_scm[toml]>=7",
[project]
name = "usb_protocol"
description = "utilities, data structures, constants, parsers, and tools for working with USB data"
dynamic = ["version"]
dependencies = [
"construct",
'importlib-metadata; python_version < "3.8"',
]
build-backend = "setuptools.build_meta"
requires-python = ">=3.7"
authors = [
{name = "Katherine J. Temkin", email = "[email protected]"},
{name = "Antoine van Gelder", email = "[email protected]"},
]

readme = "README.md"
license = {file = "LICENSE.txt"}

classifiers = [
"Development Status :: 1 - Planning",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Environment :: Console",
"Environment :: Plugins",
"Topic :: Scientific/Engineering",
"Topic :: Software Development",
"Topic :: Security",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

[project.optional-dependencies]
doc = [
"sphinx==7.2.6",
"sphinx_rtd_theme==2.0.0",
"sphinxcontrib-apidoc",
"readthedocs-sphinx-search==0.3.2",
"jinja2==3.1.3",
]
cov = [
"coverage[toml]",
"coverage_python_version",
]
test = [
"pytest",
"pytest-cov",
]

[project.urls]
Homepage = "https://github.com/greatscottgadgets/python-usb-protocol"
Repository = "https://github.com/greatscottgadgets/python-usb-protocol.git"
Issues = "https://github.com/greatscottgadgets/python-usb-protocol/issues"

[tool.setuptools_scm]
[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[tool.hatch.version]
source = "vcs"
fallback-version = "0.0.1"

[tool.hatch.build.targets.sdist]
exclude = [
"/.github",
"/.tox",
]

[tool.hatch.build.targets.wheel]
packages = ["usb_protocol"]

[tool.pytest.ini_options]
minversion = "6.0"
testpaths = ["tests",]
python_files = "*.py"
testpaths = ["usb_protocol",]
log_cli = true
doctest_optionflags = ["ELLIPSIS", "NORMALIZE_WHITESPACE",]
addopts = "--strict-markers"
Expand All @@ -32,7 +100,7 @@ omit = [
source = ["usb_protocol"]

[tool.coverage.report]
fail_under = 50
fail_under = 80
show_missing = true

[tool.black]
Expand Down Expand Up @@ -65,3 +133,6 @@ include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true

[tool.bandit]
exclude_dirs = ["docs"]

0 comments on commit dbab737

Please sign in to comment.