diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 518247a..d5dc593 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,13 +17,19 @@ env: jobs: tests: - name: Run ${{ matrix.mark }} tests (Python ${{ matrix.python-version }} on ${{ matrix.os }}) + name: Run tests (Python ${{ matrix.python-version }}, Pydantic ${{ matrix.pydantic-version }}, ${{ matrix.os }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - python-version: ['3.7', '3.12'] - os: [ubuntu-latest] + include: + - python-version: '3.7' + pydantic-version: '1' + os: ubuntu-latest + + - python-version: '3.12' + pydantic-version: '2' + os: ubuntu-latest steps: - name: Checkout code @@ -47,10 +53,10 @@ jobs: uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-python-${{ matrix.python-version }}-tests-${{ hashFiles('requirements*.txt') }} + key: ${{ runner.os }}-python-${{ matrix.python-version }}-pydantic-${{ matrix.pydantic-version}}-tests-${{ hashFiles('requirements*.txt') }} restore-keys: | - ${{ runner.os }}-python-${{ matrix.python-version }}-tests-${{ hashFiles('requirements*.txt') }} - ${{ runner.os }}-python-${{ matrix.python-version }}-tests- + ${{ runner.os }}-python-${{ matrix.python-version }}-pydantic-${{ matrix.pydantic-version}}-tests-${{ hashFiles('requirements*.txt') }} + ${{ runner.os }}-python-${{ matrix.python-version }}-pydantic-${{ matrix.pydantic-version}}-tests- ${{ runner.os }}-python ${{ runner.os }}- @@ -58,7 +64,7 @@ jobs: run: python -m pip install --upgrade pip setuptools wheel - name: Install dependencies - run: pip install -I -r requirements.txt -r requirements-test.txt + run: pip install -I -r requirements.txt -r requirements-test.txt "pydantic==${{ matrix.pydantic-version }}.*" - name: Build package run: | @@ -68,6 +74,7 @@ jobs: - name: Run tests run: | mkdir reports/ || echo "Directory exists" + # required to register package in etl-entities pip install -e . --no-build-isolation source .env.local ./run_tests.sh @@ -75,7 +82,7 @@ jobs: - name: Upload coverage results uses: actions/upload-artifact@v4 with: - name: coverage-${{ matrix.python-version }}-os-${{ matrix.os }} + name: coverage-python-${{ matrix.python-version }}-pydantic-${{ matrix.pydantic-version }}-os-${{ matrix.os }} path: reports/* - name: Shutdown Backend Container diff --git a/docs/changelog/next_release/14.feature.rst b/docs/changelog/next_release/14.feature.rst new file mode 100644 index 0000000..bda8f10 --- /dev/null +++ b/docs/changelog/next_release/14.feature.rst @@ -0,0 +1 @@ +Add Pydantic v2 support. diff --git a/horizon_hwm_store/horizon_hwm_store.py b/horizon_hwm_store/horizon_hwm_store.py index 4198d3c..f478181 100644 --- a/horizon_hwm_store/horizon_hwm_store.py +++ b/horizon_hwm_store/horizon_hwm_store.py @@ -14,7 +14,15 @@ HWMUpdateRequestV1, NamespacePaginateQueryV1, ) -from pydantic import Field, PrivateAttr + +try: + from pydantic.v1 import Field, PrivateAttr, root_validator +except ImportError: + from pydantic import ( # type: ignore[no-redef, assignment] + Field, + PrivateAttr, + root_validator, + ) @register_hwm_store_class("horizon") @@ -142,17 +150,7 @@ def main(config): retry: RetryConfig = Field(default_factory=RetryConfig) timeout: TimeoutConfig = Field(default_factory=TimeoutConfig) _client: HorizonClientSync = PrivateAttr() - _namespace_id: Optional[int] = PrivateAttr() - - def __init__(self, **kwargs): - super().__init__(**kwargs) - self._client = HorizonClientSync( # noqa: WPS601 - base_url=self.api_url, - auth=self.auth, - retry=self.retry, - timeout=self.timeout, - ) - self._namespace_id = None # noqa: WPS601 + _namespace_id: Optional[int] = PrivateAttr(default=None) def get_hwm(self, name: str) -> Optional[HWM]: namespace_id = self._get_namespace_id() @@ -203,6 +201,16 @@ def check(self) -> HorizonHWMStore: self._get_namespace_id() return self + @root_validator(skip_on_failure=True) + def _set_client(cls, values): # noqa: N805 + values["_client"] = HorizonClientSync( # noqa: WPS601 + base_url=values["api_url"], + auth=values["auth"], + retry=values["retry"], + timeout=values["timeout"], + ) + return values + def _get_namespace_id(self) -> int: """ Fetch the ID of the namespace. Raises an exception if the namespace doesn't exist. diff --git a/requirements-docs.txt b/requirements-docs.txt index 0ef5b3a..4883d56 100644 --- a/requirements-docs.txt +++ b/requirements-docs.txt @@ -1,4 +1,4 @@ -autodoc_pydantic<2 +autodoc_pydantic furo numpydoc sphinx diff --git a/requirements.txt b/requirements.txt index 3fba505..362339f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ data-horizon[client-sync]>=0.0.8,<0.1 -etl-entities>=2.1.0,<2.3.0 +etl-entities>=2.1.0,<2.4.0