Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion commitizen/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,25 @@ def set(self, pyproject: tomlkit.TOMLDocument, version: str):
class CargoProvider(TomlProvider):
"""
Cargo version management

With support for `workspaces`
"""

filename = "Cargo.toml"

def get(self, document: tomlkit.TOMLDocument) -> str:
return document["package"]["version"] # type: ignore
try:
return document["package"]["version"] # type: ignore
except tomlkit.exceptions.NonExistentKey:
...
return document["workspace"]["package"]["version"] # type: ignore

def set(self, document: tomlkit.TOMLDocument, version: str):
try:
document["workspace"]["package"]["version"] = version # type: ignore
return
except tomlkit.exceptions.NonExistentKey:
...
document["package"]["version"] = version # type: ignore


Expand Down
34 changes: 26 additions & 8 deletions tests/test_version_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture):
mock.assert_called_once_with("version", "43.1")


FILE_PROVIDERS = dict(
pep621=(
FILE_PROVIDERS = [
(
"pep621",
"pyproject.toml",
Pep621Provider,
"""\
Expand All @@ -70,7 +71,8 @@ def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture):
version = "42.1"
""",
),
poetry=(
(
"poetry",
"pyproject.toml",
PoetryProvider,
"""\
Expand All @@ -82,7 +84,21 @@ def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture):
version = "42.1"
""",
),
cargo=(
(
"cargo",
"Cargo.toml",
CargoProvider,
"""\
[workspace.package]
version = "0.1.0"
""",
"""\
[workspace.package]
version = "42.1"
""",
),
(
"cargo",
"Cargo.toml",
CargoProvider,
"""\
Expand All @@ -94,7 +110,8 @@ def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture):
version = "42.1"
""",
),
npm=(
(
"npm",
"package.json",
NpmProvider,
"""\
Expand All @@ -110,7 +127,8 @@ def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture):
}
""",
),
composer=(
(
"composer",
"composer.json",
ComposerProvider,
"""\
Expand All @@ -126,12 +144,12 @@ def test_commitizen_provider(config: BaseConfig, mocker: MockerFixture):
}
""",
),
)
]


@pytest.mark.parametrize(
"id,filename,cls,content,expected",
(pytest.param(id, *FILE_PROVIDERS[id], id=id) for id in FILE_PROVIDERS),
FILE_PROVIDERS,
)
def test_file_providers(
config: BaseConfig,
Expand Down