Skip to content

Commit cf49897

Browse files
committed
Move to Hatch for package management
1 parent 4d3f4ae commit cf49897

File tree

8 files changed

+119
-111
lines changed

8 files changed

+119
-111
lines changed

.github/workflows/build.yml

+49-35
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,59 @@ jobs:
1111
python_version: [3.7, 3.8, 3.9, '3.10', '3.11']
1212

1313
steps:
14-
- uses: actions/checkout@v1
15-
- name: Set up Python
16-
uses: actions/setup-python@v1
17-
with:
18-
python-version: ${{ matrix.python_version }}
19-
- name: Install dependencies
20-
run: |
21-
python -m pip install --upgrade pip
22-
pip install -r requirements.dev.txt
23-
- name: Test with pytest
24-
env:
25-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
26-
run: |
27-
pytest --cov=fastapi_users_db_sqlmodel/
28-
codecov
29-
- name: Build and install it on system host
30-
run: |
31-
flit build
32-
flit install --python $(which python)
33-
python test_build.py
14+
- uses: actions/checkout@v3
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: ${{ matrix.python_version }}
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install hatch
23+
hatch env create
24+
- name: Lint and typecheck
25+
run: |
26+
hatch run lint-check
27+
- name: Test
28+
run: |
29+
hatch run test-cov-xml
30+
- uses: codecov/codecov-action@v3
31+
with:
32+
token: ${{ secrets.CODECOV_TOKEN }}
33+
fail_ci_if_error: true
34+
verbose: true
35+
- name: Build and install it on system host
36+
run: |
37+
hatch build
38+
pip install dist/fastapi_users_db_sqlmodel-*.whl
39+
python test_build.py
3440
3541
release:
3642
runs-on: ubuntu-latest
3743
needs: test
3844
if: startsWith(github.ref, 'refs/tags/')
3945

4046
steps:
41-
- uses: actions/checkout@v1
42-
- name: Set up Python
43-
uses: actions/setup-python@v1
44-
with:
45-
python-version: 3.7
46-
- name: Install dependencies
47-
run: |
48-
python -m pip install --upgrade pip
49-
pip install -r requirements.dev.txt
50-
- name: Release on PyPI
51-
env:
52-
FLIT_USERNAME: ${{ secrets.FLIT_USERNAME }}
53-
FLIT_PASSWORD: ${{ secrets.FLIT_PASSWORD }}
54-
run: |
55-
flit publish
47+
- uses: actions/checkout@v3
48+
- name: Set up Python
49+
uses: actions/setup-python@v4
50+
with:
51+
python-version: 3.7
52+
- name: Install dependencies
53+
run: |
54+
python -m pip install --upgrade pip
55+
pip install hatch
56+
- name: Build and publish on PyPI
57+
env:
58+
HATCH_INDEX_USER: ${{ secrets.HATCH_INDEX_USER }}
59+
HATCH_INDEX_AUTH: ${{ secrets.HATCH_INDEX_AUTH }}
60+
run: |
61+
hatch build
62+
hatch publish
63+
- name: Create release
64+
uses: ncipollo/release-action@v1
65+
with:
66+
draft: true
67+
body: ${{ github.event.head_commit.message }}
68+
artifacts: dist/*.whl,dist/*.tar.gz
69+
token: ${{ secrets.GITHUB_TOKEN }}

Makefile

-17
This file was deleted.

fastapi_users_db_sqlmodel/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async def get(self, id: ID) -> Optional[UP]:
7575

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

172172
async def get_by_email(self, email: str) -> Optional[UP]:
173173
"""Get a single user by email."""
174-
statement = select(self.user_model).where(
174+
statement = select(self.user_model).where( # type: ignore
175175
func.lower(self.user_model.email) == func.lower(email)
176176
)
177177
results = await self.session.execute(statement)

fastapi_users_db_sqlmodel/access_token.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, session: Session, access_token_model: Type[AP]):
4343
async def get_by_token(
4444
self, token: str, max_age: Optional[datetime] = None
4545
) -> Optional[AP]:
46-
statement = select(self.access_token_model).where(
46+
statement = select(self.access_token_model).where( # type: ignore
4747
self.access_token_model.token == token
4848
)
4949
if max_age is not None:
@@ -90,7 +90,7 @@ def __init__(self, session: AsyncSession, access_token_model: Type[AP]):
9090
async def get_by_token(
9191
self, token: str, max_age: Optional[datetime] = None
9292
) -> Optional[AP]:
93-
statement = select(self.access_token_model).where(
93+
statement = select(self.access_token_model).where( # type: ignore
9494
self.access_token_model.token == token
9595
)
9696
if max_age is not None:

pyproject.toml

+66-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,84 @@
1+
[tool.pytest.ini_options]
2+
asyncio_mode = "auto"
3+
addopts = "--ignore=test_build.py"
4+
5+
[tool.ruff]
6+
extend-select = ["I"]
7+
8+
[tool.hatch]
9+
10+
[tool.hatch.metadata]
11+
allow-direct-references = true
12+
13+
[tool.hatch.version]
14+
source = "regex_commit"
15+
commit_extra_args = ["-e"]
16+
path = "fastapi_users_db_sqlmodel/__init__.py"
17+
18+
[tool.hatch.envs.default]
19+
dependencies = [
20+
"aiosqlite",
21+
"pytest",
22+
"pytest-asyncio",
23+
"black",
24+
"mypy",
25+
"pytest-cov",
26+
"pytest-mock",
27+
"httpx",
28+
"asgi_lifespan",
29+
"ruff",
30+
]
31+
32+
[tool.hatch.envs.default.scripts]
33+
test = "pytest --cov=fastapi_users_db_sqlmodel/ --cov-report=term-missing --cov-fail-under=100"
34+
test-cov-xml = "pytest --cov=fastapi_users_db_sqlmodel/ --cov-report=xml --cov-fail-under=100"
35+
lint = [
36+
"black . ",
37+
"ruff --fix .",
38+
"mypy fastapi_users_db_sqlmodel/",
39+
]
40+
lint-check = [
41+
"black --check .",
42+
"ruff .",
43+
"mypy fastapi_users_db_sqlmodel/",
44+
]
45+
46+
[tool.hatch.build.targets.sdist]
47+
support-legacy = true # Create setup.py
48+
149
[build-system]
2-
requires = ["flit_core >=2,<3"]
3-
build-backend = "flit_core.buildapi"
4-
5-
[tool.flit.metadata]
6-
module = "fastapi_users_db_sqlmodel"
7-
dist-name = "fastapi-users-db-sqlmodel"
8-
author = "François Voron"
9-
author-email = "[email protected]"
10-
home-page = "https://github.com/fastapi-users/fastapi-users-db-sqlmodel"
50+
requires = ["hatchling", "hatch-regex-commit"]
51+
build-backend = "hatchling.build"
52+
53+
[project]
54+
name = "fastapi-users-db-sqlmodel"
55+
authors = [
56+
{ name = "François Voron", email = "[email protected]" },
57+
]
58+
description = "FastAPI Users database adapter for SQLModel"
59+
readme = "README.md"
60+
dynamic = ["version"]
1161
classifiers = [
1262
"License :: OSI Approved :: MIT License",
1363
"Development Status :: 5 - Production/Stable",
64+
"Framework :: FastAPI",
1465
"Framework :: AsyncIO",
1566
"Intended Audience :: Developers",
1667
"Programming Language :: Python :: 3.7",
1768
"Programming Language :: Python :: 3.8",
1869
"Programming Language :: Python :: 3.9",
70+
"Programming Language :: Python :: 3.10",
71+
"Programming Language :: Python :: 3.11",
1972
"Programming Language :: Python :: 3 :: Only",
2073
"Topic :: Internet :: WWW/HTTP :: Session",
2174
]
22-
description-file = "README.md"
2375
requires-python = ">=3.7"
24-
requires = [
76+
dependencies = [
2577
"fastapi-users >= 10.0.2",
78+
"greenlet",
2679
"sqlmodel",
2780
]
2881

29-
[tool.flit.metadata.urls]
82+
[project.urls]
3083
Documentation = "https://fastapi-users.github.io/fastapi-users"
84+
Source = "https://github.com/fastapi-users/fastapi-users-db-sqlmodel"

requirements.dev.txt

-18
This file was deleted.

requirements.txt

-4
This file was deleted.

setup.cfg

-21
This file was deleted.

0 commit comments

Comments
 (0)