Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 70b5963

Browse files
woileLee-W
authored andcommitted
feat: add support for cargo workspaces
1 parent 17b2f02 commit 70b5963

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

commitizen/providers.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,25 @@ def set(self, pyproject: tomlkit.TOMLDocument, version: str):
115115
class CargoProvider(TomlProvider):
116116
"""
117117
Cargo version management
118+
119+
With support for `workspaces`
118120
"""
119121

120122
filename = "Cargo.toml"
121123

122124
def get(self, document: tomlkit.TOMLDocument) -> str:
123-
return document["package"]["version"] # type: ignore
125+
try:
126+
return document["package"]["version"] # type: ignore
127+
except tomlkit.exceptions.NonExistentKey:
128+
...
129+
return document["workspace"]["package"]["version"] # type: ignore
124130

125131
def set(self, document: tomlkit.TOMLDocument, version: str):
132+
try:
133+
document["workspace"]["package"]["version"] = version # type: ignore
134+
return
135+
except tomlkit.exceptions.NonExistentKey:
136+
...
126137
document["package"]["version"] = version # type: ignore
127138

128139

tests/test_version_providers.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture):
5757
mock.assert_called_once_with("version", "43.1")
5858

5959

60-
FILE_PROVIDERS = dict(
61-
pep621=(
60+
FILE_PROVIDERS = [
61+
(
62+
"pep621",
6263
"pyproject.toml",
6364
Pep621Provider,
6465
"""\
@@ -70,7 +71,8 @@ def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture):
7071
version = "42.1"
7172
""",
7273
),
73-
poetry=(
74+
(
75+
"poetry",
7476
"pyproject.toml",
7577
PoetryProvider,
7678
"""\
@@ -82,7 +84,21 @@ def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture):
8284
version = "42.1"
8385
""",
8486
),
85-
cargo=(
87+
(
88+
"cargo",
89+
"Cargo.toml",
90+
CargoProvider,
91+
"""\
92+
[workspace.package]
93+
version = "0.1.0"
94+
""",
95+
"""\
96+
[workspace.package]
97+
version = "42.1"
98+
""",
99+
),
100+
(
101+
"cargo",
86102
"Cargo.toml",
87103
CargoProvider,
88104
"""\
@@ -94,7 +110,8 @@ def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture):
94110
version = "42.1"
95111
""",
96112
),
97-
npm=(
113+
(
114+
"npm",
98115
"package.json",
99116
NpmProvider,
100117
"""\
@@ -110,7 +127,8 @@ def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture):
110127
}
111128
""",
112129
),
113-
composer=(
130+
(
131+
"composer",
114132
"composer.json",
115133
ComposerProvider,
116134
"""\
@@ -126,12 +144,12 @@ def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture):
126144
}
127145
""",
128146
),
129-
)
147+
]
130148

131149

132150
@pytest.mark.parametrize(
133151
"id,filename,cls,content,expected",
134-
(pytest.param(id, *FILE_PROVIDERS[id], id=id) for id in FILE_PROVIDERS),
152+
FILE_PROVIDERS,
135153
)
136154
def test_file_providers(
137155
config: BaseConfig,

0 commit comments

Comments
 (0)