Use hatch for package management

This commit is contained in:
François Voron
2022-10-18 08:32:06 +02:00
parent 8208307955
commit 21f30229dc
5 changed files with 110 additions and 142 deletions

View File

@ -11,33 +11,31 @@ jobs:
python_version: [3.7, 3.8, 3.9, '3.10'] python_version: [3.7, 3.8, 3.9, '3.10']
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v3
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v1 uses: actions/setup-python@v4
with: with:
python-version: ${{ matrix.python_version }} python-version: ${{ matrix.python_version }}
- name: Install dependencies - name: Install dependencies
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install flit pip install hatch
flit install --deps develop --extras oauth,redis hatch env create
- name: Check codestyle - name: Lint and typecheck
run: | run: |
make format-check hatch run lint-check
make lint - name: Test
- name: Typecheck
run: | run: |
make typecheck hatch run test-cov-xml
- name: Test with pytest - uses: codecov/codecov-action@v2
env: with:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} token: ${{ secrets.CODECOV_TOKEN }}
run: | fail_ci_if_error: true
pytest --cov=fastapi_users/ verbose: true
codecov
- name: Build and install it on system host - name: Build and install it on system host
run: | run: |
flit build --setup-py hatch build
flit install --deps none --python $(which python) pip install dist/fastapi_users-*.whl
python test_build.py python test_build.py
release: release:
@ -46,19 +44,20 @@ jobs:
if: startsWith(github.ref, 'refs/tags/') if: startsWith(github.ref, 'refs/tags/')
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v3
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v1 uses: actions/setup-python@v4
with: with:
python-version: 3.7 python-version: 3.7
- name: Install dependencies - name: Install dependencies
shell: bash
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install flit pip install hatch
flit install --deps develop --extras oauth,redis - name: Build and publish on PyPI
- name: Release on PyPI
env: env:
FLIT_USERNAME: ${{ secrets.FLIT_USERNAME }} HATCH_INDEX_USER: ${{ secrets.HATCH_INDEX_USER }}
FLIT_PASSWORD: ${{ secrets.FLIT_PASSWORD }} HATCH_INDEX_AUTH: ${{ secrets.HATCH_INDEX_AUTH }}
run: | run: |
flit publish --setup-py hatch build
hatch publish

View File

@ -14,16 +14,16 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Set up Python 3.7 - name: Set up Python 3.7
uses: actions/setup-python@v3 uses: actions/setup-python@v4
with: with:
python-version: 3.7 python-version: 3.7
- name: Install dependencies - name: Install dependencies
shell: bash
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install flit pip install hatch
flit install --deps develop --extras oauth,redis
- name: Build - name: Build
run: mkdocs build run: hatch run mkdocs build
- name: Parse tag - name: Parse tag
id: version_tag id: version_tag
uses: battila7/get-version-action@v2 uses: battila7/get-version-action@v2

View File

@ -1,52 +0,0 @@
install:
python -m pip install --upgrade pip
pip install flit
flit install --deps develop --extras oauth,redis
isort-src:
isort ./fastapi_users ./tests
isort-docs:
isort ./docs/src -o fastapi_users
isort-examples:
isort ./examples -o fastapi_users -p app
format: isort-src isort-docs isort-examples
black .
isort-src-check:
isort --check-only ./fastapi_users ./tests
isort-docs-check:
isort --check-only ./docs/src -o fastapi_users
isort-examples-check:
isort --check-only ./examples -o fastapi_users -p app
format-check: isort-src-check isort-docs-check isort-examples-check
black --check .
lint:
flake8 ./fastapi_users ./tests
typecheck:
mypy fastapi_users/
test:
pytest --cov=fastapi_users/ --cov-report=term-missing --cov-fail-under=100
docs-serve:
mkdocs serve
docs-publish:
mkdocs gh-deploy
bumpversion-major:
bumpversion major
bumpversion-minor:
bumpversion minor
bumpversion-patch:
bumpversion patch

View File

@ -178,40 +178,14 @@ This project follows the [all-contributors](https://github.com/all-contributors/
### Setup environment ### Setup environment
You should create a virtual environment and activate it: We use [Hatch](https://hatch.pypa.io/latest/install/) to manage the development environment and production build. Ensure it's installed on your system.
```bash
python -m venv venv/
```
```bash
source venv/bin/activate
```
And then install the development dependencies:
```bash
make install
```
### Run unit tests ### Run unit tests
You can run all the tests with: You can run all the tests with:
```bash ```bash
make test hatch run test
```
Alternatively, you can run `pytest` yourself.
```bash
pytest
```
There are quite a few unit tests, so you might run into ulimit issues where there are too many open file descriptors. You may be able to set a new, higher limit temporarily with:
```bash
ulimit -n 2048
``` ```
### Format the code ### Format the code
@ -219,9 +193,19 @@ ulimit -n 2048
Execute the following command to apply `isort` and `black` formatting: Execute the following command to apply `isort` and `black` formatting:
```bash ```bash
make format hatch run lint
``` ```
### Serve the documentation
You can serve the documentation locally with the following command:
```bash
hatch run docs
```
The documentation will be available on [http://localhost:8000](http://localhost:8000).
## License ## License
This project is licensed under the terms of the MIT license. This project is licensed under the terms of the MIT license.

View File

@ -31,12 +31,75 @@ markers = [
"router", "router",
] ]
[build-system] [tool.hatch]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"
[tool.flit.module] [tool.hatch.metadata]
name = "fastapi_users" allow-direct-references = true
[tool.hatch.version]
source = "regex_commit"
commit_extra_args = ["-e"]
path = "fastapi_users/__init__.py"
[tool.hatch.envs.default]
features = [
"sqlalchemy",
"beanie",
"oauth",
"redis",
]
dependencies = [
"flake8",
"pytest",
"requests",
"isort",
"pytest-asyncio",
"flake8-docstrings",
"mike",
"mkdocs",
"mkdocs-material",
"mkdocs-mermaid2-plugin",
"black",
"mypy",
"pytest-cov",
"pytest-mock",
"flit",
"markdown-include",
"pygments",
"pymdown-extensions",
"bumpversion",
"httpx-oauth",
"httpx",
"asgi_lifespan",
"uvicorn",
"types-redis",
]
[tool.hatch.envs.default.scripts]
test = "pytest --cov=fastapi_users/ --cov-report=term-missing --cov-fail-under=100"
test-cov-xml = "pytest --cov=fastapi_users/ --cov-report=xml --cov-fail-under=100"
lint = [
"isort ./fastapi_users ./tests",
"isort ./docs/src -o fastapi_users",
"isort ./examples -o fastapi_users -p app",
"black . ",
"mypy fastapi_users/",
]
lint-check = [
"isort --check-only ./fastapi_users ./tests",
"isort --check-only ./docs/src -o fastapi_users",
"isort --check-only ./examples -o fastapi_users -p app",
"black --check .",
"mypy fief_client/",
]
docs = "mkdocs serve"
[tool.hatch.build.targets.sdist]
support-legacy = true # Create setup.py
[build-system]
requires = ["hatchling", "hatch-regex-commit"]
build-backend = "hatchling.build"
[project] [project]
name = "fastapi-users" name = "fastapi-users"
@ -71,33 +134,6 @@ dependencies = [
] ]
[project.optional-dependencies] [project.optional-dependencies]
dev = [
"flake8",
"pytest",
"requests",
"isort",
"pytest-asyncio",
"flake8-docstrings",
"mike",
"mkdocs",
"mkdocs-material",
"mkdocs-mermaid2-plugin",
"black",
"mypy",
"codecov",
"pytest-cov",
"pytest-mock",
"flit",
"markdown-include",
"pygments",
"pymdown-extensions",
"bumpversion",
"httpx-oauth",
"httpx",
"asgi_lifespan",
"uvicorn",
"types-redis",
]
sqlalchemy = [ sqlalchemy = [
"fastapi-users-db-sqlalchemy >=4.0.0", "fastapi-users-db-sqlalchemy >=4.0.0",
] ]
@ -113,3 +149,4 @@ redis = [
[project.urls] [project.urls]
Documentation = "https://fastapi-users.github.io/fastapi-users/" Documentation = "https://fastapi-users.github.io/fastapi-users/"
Source = "https://github.com/fastapi-users/fastapi-users"