Skip to content

Commit

Permalink
Fideslang Pydantic V2 Upgrade (#11)
Browse files Browse the repository at this point in the history
- Fideslang Pydantic V2 Upgrade
- Removes Python 3.8 from supported versions
  • Loading branch information
pattisdr authored Aug 20, 2024
1 parent ae88104 commit 6c0528b
Show file tree
Hide file tree
Showing 24 changed files with 680 additions and 392 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ jobs:
Pytest-Matrix:
strategy:
matrix:
python_version: ["3.8", "3.9", "3.10", "3.11"]
pydantic_version: ["1.8.2", "1.9.2", "1.10.9"]
pyyaml_version: ["5.4.1", "6.0"]
python_version: ["3.9", "3.10", "3.11"]
pydantic_version: ["2.3.0", "2.4.2", "2.5.3", "2.6.4", "2.7.1"]
pyyaml_version: ["5.4.1", "6.0.1"]
runs-on: ubuntu-latest
continue-on-error: true
steps:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ The types of changes are:

## [Unreleased](https://github.com/ethyca/fideslang/compare/3.0.1...main)

### Changed

- Upgrades Pydantic for V2 support and removes support for Pydantic V1 [#11](https://github.com/ethyca/fideslang/pull/11)
- Removes Python 3.8 from supported versions [#11](https://github.com/ethyca/fideslang/pull/11)
-
## [3.0.1](https://github.com/ethyca/fideslang/compare/3.0.0...3.0.1)

### Added
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8-slim-bullseye as base
FROM python:3.9-slim-bullseye as base

# Update pip in the base image since we'll use it everywhere
RUN pip install -U pip
Expand Down
6 changes: 3 additions & 3 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
black==23.3.0
mypy==1.4.0
mypy==1.10.0
nox>=2023
packaging>=22.0
pre-commit==2.9.3
pre-commit==3.7.1
pylint==2.10.0
pytest==7.3.1
pytest-cov==2.11.1
requests-mock==1.8.0
setuptools>=64.0.2
types-PyYAML
xenon==0.7.3
xenon==0.9.1
2 changes: 1 addition & 1 deletion mkdocs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8-slim-bullseye
FROM python:3.9-slim-bullseye

# Install auxiliary software
RUN apt-get update
Expand Down
7 changes: 4 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
nox.options.sessions = []
nox.options.reuse_existing_virtualenvs = True

TESTED_PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11"]
TESTED_PYDANTIC_VERSIONS = ["1.8.2", "1.9.2", "1.10.9"]
TESTED_PYYAML_VERSIONS = ["5.4.1", "6.0"]
# These should match what is in the `pr_checks.yml` file for CI runs
TESTED_PYTHON_VERSIONS = ["3.9", "3.10", "3.11"]
TESTED_PYDANTIC_VERSIONS = ["2.3.0", "2.4.2", "2.5.3", "2.6.4", "2.7.1"]
TESTED_PYYAML_VERSIONS = ["5.4.1", "6.0.1"]


def install_requirements(session: nox.Session) -> None:
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ name = "fideslang"
description = "Fides Taxonomy Language"
dynamic = ["dependencies", "version"]
readme = "README.md"
requires-python = ">=3.8, <4"
requires-python = ">=3.9, <4"
authors = [{ name = "Ethyca, Inc.", email = "fidesteam@ethyca.com" }]
license = { text = "Apache License 2.0" }
classifiers = [
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pydantic>=1.8.1,<1.11.0
pydantic>=2.3.0,<=2.7.1
pyyaml>=5,<7
packaging>=20.0
2 changes: 1 addition & 1 deletion src/fideslang/default_taxonomy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def default_factory(taxonomy_class: CustomType, **kwargs: Dict) -> CustomType:
# This is the version where we started tracking from, so
# we use it as the default starting point.
kwargs["version_added"] = "2.0.0" # type: ignore[assignment]
item = taxonomy_class.parse_obj(kwargs)
item = taxonomy_class.model_validate(kwargs)
return item
16 changes: 8 additions & 8 deletions src/fideslang/gvl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ def _load_data() -> None:
) as mapping_file:
data = load(mapping_file)
for raw_purpose in data["purposes"].values():
purpose = Purpose.parse_obj(raw_purpose)
mapped_purpose = MappedPurpose.parse_obj(raw_purpose)
purpose = Purpose.model_validate(raw_purpose)
mapped_purpose = MappedPurpose.model_validate(raw_purpose)
GVL_PURPOSES[purpose.id] = purpose
MAPPED_PURPOSES[mapped_purpose.id] = mapped_purpose
for data_use in mapped_purpose.data_uses:
MAPPED_PURPOSES_BY_DATA_USE[data_use] = mapped_purpose

for raw_special_purpose in data["specialPurposes"].values():
special_purpose = Purpose.parse_obj(raw_special_purpose)
mapped_special_purpose = MappedPurpose.parse_obj(raw_special_purpose)
special_purpose = Purpose.model_validate(raw_special_purpose)
mapped_special_purpose = MappedPurpose.model_validate(raw_special_purpose)
GVL_SPECIAL_PURPOSES[special_purpose.id] = special_purpose
MAPPED_SPECIAL_PURPOSES[mapped_special_purpose.id] = mapped_special_purpose
for data_use in mapped_special_purpose.data_uses:
Expand All @@ -71,12 +71,12 @@ def _load_data() -> None:
feature_data = load(feature_mapping_file)

for raw_feature in feature_data["features"].values():
feature = Feature.parse_obj(raw_feature)
feature = Feature.model_validate(raw_feature)
GVL_FEATURES[feature.id] = feature
FEATURES_BY_NAME[feature.name] = feature

for raw_special_feature in feature_data["specialFeatures"].values():
special_feature = Feature.parse_obj(raw_special_feature)
special_feature = Feature.model_validate(raw_special_feature)
GVL_SPECIAL_FEATURES[special_feature.id] = special_feature
FEATURES_BY_NAME[special_feature.name] = special_feature

Expand All @@ -86,8 +86,8 @@ def _load_data() -> None:
data_category_data = load(data_category_mapping_file)

for raw_data_category in data_category_data.values():
data_category = GVLDataCategory.parse_obj(raw_data_category)
mapped_data_category = MappedDataCategory.parse_obj(raw_data_category)
data_category = GVLDataCategory.model_validate(raw_data_category)
mapped_data_category = MappedDataCategory.model_validate(raw_data_category)
GVL_DATA_CATEGORIES[data_category.id] = data_category
MAPPED_GVL_DATA_CATEGORIES[mapped_data_category.id] = mapped_data_category

Expand Down
3 changes: 2 additions & 1 deletion src/fideslang/gvl/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class MappedPurpose(Purpose):


class Feature(BaseModel):
"Pydantic model for GVL feature records"
"""Pydantic model for GVL feature records"""

id: int = Field(description="Official GVL feature ID or special feature ID")
name: str = Field(description="Name of the GVL feature or special feature.")
description: str = Field(
Expand Down
Loading

0 comments on commit 6c0528b

Please sign in to comment.