Skip to content

Commit 089d270

Browse files
authored
Support Python 3.12+ and address pydantic v2 compatibility issues (#41)
* Run `poetry lock` with Poetry 1.8.4 * Upgrade flake8 to 7.0 * Upgrade pydantic to 2.0 * Drop pytest-flake8 in favor of invoking flake8 directly * Address pydantic 2.0 UserWarning for allow_population_by_field_name * Address pydantic 2.0 deprecation warnings in shrub.v3 * Address Python 3.12 deprecation warnings in pytest * Update changelog and package version number * Remove stray git merge conflict marker * Relock dependencies with Poetry 1.8.4 * Bump version number in pyproject.toml
1 parent 3038539 commit 089d270

File tree

8 files changed

+339
-531
lines changed

8 files changed

+339
-531
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 3.6.0 - 2024-11-18
4+
- Address Python 3.12+ compatibility issues.
5+
- Address pydantic v2 compatibility issues.
6+
- Raise minimum required Python version to 3.8.
7+
- Raise minimum required `pydantic` version to 2.0.
8+
39
## 3.5.0 - 2024-11-12
410
- Add `batchtime` and `depends_on` fields to `shrub.v3.evg_task.EvgTaskRef`.
511

evergreen.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ buildvariants:
55
- ubuntu2204-small
66
tasks:
77
- name: unit_tests
8+
- name: lint
89
- name: deploy
910

1011
functions:
@@ -47,11 +48,24 @@ tasks:
4748
. venv/bin/activate
4849
4950
poetry run pytest --junitxml=junit-test-output.xml
51+
- name: lint
52+
commands:
53+
- command: shell.exec
54+
params:
55+
working_dir: src
56+
script: |
57+
set -o errexit
58+
set -o verbose
59+
60+
. venv/bin/activate
61+
62+
poetry run flake8 src/shrub tests
5063
5164
- name: deploy
5265
patchable: false
5366
depends_on:
5467
- name: unit_tests
68+
- name: lint
5569
commands:
5670
- command: subprocess.exec
5771
params:

poetry.lock

Lines changed: 303 additions & 516 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "shrub.py"
3-
version = "3.5.0"
3+
version = "3.6.0"
44
description = "Library for creating evergreen configurations"
55
authors = ["DevProd Services & Integrations Team <[email protected]>"]
66
license = "Apache-2.0"
@@ -11,21 +11,20 @@ packages = [
1111
]
1212

1313
[tool.poetry.dependencies]
14-
python = ">3.7.0"
14+
python = ">=3.8.1"
1515
PyYaml = "^5.1 || ^6.0"
1616
dataclasses = {version = "^0.7", python = "3.6.*"}
17-
pydantic = "^1.8 || ^2.0"
17+
pydantic = "^2.0"
1818
typing-extensions = "^4"
1919
croniter = "^1.4.1"
2020

2121
[tool.poetry.dev-dependencies]
22-
pytest = "^6.0"
22+
pytest = "^7.0"
2323
pytest-black = "^0.3"
24-
pytest-flake8 = "^1.0"
2524
pytest-mypy = "^0.8.0"
2625
black = "^23.3.0"
2726
types-PyYAML = "^5.1 || ^6.0"
28-
flake8 = "3.9.2"
27+
flake8 = "^7.0"
2928

3029
[tool.black]
3130
line-length = 100

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
max-line-length = 100
33
per-file-ignores =
44
src/shrub/v2/__init__.py:F401
5+
extend-ignore = W605,W503,W291,E203,E501,F821
56

67
[tool:pytest]
7-
flake8-ignore=W605 W503 W291 E203 E501 F821
8-
addopts = --flake8 --black --mypy
8+
addopts = --black --mypy

src/shrub/v3/evg_command.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any, Dict, Optional, Union, List
44
from typing_extensions import Literal
55

6-
from pydantic import BaseModel
6+
from pydantic import BaseModel, ConfigDict
77

88

99
AvailableCommands = Literal[
@@ -198,9 +198,11 @@ def __init__(self, **kwargs: Dict[str, Any]) -> None:
198198
kwargs["params"] = {k: v for k, v in kwargs["params"].items() if v is not None}
199199
super().__init__(**kwargs)
200200

201-
class Config:
202-
allow_population_by_field_name = True
203-
use_enum_values = True
201+
model_config = ConfigDict(
202+
populate_by_name=True,
203+
use_enum_values=True,
204+
validate_default=True,
205+
)
204206

205207

206208
EvgCommand = Union[

src/shrub/v3/shrub_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def generate_yaml(shrub_config: BaseModel) -> str:
116116
:return: YAML version of given shrub configuration.
117117
"""
118118
return yaml.dump(
119-
shrub_config.dict(exclude_none=True, exclude_unset=True, by_alias=True),
119+
shrub_config.model_dump(exclude_none=True, exclude_unset=True, by_alias=True),
120120
Dumper=ConfigDumper,
121121
default_flow_style=False,
122122
width=float("inf"),
@@ -130,4 +130,4 @@ def generate_json(shrub_config: BaseModel) -> str:
130130
:param shrub_config: Shrub configuration to generate.
131131
:return: JSON version of given shrub configuration.
132132
"""
133-
return shrub_config.json(exclude_none=True, exclude_unset=True, by_alias=True)
133+
return shrub_config.model_dump_json(exclude_none=True, exclude_unset=True, by_alias=True)

tests/shrub/v3/test_evg_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_expansions_update(self):
2424
updates=[under_test.KeyValueParam(key=f"key_{i}", value=f"value_{i}") for i in range(5)]
2525
)
2626

27-
assert cmd.dict(exclude_none=True, exclude_unset=True) == {
27+
assert cmd.model_dump(exclude_none=True, exclude_unset=True) == {
2828
"command": "expansions.update",
2929
"params": {
3030
"updates": [

0 commit comments

Comments
 (0)