Skip to content

Commit 577aa4c

Browse files
committed
Updated dependency from Pydantic 1 to 2.
1 parent 46be61b commit 577aa4c

16 files changed

+158
-49
lines changed

.pre-commit-config.yaml

+4-7
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,12 @@ repos:
4444
- id: mypy
4545
args: [--no-strict-optional, --ignore-missing-imports]
4646
additional_dependencies: ["pydantic<2.0", "toml", "types-all"]
47-
- repo: https://github.com/terrencepreilly/darglint
48-
rev: v1.8.1
47+
- repo: https://github.com/jsh9/pydoclint
48+
rev: 0.3.2
4949
hooks:
50-
- id: darglint
51-
exclude: test.*|cli\.py
50+
- id: pydoclint
5251
args:
53-
- -v 2
54-
- "--message-template={path}:{line} in `{obj}`:\n {msg_id}: {msg}"
55-
- --strictness=short
52+
- "--config=pyproject.toml"
5653
- repo: https://github.com/econchick/interrogate
5754
rev: 1.5.0 # or master if you're bold
5855
hooks:

bumpversion/config.py

+19-20
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
from bumpversion.scm import SCMInfo
1717
from bumpversion.version_part import VersionConfig
1818

19-
from pydantic import BaseModel, BaseSettings, Field
19+
from pydantic import BaseModel, Field
20+
from pydantic_settings import BaseSettings, SettingsConfigDict
2021

2122
from bumpversion.exceptions import ConfigurationError
2223

@@ -26,32 +27,32 @@
2627
class VersionPartConfig(BaseModel):
2728
"""Configuration of a part of the version."""
2829

29-
values: Optional[list] # Optional. Numeric is used if missing or no items in list
30-
optional_value: Optional[str] # Optional.
30+
values: Optional[list] = None # Optional. Numeric is used if missing or no items in list
31+
optional_value: Optional[str] = None # Optional.
3132
# Defaults to first value. 0 in the case of numeric. Empty string means nothing is optional.
32-
first_value: Optional[str] # Optional. Defaults to first value in values
33+
first_value: Union[str, int, None] = None # Optional. Defaults to first value in values
3334
independent: bool = False
3435

3536

3637
class FileConfig(BaseModel):
3738
"""Search and replace file config."""
3839

39-
filename: Optional[str]
40-
glob: Optional[str] # Conflicts with filename. If both are specified, glob wins
41-
parse: Optional[str] # If different from outer scope
42-
serialize: Optional[List[str]] # If different from outer scope
43-
search: Optional[str] # If different from outer scope
44-
replace: Optional[str] # If different from outer scope
45-
no_regex: Optional[bool] # If different from outer scope
46-
ignore_missing_version: Optional[bool]
40+
filename: Optional[str] = None
41+
glob: Optional[str] = None # Conflicts with filename. If both are specified, glob wins
42+
parse: Optional[str] = None # If different from outer scope
43+
serialize: Optional[List[str]] = None # If different from outer scope
44+
search: Optional[str] = None # If different from outer scope
45+
replace: Optional[str] = None # If different from outer scope
46+
no_regex: Optional[bool] = None # If different from outer scope
47+
ignore_missing_version: Optional[bool] = None
4748

4849

4950
class Config(BaseSettings):
5051
"""Bump Version configuration."""
5152

5253
current_version: Optional[str]
5354
parse: str
54-
serialize: List[str] = Field(min_items=1)
55+
serialize: List[str] = Field(min_length=1)
5556
search: str
5657
replace: str
5758
no_regex: bool
@@ -67,11 +68,9 @@ class Config(BaseSettings):
6768
scm_info: Optional["SCMInfo"]
6869
parts: Dict[str, VersionPartConfig]
6970
files: List[FileConfig]
70-
included_paths: List[str] = []
71-
excluded_paths: List[str] = []
72-
73-
class Config:
74-
env_prefix = "bumpversion_"
71+
included_paths: List[str] = Field(default_factory=list)
72+
excluded_paths: List[str] = Field(default_factory=list)
73+
model_config = SettingsConfigDict(env_prefix="bumpversion_")
7574

7675
def add_files(self, filename: Union[str, List[str]]) -> None:
7776
"""Add a filename to the list of files."""
@@ -177,7 +176,7 @@ def get_configuration(config_file: Union[str, Path, None] = None, **overrides) -
177176
Returns:
178177
The configuration
179178
"""
180-
from bumpversion.scm import SCMInfo, get_scm_info
179+
from bumpversion.scm import SCMInfo, SourceCodeManager, get_scm_info # noqa: F401
181180

182181
config_dict = DEFAULTS.copy()
183182
parsed_config = read_config_file(config_file) if config_file else {}
@@ -195,7 +194,7 @@ def get_configuration(config_file: Union[str, Path, None] = None, **overrides) -
195194
config_dict["files"] = get_all_file_configs(config_dict)
196195

197196
# Resolve the SCMInfo class for Pydantic's BaseSettings
198-
Config.update_forward_refs(SCMInfo=SCMInfo)
197+
Config.model_rebuild()
199198
config = Config(**config_dict) # type: ignore[arg-type]
200199

201200
# Get the information about the SCM

bumpversion/functions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class NumericFunction(PartFunction):
3131

3232
FIRST_NUMERIC = re.compile(r"(\D*)(\d+)(.*)")
3333

34-
def __init__(self, optional_value: Optional[str] = None, first_value: Optional[str] = None):
34+
def __init__(self, optional_value: Union[str, int, None] = None, first_value: Union[str, int, None] = None):
3535
if first_value is not None and not self.FIRST_NUMERIC.search(str(first_value)):
3636
raise ValueError(f"The given first value {first_value} does not contain any digit")
3737

3838
self.first_value = str(first_value or 0)
39-
self.optional_value = optional_value or self.first_value
39+
self.optional_value = str(optional_value or self.first_value)
4040

4141
def bump(self, value: Union[str, int]) -> str:
4242
"""Increase the first numerical value by one."""

bumpversion/version_part.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re
44
import string
55
from copy import copy
6-
from typing import Any, Dict, List, MutableMapping, Optional
6+
from typing import Any, Dict, List, MutableMapping, Optional, Union
77

88
from click import UsageError
99

@@ -23,12 +23,15 @@ class VersionPart:
2323
based on the configuration given.
2424
"""
2525

26-
def __init__(self, config: VersionPartConfig, value: Optional[str] = None):
27-
self._value = value
26+
def __init__(self, config: VersionPartConfig, value: Union[str, int, None] = None):
27+
self._value = str(value) if value is not None else None
2828
self.config = config
2929
self.func: Optional[PartFunction] = None
3030
if config.values:
31-
self.func = ValuesFunction(config.values, config.optional_value, config.first_value)
31+
str_values = [str(v) for v in config.values]
32+
str_optional_value = str(config.optional_value) if config.optional_value is not None else None
33+
str_first_value = str(config.first_value) if config.first_value is not None else None
34+
self.func = ValuesFunction(str_values, str_optional_value, str_first_value)
3235
else:
3336
self.func = NumericFunction(config.optional_value, config.first_value or "0")
3437

pyproject.toml

+10-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ keywords = ["bumpversion", "version", "release"]
3333
dynamic = ["version"]
3434
dependencies = [
3535
"click",
36-
"pydantic<2.0.0",
36+
"pydantic",
37+
"pydantic-settings",
3738
"rich-click",
3839
"rich",
3940
"tomlkit",
@@ -237,3 +238,11 @@ search = "Unreleased"
237238
filename = "CHANGELOG.md"
238239
search = "{current_version}...HEAD"
239240
replace = "{current_version}...{new_version}"
241+
242+
[tool.pydoclint]
243+
style = "google"
244+
exclude = '\.git|tests'
245+
require-return-section-when-returning-nothing = false
246+
arg-type-hints-in-docstring = false
247+
check-return-types = false
248+
quiet = true

requirements/dev.txt

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#
77
alabaster==0.7.13
88
# via sphinx
9+
annotated-types==0.5.0
10+
# via pydantic
911
argopt==0.8.2
1012
# via git-fame
1113
astroid==2.15.6
@@ -103,7 +105,13 @@ pluggy==1.0.0
103105
# via pytest
104106
pre-commit==3.3.3
105107
# via bump-my-version (pyproject.toml)
106-
pydantic==1.10.9
108+
pydantic==2.4.0
109+
# via
110+
# bump-my-version (pyproject.toml)
111+
# pydantic-settings
112+
pydantic-core==2.10.0
113+
# via pydantic
114+
pydantic-settings==2.0.3
107115
# via bump-my-version (pyproject.toml)
108116
pygments==2.15.1
109117
# via
@@ -123,6 +131,8 @@ pytest-mock==3.11.1
123131
# via bump-my-version (pyproject.toml)
124132
python-dateutil==2.8.2
125133
# via ghp-import
134+
python-dotenv==1.0.0
135+
# via pydantic-settings
126136
pyyaml==6.0
127137
# via
128138
# myst-parser
@@ -197,6 +207,7 @@ typing-extensions==4.6.3
197207
# via
198208
# astroid
199209
# pydantic
210+
# pydantic-core
200211
# sphinx-autodoc2
201212
# typer
202213
uc-micro-py==1.0.2

requirements/docs.txt

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#
77
alabaster==0.7.13
88
# via sphinx
9+
annotated-types==0.5.0
10+
# via pydantic
911
astroid==2.15.6
1012
# via sphinx-autodoc2
1113
babel==2.12.1
@@ -57,7 +59,13 @@ myst-parser==2.0.0
5759
# via bump-my-version (pyproject.toml)
5860
packaging==23.1
5961
# via sphinx
60-
pydantic==1.10.9
62+
pydantic==2.4.0
63+
# via
64+
# bump-my-version (pyproject.toml)
65+
# pydantic-settings
66+
pydantic-core==2.10.0
67+
# via pydantic
68+
pydantic-settings==2.0.3
6169
# via bump-my-version (pyproject.toml)
6270
pygments==2.15.1
6371
# via
@@ -66,6 +74,8 @@ pygments==2.15.1
6674
# sphinx
6775
python-dateutil==2.8.2
6876
# via ghp-import
77+
python-dotenv==1.0.0
78+
# via pydantic-settings
6979
pyyaml==6.0
7080
# via myst-parser
7181
requests==2.31.0
@@ -121,6 +131,7 @@ typing-extensions==4.6.3
121131
# via
122132
# astroid
123133
# pydantic
134+
# pydantic-core
124135
# sphinx-autodoc2
125136
uc-micro-py==1.0.2
126137
# via linkify-it-py

requirements/prod.txt

+14-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# pip-compile --output-file=requirements/prod.txt pyproject.toml
66
#
7+
annotated-types==0.5.0
8+
# via pydantic
79
click==8.1.3
810
# via
911
# bump-my-version (pyproject.toml)
@@ -12,10 +14,18 @@ markdown-it-py==3.0.0
1214
# via rich
1315
mdurl==0.1.2
1416
# via markdown-it-py
15-
pydantic==1.10.9
17+
pydantic==2.4.0
18+
# via
19+
# bump-my-version (pyproject.toml)
20+
# pydantic-settings
21+
pydantic-core==2.10.0
22+
# via pydantic
23+
pydantic-settings==2.0.3
1624
# via bump-my-version (pyproject.toml)
1725
pygments==2.15.1
1826
# via rich
27+
python-dotenv==1.0.0
28+
# via pydantic-settings
1929
rich==13.4.2
2030
# via
2131
# bump-my-version (pyproject.toml)
@@ -25,4 +35,6 @@ rich-click==1.6.1
2535
tomlkit==0.11.8
2636
# via bump-my-version (pyproject.toml)
2737
typing-extensions==4.6.3
28-
# via pydantic
38+
# via
39+
# pydantic
40+
# pydantic-core

requirements/test.txt

+14-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# pip-compile --extra=test --output-file=requirements/test.txt pyproject.toml
66
#
7+
annotated-types==0.5.0
8+
# via pydantic
79
cfgv==3.3.1
810
# via pre-commit
911
click==8.1.3
@@ -38,7 +40,13 @@ pluggy==1.0.0
3840
# via pytest
3941
pre-commit==3.3.3
4042
# via bump-my-version (pyproject.toml)
41-
pydantic==1.10.9
43+
pydantic==2.4.0
44+
# via
45+
# bump-my-version (pyproject.toml)
46+
# pydantic-settings
47+
pydantic-core==2.10.0
48+
# via pydantic
49+
pydantic-settings==2.0.3
4250
# via bump-my-version (pyproject.toml)
4351
pygments==2.15.1
4452
# via rich
@@ -51,6 +59,8 @@ pytest-cov==4.1.0
5159
# via bump-my-version (pyproject.toml)
5260
pytest-mock==3.11.1
5361
# via bump-my-version (pyproject.toml)
62+
python-dotenv==1.0.0
63+
# via pydantic-settings
5464
pyyaml==6.0
5565
# via pre-commit
5666
rich==13.4.2
@@ -66,7 +76,9 @@ tomli==2.0.1
6676
tomlkit==0.11.8
6777
# via bump-my-version (pyproject.toml)
6878
typing-extensions==4.6.3
69-
# via pydantic
79+
# via
80+
# pydantic
81+
# pydantic-core
7082
virtualenv==20.23.1
7183
# via pre-commit
7284

setup.cfg

-2
This file was deleted.

setup.py

-4
This file was deleted.

tests/fixtures/basic_cfg_expected.txt

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@
5252
'optional_value': 'gamma',
5353
'values': ['dev', 'gamma']}},
5454
'replace': '{new_version}',
55-
'scm_info': SCMInfo(tool=No SCM tool, commit_sha=None, distance_to_latest_tag=None, current_version=None, dirty=None),
55+
'scm_info': {'branch_name': None,
56+
'commit_sha': None,
57+
'current_version': None,
58+
'dirty': None,
59+
'distance_to_latest_tag': None,
60+
'short_branch_name': None,
61+
'tool': None},
5662
'search': '{current_version}',
5763
'serialize': ['{major}.{minor}.{patch}-{release}', '{major}.{minor}.{patch}'],
5864
'sign_tags': False,

tests/fixtures/basic_cfg_expected.yaml

+8-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ parts:
6565
- "dev"
6666
- "gamma"
6767
replace: "{new_version}"
68-
scm_info: "SCMInfo(tool=No SCM tool, commit_sha=None, distance_to_latest_tag=None, current_version=None, dirty=None)"
68+
scm_info:
69+
branch_name: null
70+
commit_sha: null
71+
current_version: null
72+
dirty: null
73+
distance_to_latest_tag: null
74+
short_branch_name: null
75+
tool: null
6976
search: "{current_version}"
7077
serialize:
7178
- "{major}.{minor}.{patch}-{release}"

tests/fixtures/basic_cfg_expected_full.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@
8080
}
8181
},
8282
"replace": "{new_version}",
83-
"scm_info": "SCMInfo(tool=No SCM tool, commit_sha=None, distance_to_latest_tag=None, current_version=None, dirty=None)",
83+
"scm_info": {
84+
"branch_name": null,
85+
"commit_sha": null,
86+
"current_version": null,
87+
"dirty": null,
88+
"distance_to_latest_tag": null,
89+
"short_branch_name": null,
90+
"tool": null
91+
},
8492
"search": "{current_version}",
8593
"serialize": [
8694
"{major}.{minor}.{patch}-{release}",

0 commit comments

Comments
 (0)