From 21f30229dcc5ad8c79173dfdc919fa58c3b0a4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Voron?= Date: Tue, 18 Oct 2022 08:32:06 +0200 Subject: [PATCH] Use hatch for package management --- .github/workflows/build.yml | 49 +++++++------- .github/workflows/documentation.yml | 8 +-- Makefile | 52 -------------- README.md | 42 ++++-------- pyproject.toml | 101 +++++++++++++++++++--------- 5 files changed, 110 insertions(+), 142 deletions(-) delete mode 100644 Makefile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e7f17ab7..144b5173 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,33 +11,31 @@ jobs: python_version: [3.7, 3.8, 3.9, '3.10'] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python_version }} - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flit - flit install --deps develop --extras oauth,redis - - name: Check codestyle + pip install hatch + hatch env create + - name: Lint and typecheck run: | - make format-check - make lint - - name: Typecheck + hatch run lint-check + - name: Test run: | - make typecheck - - name: Test with pytest - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - run: | - pytest --cov=fastapi_users/ - codecov + hatch run test-cov-xml + - uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: true + verbose: true - name: Build and install it on system host run: | - flit build --setup-py - flit install --deps none --python $(which python) + hatch build + pip install dist/fastapi_users-*.whl python test_build.py release: @@ -46,19 +44,20 @@ jobs: if: startsWith(github.ref, 'refs/tags/') steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v4 with: python-version: 3.7 - name: Install dependencies + shell: bash run: | python -m pip install --upgrade pip - pip install flit - flit install --deps develop --extras oauth,redis - - name: Release on PyPI + pip install hatch + - name: Build and publish on PyPI env: - FLIT_USERNAME: ${{ secrets.FLIT_USERNAME }} - FLIT_PASSWORD: ${{ secrets.FLIT_PASSWORD }} + HATCH_INDEX_USER: ${{ secrets.HATCH_INDEX_USER }} + HATCH_INDEX_AUTH: ${{ secrets.HATCH_INDEX_AUTH }} run: | - flit publish --setup-py + hatch build + hatch publish diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 74a4078e..3705e025 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -14,16 +14,16 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python 3.7 - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: 3.7 - name: Install dependencies + shell: bash run: | python -m pip install --upgrade pip - pip install flit - flit install --deps develop --extras oauth,redis + pip install hatch - name: Build - run: mkdocs build + run: hatch run mkdocs build - name: Parse tag id: version_tag uses: battila7/get-version-action@v2 diff --git a/Makefile b/Makefile deleted file mode 100644 index 04501138..00000000 --- a/Makefile +++ /dev/null @@ -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 diff --git a/README.md b/README.md index 78c52839..13a30cb1 100644 --- a/README.md +++ b/README.md @@ -178,40 +178,14 @@ This project follows the [all-contributors](https://github.com/all-contributors/ ### Setup environment -You should create a virtual environment and activate it: - -```bash -python -m venv venv/ -``` - -```bash -source venv/bin/activate -``` - -And then install the development dependencies: - -```bash -make install -``` +We use [Hatch](https://hatch.pypa.io/latest/install/) to manage the development environment and production build. Ensure it's installed on your system. ### Run unit tests You can run all the tests with: ```bash -make 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 +hatch run test ``` ### Format the code @@ -219,9 +193,19 @@ ulimit -n 2048 Execute the following command to apply `isort` and `black` formatting: ```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 This project is licensed under the terms of the MIT license. diff --git a/pyproject.toml b/pyproject.toml index af2d1c6b..fa23f188 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,12 +31,75 @@ markers = [ "router", ] -[build-system] -requires = ["flit_core >=3.2,<4"] -build-backend = "flit_core.buildapi" +[tool.hatch] -[tool.flit.module] -name = "fastapi_users" +[tool.hatch.metadata] +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] name = "fastapi-users" @@ -71,33 +134,6 @@ 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 = [ "fastapi-users-db-sqlalchemy >=4.0.0", ] @@ -113,3 +149,4 @@ redis = [ [project.urls] Documentation = "https://fastapi-users.github.io/fastapi-users/" +Source = "https://github.com/fastapi-users/fastapi-users"