diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1114219..ae04238 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,26 +11,32 @@ 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 @@ -38,18 +44,26 @@ jobs: 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 }} diff --git a/Makefile b/Makefile deleted file mode 100644 index 91608b0..0000000 --- a/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -isort: - isort ./fastapi_users_db_sqlmodel ./tests - -format: isort - black . - -test: - pytest --cov=fastapi_users_db_sqlmodel/ --cov-report=term-missing --cov-fail-under=100 - -bumpversion-major: - bumpversion major - -bumpversion-minor: - bumpversion minor - -bumpversion-patch: - bumpversion patch diff --git a/fastapi_users_db_sqlmodel/__init__.py b/fastapi_users_db_sqlmodel/__init__.py index 9a7e486..902c368 100644 --- a/fastapi_users_db_sqlmodel/__init__.py +++ b/fastapi_users_db_sqlmodel/__init__.py @@ -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) @@ -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) diff --git a/fastapi_users_db_sqlmodel/access_token.py b/fastapi_users_db_sqlmodel/access_token.py index 7395a43..8a4519e 100644 --- a/fastapi_users_db_sqlmodel/access_token.py +++ b/fastapi_users_db_sqlmodel/access_token.py @@ -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: @@ -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: diff --git a/pyproject.toml b/pyproject.toml index 1455110..971fac3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = "fvoron@gmail.com" -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 = "fvoron@gmail.com" }, +] +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" diff --git a/requirements.dev.txt b/requirements.dev.txt deleted file mode 100644 index e8ebaaf..0000000 --- a/requirements.dev.txt +++ /dev/null @@ -1,18 +0,0 @@ --r requirements.txt - -flake8 -pytest -requests -isort -pytest-asyncio -flake8-docstrings -black -mypy -codecov -pytest-cov -pytest-mock -asynctest -flit -bumpversion -httpx -asgi_lifespan diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index df49004..0000000 --- a/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -aiosqlite >= 0.19.0 -fastapi-users >= 10 -sqlmodel -greenlet diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 03dd6e4..0000000 --- a/setup.cfg +++ /dev/null @@ -1,21 +0,0 @@ -[bumpversion] -current_version = 0.2.0 -commit = True -tag = True - -[bumpversion:file:fastapi_users_db_sqlmodel/__init__.py] -search = __version__ = "{current_version}" -replace = __version__ = "{new_version}" - -[flake8] -exclude = docs -max-line-length = 88 -docstring-convention = numpy -ignore = D1 - -[isort] -profile = black - -[tool:pytest] -addopts = --ignore=test_build.py -asyncio_mode = strict