From cc4ad7168e6b8617faa1c24a2e4c5c81ace974cf Mon Sep 17 00:00:00 2001 From: FaydSpeare Date: Sat, 10 Aug 2024 18:13:42 +0200 Subject: [PATCH] pre-commit ruff --- .github/workflows/release.yml | 75 +++++++++++++++++----------------- .pre-commit-config.yaml | 6 +++ ensembledata/api/_requester.py | 2 +- pyproject.toml | 3 ++ requirements.txt | 5 ++- tests/__init__.py | 0 tests/test_clients.py | 6 ++- 7 files changed, 55 insertions(+), 42 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 tests/__init__.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2bab117..4767afc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,37 +2,38 @@ name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI on: push jobs: + build: name: Build distribution 📦 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.x" + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" - - name: Install pypa/build - run: >- - python3 -m - pip install - build - --user + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user - - name: Build a binary wheel and a source tarball - run: python3 -m build + - name: Build a binary wheel and a source tarball + run: python3 -m build - - name: Store the distribution packages - uses: actions/upload-artifact@v3 - with: - name: python-package-distributions - path: dist/ + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distributions + path: dist/ publish-to-testpypi: name: Publish Python 🐍 distribution 📦 to TestPyPI needs: - - build + - build runs-on: ubuntu-latest environment: @@ -43,23 +44,23 @@ jobs: id-token: write # IMPORTANT: mandatory for trusted publishing steps: - - name: Download all the dists - uses: actions/download-artifact@v3 - with: - name: python-package-distributions - path: dist/ - - name: Publish distribution 📦 to TestPyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - repository-url: https://test.pypi.org/legacy/ - skip-existing: true + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + skip-existing: true publish-to-pypi: name: >- Publish Python 🐍 distribution 📦 to PyPI if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes needs: - - build + - build runs-on: ubuntu-latest environment: name: pypi @@ -67,10 +68,10 @@ jobs: permissions: id-token: write # IMPORTANT: mandatory for trusted publishing steps: - - name: Download all the dists - uses: actions/download-artifact@v3 - with: - name: python-package-distributions - path: dist/ - - name: Publish distribution 📦 to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..17cca8e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.5.7 + hooks: + - id: ruff + # - id: ruff-format \ No newline at end of file diff --git a/ensembledata/api/_requester.py b/ensembledata/api/_requester.py index 54103a0..c9d094f 100644 --- a/ensembledata/api/_requester.py +++ b/ensembledata/api/_requester.py @@ -7,8 +7,8 @@ import httpx from ._response import EDResponse -from .errors import EDError from ._version import version +from .errors import EDError BASE_URL = "https://ensembledata.com/apis" USER_AGENT = f"ensembledata-python/{version}" diff --git a/pyproject.toml b/pyproject.toml index 2816750..f49d3b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,9 @@ Homepage = "https://ensembledata.com" Documenation = "https://ensembledata.com/apis/docs" Repository = "https://github.com/ensembledata/ensembledata-python" +[tool.mypy] +strict = true + [tool.ruff] target-version = "py37" line-length = 100 diff --git a/requirements.txt b/requirements.txt index d90a6e8..d41402f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -ruff==0.5.6 +ruff==0.5.7 mypy==1.11.1 pytest==7.4.4 -pytest-asyncio=0.21.2 \ No newline at end of file +pytest-asyncio=0.21.2 +pre-commit==2.21.0 \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_clients.py b/tests/test_clients.py index 7f44ae8..748ed16 100644 --- a/tests/test_clients.py +++ b/tests/test_clients.py @@ -1,9 +1,11 @@ import pytest -from ensembledata.api import EDClient, EDAsyncClient, EDError, errors +from ensembledata.api import EDAsyncClient, EDClient, EDError, errors + def test_client(): client = EDClient("xxx") + with pytest.raises(EDError) as e: client.customer.get_usage("2024-01-01") @@ -17,4 +19,4 @@ async def test_async_client(): with pytest.raises(EDError) as e: await client.customer.get_usage("2024-01-01") - assert e.value.status_code == errors.STATUS_491_INVALID_TOKEN \ No newline at end of file + assert e.value.status_code == errors.STATUS_491_INVALID_TOKEN