From c9a7dbe121d3ce379c87b9bcb3c251d380a0a74b Mon Sep 17 00:00:00 2001 From: Paul Sanders Date: Wed, 9 Oct 2024 09:43:55 -0400 Subject: [PATCH 1/5] Drop support for python 3.8 --- .github/workflows/testing.yml | 29 ++++++++++++++++++++++++++++- README.md | 2 -- prelude_parser/pandas.py | 4 ---- prelude_parser/types.py | 7 ++++--- pyproject.toml | 9 ++++----- tests/test_pandas.py | 11 ++--------- 6 files changed, 38 insertions(+), 24 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 9d0cd46..cd1dde8 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -8,6 +8,7 @@ env: CARGO_TERM_COLOR: always RUST_BACKTRACE: 1 RUSTFLAGS: "-D warnings" + PYTHON_VERSION: "3.9" jobs: clippy: name: Clippy @@ -33,11 +34,37 @@ jobs: uses: Swatinem/rust-cache@v2.7.3 - name: Run cargo fmt run: cargo fmt --all -- --check + python-linting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: install Just + uses: taiki-e/install-action@just + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Restore uv cache + uses: actions/cache@v4 + with: + path: ${{ env.UV_CACHE_DIR }} + key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} + restore-keys: | + uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} + uv-${{ runner.os }} + - name: Install Dependencies + run: just install + - name: mypy check + run: just mypy + - name: Minimize uv cache + run: uv cache prune --ci test: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: diff --git a/README.md b/README.md index f1e80c3..227da6b 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,6 @@ pip install prelude-parser Optionally the `pandas` extra can be installed to parse to a Pandas `DataFrame` -Note: Pandas only supports Python 3.9+ so this is not available in Python 3.8. - ```sh pip install prelude-parser[pandas] ``` diff --git a/prelude_parser/pandas.py b/prelude_parser/pandas.py index 6ed3c82..59375d9 100644 --- a/prelude_parser/pandas.py +++ b/prelude_parser/pandas.py @@ -1,6 +1,5 @@ from __future__ import annotations -import sys from pathlib import Path from prelude_parser._prelude_parser import _parse_flat_file_to_pandas_dict @@ -13,9 +12,6 @@ class UnsupportedPythonVersionError(Exception): try: import pandas as pd except ImportError as e: # pragma: no cover - if sys.version_info < (3, 9): # pargma: no cover - raise UnsupportedPythonVersionError("Pandas only supports Python 3.9+") from e - raise ImportError( "prelude-parser must be installed with the pandas or all extra to use pandas" ) from e diff --git a/prelude_parser/types.py b/prelude_parser/types.py index 43d8c28..6b0804b 100644 --- a/prelude_parser/types.py +++ b/prelude_parser/types.py @@ -1,5 +1,6 @@ +from __future__ import annotations + from datetime import date, datetime -from typing import Dict, List, Union -FieldInfo = Union[str, int, float, date, datetime, None] -FlatFormInfo = List[Dict[str, FieldInfo]] +FieldInfo = str | int | float | date | datetime | None +FlatFormInfo = list[dict[str, FieldInfo]] diff --git a/pyproject.toml b/pyproject.toml index 41aa8bf..48db8d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,14 +4,13 @@ build-backend = "maturin" [project] name = "prelude-parser" -requires-python = ">=3.8" +requires-python = ">=3.9" description = "Parses XML files exported from Prelude EDC into formats usable by Python." authors = [{name = "Paul Sanders", email = "paul@pbsdatasolutions.com"}] keywords = ["parser", "prelude-edc", "xml", "pandas", "polars"] classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -29,9 +28,9 @@ documentation = "https://github.com/pbs-data-solutions/prelude-parser" dependencies = ["camel-converter>=3.0.0"] [project.optional-dependencies] -pandas = ['pandas>=2.1.0; python_version>"3.8"'] +pandas = ["pandas>=2.1.0"] polars = ["polars>=0.17.14"] -all = ['pandas>=2.1.0; python_version>"3.8"', "polars>=0.17.14"] +all = ["pandas>=2.1.0", "polars>=0.17.14"] [tool.maturin] module-name = "prelude_parser._prelude_parser" @@ -52,7 +51,7 @@ disallow_untyped_defs = false [tool.ruff] line-length = 100 -target-version = "py38" +target-version = "py39" fix = true [tool.ruff.lint] diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 66112bb..bead39d 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -1,14 +1,8 @@ -import sys +import pandas as pd -import pytest +from prelude_parser.pandas import to_dataframe -if sys.version_info >= (3, 9): - import pandas as pd - from prelude_parser.pandas import to_dataframe - - -@pytest.mark.skipif(sys.version_info < (3, 9), reason="Pandas only supports 3.9+") def test_pandas_to_dataframe(test_file_1): result = to_dataframe(test_file_1) data = { @@ -32,7 +26,6 @@ def test_pandas_to_dataframe(test_file_1): assert expected.equals(result) -@pytest.mark.skipif(sys.version_info < (3, 9), reason="Pandas only supports 3.9+") def test_pandas_to_dataframe_short_names(test_file_4): result = to_dataframe(test_file_4, short_names=True) data = { From c263db939040a1188fffc4ddcc96394cfa669517 Mon Sep 17 00:00:00 2001 From: Paul Sanders Date: Wed, 9 Oct 2024 09:52:14 -0400 Subject: [PATCH 2/5] Fix 3.9 mypy errors --- prelude_parser/types.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/prelude_parser/types.py b/prelude_parser/types.py index 6b0804b..1c2c13c 100644 --- a/prelude_parser/types.py +++ b/prelude_parser/types.py @@ -1,6 +1,7 @@ -from __future__ import annotations +# UP035 and UP006 ignored because Python 3.9 doesn't support the upgrade from datetime import date, datetime +from typing import Dict, List, Union # noqa: UP035 -FieldInfo = str | int | float | date | datetime | None -FlatFormInfo = list[dict[str, FieldInfo]] +FieldInfo = Union[str, int, float, date, datetime, None] +FlatFormInfo = List[Dict[str, FieldInfo]] # noqa: UP006 From 6f70ecf996c954b59982c82eb53f38f283076670 Mon Sep 17 00:00:00 2001 From: Paul Sanders Date: Wed, 9 Oct 2024 09:58:58 -0400 Subject: [PATCH 3/5] Fix cache --- .github/workflows/testing.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index cd1dde8..e858df4 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -40,26 +40,15 @@ jobs: - uses: actions/checkout@v4 - name: install Just uses: taiki-e/install-action@just - - name: Install uv - run: curl -LsSf https://astral.sh/uv/install.sh | sh - name: Set up Python uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_VERSION }} - - name: Restore uv cache - uses: actions/cache@v4 - with: - path: ${{ env.UV_CACHE_DIR }} - key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} - restore-keys: | - uv-${{ runner.os }}-${{ hashFiles('uv.lock') }} - uv-${{ runner.os }} + cache: "pip" - name: Install Dependencies run: just install - name: mypy check run: just mypy - - name: Minimize uv cache - run: uv cache prune --ci test: strategy: fail-fast: false From 26f2d1cd9bd3ac6cd37f1d2fd50e6050ae6c725b Mon Sep 17 00:00:00 2001 From: Paul Sanders Date: Wed, 9 Oct 2024 10:07:05 -0400 Subject: [PATCH 4/5] Fix install --- .github/workflows/testing.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index e858df4..49eb79d 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -45,8 +45,13 @@ jobs: with: python-version: ${{ env.PYTHON_VERSION }} cache: "pip" - - name: Install Dependencies - run: just install + - name: Install dependencies + run: | + pip install -U pip + pip install -r requirements-dev.txt + pip install -e .[all] + maturin build --out dist + pip install --no-index --find-links=dist/ prelude-parser - name: mypy check run: just mypy test: From 2ed9a37840e8ee82759199092e7bf2629e533135 Mon Sep 17 00:00:00 2001 From: Paul Sanders Date: Wed, 9 Oct 2024 10:10:18 -0400 Subject: [PATCH 5/5] Run mypy with 3.10 because of pandas types --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 49eb79d..41a263a 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -8,7 +8,7 @@ env: CARGO_TERM_COLOR: always RUST_BACKTRACE: 1 RUSTFLAGS: "-D warnings" - PYTHON_VERSION: "3.9" + PYTHON_VERSION: "3.10" # Because of pandas types jobs: clippy: name: Clippy