Skip to content

Commit

Permalink
Move to Hatch for package management
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed May 3, 2023
1 parent 4d3f4ae commit cf49897
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 111 deletions.
84 changes: 49 additions & 35 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,59 @@ jobs:
python_version: [3.7, 3.8, 3.9, '3.10', '3.11']

steps:
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python_version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.dev.txt
- name: Test with pytest
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
pytest --cov=fastapi_users_db_sqlmodel/
codecov
- name: Build and install it on system host
run: |
flit build
flit install --python $(which python)
python test_build.py
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch
hatch env create
- name: Lint and typecheck
run: |
hatch run lint-check
- name: Test
run: |
hatch run test-cov-xml
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
- name: Build and install it on system host
run: |
hatch build
pip install dist/fastapi_users_db_sqlmodel-*.whl
python test_build.py
release:
runs-on: ubuntu-latest
needs: test
if: startsWith(github.ref, 'refs/tags/')

steps:
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.dev.txt
- name: Release on PyPI
env:
FLIT_USERNAME: ${{ secrets.FLIT_USERNAME }}
FLIT_PASSWORD: ${{ secrets.FLIT_PASSWORD }}
run: |
flit publish
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch
- name: Build and publish on PyPI
env:
HATCH_INDEX_USER: ${{ secrets.HATCH_INDEX_USER }}
HATCH_INDEX_AUTH: ${{ secrets.HATCH_INDEX_AUTH }}
run: |
hatch build
hatch publish
- name: Create release
uses: ncipollo/release-action@v1
with:
draft: true
body: ${{ github.event.head_commit.message }}
artifacts: dist/*.whl,dist/*.tar.gz
token: ${{ secrets.GITHUB_TOKEN }}
17 changes: 0 additions & 17 deletions Makefile

This file was deleted.

4 changes: 2 additions & 2 deletions fastapi_users_db_sqlmodel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def get(self, id: ID) -> Optional[UP]:

async def get_by_email(self, email: str) -> Optional[UP]:
"""Get a single user by email."""
statement = select(self.user_model).where(
statement = select(self.user_model).where( # type: ignore
func.lower(self.user_model.email) == func.lower(email)
)
results = self.session.exec(statement)
Expand Down Expand Up @@ -171,7 +171,7 @@ async def get(self, id: ID) -> Optional[UP]:

async def get_by_email(self, email: str) -> Optional[UP]:
"""Get a single user by email."""
statement = select(self.user_model).where(
statement = select(self.user_model).where( # type: ignore
func.lower(self.user_model.email) == func.lower(email)
)
results = await self.session.execute(statement)
Expand Down
4 changes: 2 additions & 2 deletions fastapi_users_db_sqlmodel/access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, session: Session, access_token_model: Type[AP]):
async def get_by_token(
self, token: str, max_age: Optional[datetime] = None
) -> Optional[AP]:
statement = select(self.access_token_model).where(
statement = select(self.access_token_model).where( # type: ignore
self.access_token_model.token == token
)
if max_age is not None:
Expand Down Expand Up @@ -90,7 +90,7 @@ def __init__(self, session: AsyncSession, access_token_model: Type[AP]):
async def get_by_token(
self, token: str, max_age: Optional[datetime] = None
) -> Optional[AP]:
statement = select(self.access_token_model).where(
statement = select(self.access_token_model).where( # type: ignore
self.access_token_model.token == token
)
if max_age is not None:
Expand Down
78 changes: 66 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,84 @@
[tool.pytest.ini_options]
asyncio_mode = "auto"
addopts = "--ignore=test_build.py"

[tool.ruff]
extend-select = ["I"]

[tool.hatch]

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.version]
source = "regex_commit"
commit_extra_args = ["-e"]
path = "fastapi_users_db_sqlmodel/__init__.py"

[tool.hatch.envs.default]
dependencies = [
"aiosqlite",
"pytest",
"pytest-asyncio",
"black",
"mypy",
"pytest-cov",
"pytest-mock",
"httpx",
"asgi_lifespan",
"ruff",
]

[tool.hatch.envs.default.scripts]
test = "pytest --cov=fastapi_users_db_sqlmodel/ --cov-report=term-missing --cov-fail-under=100"
test-cov-xml = "pytest --cov=fastapi_users_db_sqlmodel/ --cov-report=xml --cov-fail-under=100"
lint = [
"black . ",
"ruff --fix .",
"mypy fastapi_users_db_sqlmodel/",
]
lint-check = [
"black --check .",
"ruff .",
"mypy fastapi_users_db_sqlmodel/",
]

[tool.hatch.build.targets.sdist]
support-legacy = true # Create setup.py

[build-system]
requires = ["flit_core >=2,<3"]
build-backend = "flit_core.buildapi"

[tool.flit.metadata]
module = "fastapi_users_db_sqlmodel"
dist-name = "fastapi-users-db-sqlmodel"
author = "François Voron"
author-email = "[email protected]"
home-page = "https://github.com/fastapi-users/fastapi-users-db-sqlmodel"
requires = ["hatchling", "hatch-regex-commit"]
build-backend = "hatchling.build"

[project]
name = "fastapi-users-db-sqlmodel"
authors = [
{ name = "François Voron", email = "[email protected]" },
]
description = "FastAPI Users database adapter for SQLModel"
readme = "README.md"
dynamic = ["version"]
classifiers = [
"License :: OSI Approved :: MIT License",
"Development Status :: 5 - Production/Stable",
"Framework :: FastAPI",
"Framework :: AsyncIO",
"Intended Audience :: Developers",
"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 :: Only",
"Topic :: Internet :: WWW/HTTP :: Session",
]
description-file = "README.md"
requires-python = ">=3.7"
requires = [
dependencies = [
"fastapi-users >= 10.0.2",
"greenlet",
"sqlmodel",
]

[tool.flit.metadata.urls]
[project.urls]
Documentation = "https://fastapi-users.github.io/fastapi-users"
Source = "https://github.com/fastapi-users/fastapi-users-db-sqlmodel"
18 changes: 0 additions & 18 deletions requirements.dev.txt

This file was deleted.

4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

21 changes: 0 additions & 21 deletions setup.cfg

This file was deleted.

0 comments on commit cf49897

Please sign in to comment.