Skip to content

Commit

Permalink
Use hatch for tests/builds instead of tox
Browse files Browse the repository at this point in the history
  • Loading branch information
nisimond committed Aug 10, 2023
1 parent 5c74049 commit 0e63548
Show file tree
Hide file tree
Showing 22 changed files with 2,103 additions and 340 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v2
Expand All @@ -22,9 +22,9 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
pip install hatch
- name: Run Tox
- name: Run Hatch
run: |
tox
hatch run ci
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"python.pythonPath": "${workspaceFolder}/.tox/py3/bin/python3",
"python.pythonPath": "${workspaceFolder}/.hatch/bin/python3",
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
Expand All @@ -19,7 +19,8 @@
"**/.eggs": true,
"**/.stestr/**": true,
"**/.testrepository/**": true,
"**/.tox/**": true
"**/.tox/**": true,
"**/.hatch/**": true
},
"git.allowForcePush": true,
"editor.wordWrapColumn": 79,
Expand Down
22 changes: 11 additions & 11 deletions HACKING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,59 @@ Hacking on Soufi
Running tests
-------------

The test suite can be run via the `tox` utility:
The test suite can be run via the `hatch` utility:


::

tox
hatch run ci

will run the Python 3 tests, the PEP8 tests, Bandit (security
checker), and code formatting checks. Test coverage is also displayed
and without 100% test coverage the tests will fail.

::

tox -e py3 -- <test pattern>
hatch run py3 -- <test pattern>

will run a subset of tests matching <test pattern>.

::

tox -e debug
hatch run debug

runs all tests serially in debug mode allowing the use of debuggers like pdb.

::

tox -e test soufi.tests.test_file.TestClass.test_name
hatch run test soufi.tests.test_file.TestClass.test_name

runs a single test in debug mode.

::

tox -e failing
hatch run failing

runs only the tests that failed in the previous run.

Other handy tox targets:
Other handy hatch targets:

::

tox -e repl
hatch run ipython

gives you an ipython prompt in the virtualenv used by tox.
gives you an ipython prompt in the virtualenv used by hatch.

::

tox -e format
hatch run format

reformats the code using Black and sorts imports using isort.
Tests will not pass if there are errors, which you can check using

::

tox -e formatcheck
hatch run check


Code structure
Expand Down
9 changes: 0 additions & 9 deletions MANIFEST.in

This file was deleted.

2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you want to download Alpine packages, you must have `git` installed.

Requirements
------------
Soufi is currently tested on Python versions 3.7, 3.8 and 3.9. It is
Soufi is currently tested on Python versions 3.8 through 3.11. It is
known not to work on 3.6.


Expand Down
8 changes: 4 additions & 4 deletions RELEASING.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ To release a new version of Soufi:
2. Tag the current revision with the required release number, e.g.
`git tag 2021.09.29`
3. Build the package:
`tox -e build-python-package`
`hatch build`
4. Upload the package to testpyi first to make sure it is ok:
`tox -e testpypi dist/*2021.9.29*`
5. I that looks ok, upload to the real pypi:
`tox -e pypi dist/*2021.9.29*`
`hatch run testpypi dist/*2021.9.29*`
5. If that looks ok, upload to the real pypi:
`hatch run pypi dist/*2021.9.29*`
6. Push the new tag to Github:
`git push origin 2021.09.29`
194 changes: 181 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,150 @@
[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "soufi"
dynamic = ["version"]
readme = "README.rst"
license = "Apache-2.0"
authors = [
{name = "Julian Edwards", email = "juledwar@cisco.com"},
]
maintainers = [
{name = "Julian Edwards", email = "juledwar@cisco.com"},
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: System Administrators",
"Natural Language :: English",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: System :: Systems Administration",
"Topic :: Utilities",
]
urls.Source = "https://github.com/juledwar/soufi"
dependencies = [
"click>=7.1.2",
"cryptography>=3.3.1",
"launchpadlib>=1.10.13",
"repomd>=0.2.1",
"requests>=2.25.1",
"requests-oauthlib>=1.3.0",
"lxml>=4.6.3",
"dogpile.cache>=1.1.5",
"pylru>=1.2.0",
]

[project.optional-dependencies]
test = [
"bandit[toml]",
"build",
"black",
"coverage[toml]",
"fixtures",
"ruff",
"ipython",
"isort",
"pdbpp",
"stestr",
"testscenarios",
"testresources",
"testtools",
"twine",
]
bootstrap = [
"pip",
"pip-tools",
"hatch",
"hatch-vcs",
"virtualenv",
"wheel",
]

[project.scripts]
soufi = "soufi:main"

[tool.hatch.version]
source = "vcs"

[tool.hatch.build]
include = ["/soufi"]
exclude = [
"soufi/tests",
"soufi/testing",
"soufi/functional",
]

[tool.hatch.build.hooks.vcs]
version-file = "soufi/_version.py"

[tool.hatch.build.targets.sdist]
include = ["/soufi"]
exclude = []

[tool.hatch.envs.default]
path = ".hatch"
features = ["test"]

# Bootstrap or upgrade an existing virtualenv:
scripts.install = [
# Install exactly what's in the locked requirements and nothing else.
"pip install -U --no-deps -r requirements/requirements-test.txt",
]
scripts.py3 = [
"export PYTHON='coverage run --source soufi --parallel-mode'; stestr run {args}",
"coverage combine",
"coverage xml -o coverage.xml",
"mkdir -p cover",
"coverage html -d cover",
"coverage report --show-missing --fail-under=100",
]
scripts.py3-failing = ["stestr run --failing"]
scripts.failing = ["py3-failing"] # convenience is king
scripts.test = ["python -m testtools.run {args}"]
scripts.debug = ["python -m testtools.run discover {args}"]
scripts.format = [
"black soufi",
"isort soufi",
]
scripts.check = [
"black --check soufi",
"isort --check soufi",
"ruff soufi",
]
scripts.bandit_ = ["bandit -c pyproject.toml -r soufi"]
# Special target to run all tests needed in CI.
scripts.ci = [
"py3",
"check",
"bandit_",
]
scripts.cover = [
"export PYTHON='coverage run --source soufi --parallel-mode'; stestr run",
]
scripts.pypi = ["python -m twine upload {args}"]
scripts.testpypi = ["python -m twine upload --repository testpypi {args}"]

scripts.functional = [
"stestr --test-path ./soufi/functional run {args}",
"stestr slowest",
]

scripts.compile-requirements = [
"docker run -e HATCH_ENV_ACTIVE=1 --rm -v {root}:/soufi python:3.8-slim bash -c 'cd /soufi; apt update && apt install -y git && tools/compile-requirements'",
]


[tool.black]
line-length = 79
target_version = ['py36']
target_version = ['py38']
skip-string-normalization = 1
# Needed for the vim plugin
string-normalization = 0
Expand All @@ -10,6 +154,7 @@ exclude = '''
\.eggs
| \.git
| .tox
| .hatch
| \.venv
| dist
| build
Expand All @@ -22,9 +167,9 @@ exclude = '''

[tool.coverage.run]
omit = [
'*soufi/tests*',
'*soufi/testing*',
'*soufi/functional*',
'soufi/tests/*',
'soufi/testing/*',
'soufi/functional/*',
'soufi/__init__.py',
'soufi/_version.py',
]
Expand All @@ -36,14 +181,37 @@ indent=' '
include_trailing_comma = true
use_parentheses = true

[build-system]
# If 'requires' is changed, update the same in setup.py.
requires = [
"setuptools>=60.5.0",
"wheel",
"setuptools-scm>=6.4.2",
[tool.ruff]
cache-dir = "~/.cache/ruff"
select = ["B", "C9", "D", "E", "F", "W"]
line-length = 79
show-source = true
target-version = "py38"
exclude = [
".git",
".tox",
".hatch",
"__pycache__",
"bin",
"lib",
"build",
"dist",
"eggs",
]
ignore = [
"D10", # ignore missing docstrings (for now)
"D202", # No blank lines allowed after function docstring (caused by Black)
"D203", # Allow One Blank Line Before Class
"D213", # Allow "Multi-line docstring summary should start at the second line"
"D406", # Allow section names without formatting
"D407", # Allow section names without formatting
"D412", # No blank lines allowed between a section header and its content (incompatible with Click)
"D301", # Use r""" if any backslashes in a docstring (incompatible with Click)
"E731", # make lambda expressions great again
"B904", # Disable stuipidly picky error about raise ... from None
]
build-backend = "setuptools.build_meta"
[tool.ruff.mccabe]
max-complexity = 13

[tool.setuptools_scm]
write_to = "soufi/_version.py"
[tool.bandit]
exclude_dirs = ["soufi/_version.py"]
9 changes: 0 additions & 9 deletions requirements.txt

This file was deleted.

Loading

0 comments on commit 0e63548

Please sign in to comment.