Skip to content

Commit

Permalink
πŸ“¦οΈ package: switch to uv (#149)
Browse files Browse the repository at this point in the history
* πŸ“¦οΈ package: switch to uv

* πŸ’š ci: switch to uv

* πŸ”¨ script: fix scripts

* πŸ’š ci: fix triggers

* 🧹 chore: remove pdm.lock

* πŸ”§ config(commitizen): add pre bump hook for uv

* πŸ”§ config(pre-commit): bump uv hook

* πŸ”§ config(ruff): remove pydantic validator exception

* πŸ”§ config(hatch): add config for sdist

* πŸ”§ config: remove black config

* πŸ”§ config(pre-commit): add mypy hook

* πŸ”¨ script(lint): add exit non-zero on fix

* 🚨 fix-lint: ruff fixes
  • Loading branch information
ljnsn authored Oct 18, 2024
1 parent 1470dd9 commit 33790ec
Show file tree
Hide file tree
Showing 10 changed files with 1,160 additions and 1,333 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ name: Python package

on:
push:
branches:
- "main"
pull_request:
branches:
- "**"
types: [opened, synchronize, reopened]
create:
branches:
- "**"

Expand All @@ -16,25 +23,30 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v4
id: cache
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-root
- name: Install pdm
run: |
python -m pip install --upgrade pip
python -m pip install pdm>=2.15.0

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Install Dependencies
run: python -m pdm sync -d
run: uv sync --frozen --only-dev

- name: Lint
run: python -m pdm run bash scripts/lint.sh
run: uv run bash scripts/lint.sh

- name: Test
run: python -m pdm run bash scripts/test.sh
run: uv run bash scripts/test.sh

- name: Upload coverage
uses: codecov/codecov-action@v3

Expand All @@ -56,13 +68,15 @@ jobs:
fetch-depth: 0
token: ${{ github.token }}
submodules: recursive

- name: Checkout
if: github.actor != 'dependabot[bot]'
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
submodules: recursive

- name: Create bump and changelog
uses: commitizen-tools/commitizen-action@master
with:
Expand Down
12 changes: 9 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ repos:
hooks:
- id: conventional-gitmoji

- repo: https://github.com/pdm-project/pdm
rev: 2.19.2
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.4.24
hooks:
- id: pdm-lock-check
- id: uv-lock

- repo: local
hooks:
Expand All @@ -81,3 +81,9 @@ repos:
require_serial: true
language: system
types: [python]

- id: mypy
name: mypy
entry: mypy
language: system
types: [python]
4 changes: 2 additions & 2 deletions dsws_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def token(self) -> str:
self._token = self.fetch_token()
return self._token.token_value

def fetch_snapshot_data( # noqa: PLR0913
def fetch_snapshot_data(
self,
identifiers: List[str],
fields: List[str],
Expand All @@ -105,7 +105,7 @@ def fetch_snapshot_data( # noqa: PLR0913
)
return aggregate_responses(data_responses)

def fetch_snapshot_data_iter( # noqa: PLR0913
def fetch_snapshot_data_iter(
self,
identifiers: List[str],
fields: List[str],
Expand Down
1,288 changes: 0 additions & 1,288 deletions pdm.lock

This file was deleted.

37 changes: 14 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["dsws_client"]

[tool.hatch.build.targets.sdist]
include = ["dsws_client", "pyproject.toml", "README.md"]

[project]
name = "dsws-client"
version = "1.1.3"
Expand All @@ -15,11 +25,8 @@ dependencies = [
"typing-extensions>=4.11.0; python_version < \"3.10\"",
]

[tool.pdm]
distribution = true

[tool.pdm.dev-dependencies]
dev = [
[tool.uv]
dev-dependencies = [
"commitizen>=2.42.0",
"cz-conventional-gitmoji>=0.1.3",
"ipython>=8.12.3",
Expand All @@ -31,24 +38,14 @@ dev = [
"types-requests>=2.29.0.0",
]

[tool.pdm.build]
includes = ["dsws_client"]

[tool.pdm.scripts]
lint = "./scripts/lint.sh"
test = "./scripts/test.sh"

[tool.commitizen]
name = "cz_gitmoji"
version_provider = "pep621"
tag_format = "v$version"
bump_message = "πŸ”– bump(release): v$current_version β†’ v$new_version"
update_changelog_on_bump = true
annotate_tags = true

[tool.black]
line-length = 88
target-version = ["py38"]
pre_bump_hooks = ["uv lock --upgrade-package dsws-client"]

[tool.coverage.run]
branch = true
Expand Down Expand Up @@ -164,20 +161,14 @@ unfixable = ["ERA001", "F401", "F841"]
convention = "google"

[tool.ruff.lint.flake8-tidy-imports]
# Disallow all relative imports.
ban-relative-imports = "all"

[tool.ruff.lint.pep8-naming]
# Allow Pydantic's `@validator` decorator to trigger class method treatment.
classmethod-decorators = ["classmethod", "pydantic.validator"]
classmethod-decorators = ["classmethod"]

[tool.pytest.ini_options]
addopts = """--color=yes --doctest-modules --exitfirst --failed-first \
--strict-markers --strict-config --verbosity=2 \
--junitxml=reports/pytest.xml"""
filterwarnings = ["ignore::DeprecationWarning", "ignore::ResourceWarning"]
testpaths = ["dsws_client", "tests"]

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"
6 changes: 3 additions & 3 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
set -e
set -x

pdm run ruff check dsws_client tests
pdm run ruff format --check dsws_client tests
pdm run mypy dsws_client tests
ruff check --exit-non-zero-on-fix dsws_client tests
ruff format --check dsws_client tests
mypy dsws_client tests
6 changes: 5 additions & 1 deletion scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/usr/bin/env bash

pdm publish
set -e
set -x

uv build
uv publish
6 changes: 3 additions & 3 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
set -e
set -x

pdm run coverage run
pdm run coverage report
pdm run coverage xml
coverage run
coverage report
coverage xml
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest


@pytest.fixture()
@pytest.fixture
def timeseries_response() -> Dict[str, Any]:
"""Return an example timeseries response."""
return {
Expand Down Expand Up @@ -35,7 +35,7 @@ def timeseries_response() -> Dict[str, Any]:
}


@pytest.fixture()
@pytest.fixture
def snapshot_response() -> Dict[str, Any]:
"""Return an example snapshot response."""
return {
Expand Down Expand Up @@ -89,7 +89,7 @@ def snapshot_response() -> Dict[str, Any]:
}


@pytest.fixture()
@pytest.fixture
def invalid_response(timeseries_response: Dict[str, Any]) -> Dict[str, Any]:
"""Return a response with missing dates."""
response = timeseries_response.copy()
Expand Down
Loading

0 comments on commit 33790ec

Please sign in to comment.