Skip to content

Commit

Permalink
Merge pull request #23 from icgood/hatch
Browse files Browse the repository at this point in the history
Use hatch scripts instead of invoke
  • Loading branch information
icgood committed Apr 22, 2023
2 parents f6b8a10 + 56e85fd commit db44395
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 287 deletions.
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ extend-select = B901, B902, B903, B904
extend-ignore = ANN101, ANN102
per-file-ignores =
test/*: ANN
tasks/*: ANN, B028
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build
name: check

on:
push:
Expand All @@ -8,8 +8,8 @@ on:

jobs:
build:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
Expand All @@ -23,33 +23,13 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install build tools
run: |
python -m pip install --upgrade pip invoke coveralls
- name: Install package and dependencies
run: |
invoke install
python -m pip install hatch coveralls
- name: Run test suites, type checks, and linters
run: |
invoke validate
hatch run check
- name: Report test coverage to Coveralls
if: success()
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
coveralls --service=github
docs:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install build tools
run: |
python -m pip install --upgrade pip invoke
- name: Build the Sphinx documentation
run: |
invoke install doc.install doc.build
32 changes: 32 additions & 0 deletions .github/workflows/python-doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: doc

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
release:
types: [ published ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install build tools
run: |
python -m pip install hatch
- name: Build the Sphinx documentation
run: |
hatch run doc:build
- name: Deploy to GitHub Pages
if: github.event_name == 'release'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ github.token }}
publish_dir: ./doc/build/html
38 changes: 8 additions & 30 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:

jobs:
deploy:

runs-on: ubuntu-latest

steps:
Expand All @@ -17,34 +16,13 @@ jobs:
python-version: '3.11'
- name: Install build tools
run: |
python -m pip install --upgrade pip build twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python -m build
twine upload dist/*
docs:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install build tools
python -m pip install hatch
- name: Build distributions
run: |
python -m pip install --upgrade pip invoke
- name: Build the Sphinx documentation
hatch build
- name: Publish distributions
env:
HATCH_INDEX_USER: ${{ secrets.PYPI_USERNAME }}
HATCH_INDEX_AUTH: ${{ secrets.PYPI_PASSWORD }}
run: |
invoke install doc.install doc.build
- name: Deploy to GitHub Pages
if: success()
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ github.token }}
publish_dir: ./doc/build/html
hatch publish
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,20 @@ synchronize larger amounts of metadata.

## Development

First off, I suggest activating a [venv][3]. Then, install the development
requirements and a local link to the *swim-protocol* package:
You will need to do some additional setup to develop and test plugins. Install
[Hatch][3] to use the CLI examples below.

Run all tests and linters:

```console
$ hatch run check
```
$ pip install -r requirements-dev.txt

Because this project supports several versions of Python, you can use the
following to run the checks on all versions:

```console
$ hatch run all:check
```

### Type Hinting
Expand All @@ -152,7 +161,7 @@ hinting to the extent possible and common in the rest of the codebase.
[0]: https://www.cs.cornell.edu/projects/Quicksilver/public_pdfs/SWIM.pdf
[1]: https://docs.python.org/3/library/asyncio.html
[2]: https://github.com/icgood/swim-protocol/blob/main/swimprotocol/demo/__init__.py
[3]: https://docs.python.org/3/library/venv.html
[3]: https://hatch.pypa.io/latest/install/
[4]: https://docs.python.org/3/library/typing.html
[5]: http://mypy-lang.org/
[6]: https://en.wikipedia.org/wiki/Eventual_consistency
Expand Down
3 changes: 0 additions & 3 deletions doc/requirements.txt

This file was deleted.

51 changes: 44 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ build-backend = 'hatchling.build'

[project]
name = 'swim-protocol'
version = '0.3.11'
dynamic = ['version']
authors = [
{ name = 'Ian Good', email = 'ian@icgood.net' },
]
Expand All @@ -47,20 +47,24 @@ dependencies = [
'importlib-metadata; python_version < "3.10"',
]

[project.optional-dependencies]
crc32c = ['crc32c ~= 2.2']

[project.urls]
homepage = 'https://github.com/icgood/swim-protocol/'
'Homepage' = 'https://github.com/icgood/swim-protocol/'
'API Documentation' = 'https://icgood.github.io/swim-protocol/'

[project.scripts]
swim-protocol-demo = 'swimprotocol.demo:main'

[tool.hatch.version]
path = 'swimprotocol/__about__.py'

[project.entry-points.'swimprotocol.transport']
udp = 'swimprotocol.udp:UdpTransport'

[tool.hatch.build]
exclude = ['/tasks', '/doc', '/.github']
exclude = ['/doc', '/.github']

[tool.hatch.build.targets.wheel]
packages = ['swimprotocol']

[tool.mypy]
strict = true
Expand All @@ -74,10 +78,43 @@ testpaths = 'test'
norecursedirs = 'doc'

[tool.coverage.report]
omit = ['*/main.py', '*/demo.py']
omit = ['*/__about__.py', '*/main.py', '*/demo.py']
exclude_lines = [
'pragma: no cover',
'NotImplemented',
'^\s*...\s*$',
'def __repr__',
]

[tool.hatch.envs.default]
dependencies = [
'mypy',
'pytest',
'pytest-asyncio',
'pytest-cov',
'flake8',
'flake8-annotations',
'flake8-bugbear',
'bandit[toml]',
]

[tool.hatch.envs.default.scripts]
run-pytest = 'py.test --cov-report=term-missing --cov=swimprotocol'
run-mypy = 'mypy swimprotocol test'
run-flake8 = 'flake8 swimprotocol test'
run-bandit = 'bandit -c pyproject.toml -qr swimprotocol'
check = ['run-pytest', 'run-mypy', 'run-flake8', 'run-bandit']

[[tool.hatch.envs.all.matrix]]
python = ['3.9', '3.10', '3.11']

[tool.hatch.envs.doc]
dependencies = [
'sphinx',
'sphinx-autodoc-typehints',
'cloud_sptheme',
]

[tool.hatch.envs.doc.scripts]
build = 'make -C doc html'
browse = ['build', 'open doc/build/html/index.html']
12 changes: 0 additions & 12 deletions requirements-dev.txt

This file was deleted.

2 changes: 2 additions & 0 deletions swimprotocol/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#: The package version string.
__version__ = '0.3.12'
12 changes: 0 additions & 12 deletions swimprotocol/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@

from __future__ import annotations

from importlib.metadata import distribution

__all__ = ['__version__']

#: The package version string.
#:
#: See Also:
#: `PEP 396 <https://www.python.org/dev/peps/pep-0396/>`_
__version__: str = distribution('swim-protocol').version
2 changes: 1 addition & 1 deletion swimprotocol/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import uuid
from typing import Final, Union

from . import __version__
from .__about__ import __version__

__all__ = ['Signatures']

Expand Down
71 changes: 0 additions & 71 deletions tasks/__init__.py

This file was deleted.

19 changes: 0 additions & 19 deletions tasks/check.py

This file was deleted.

0 comments on commit db44395

Please sign in to comment.