Skip to content

Commit 1ecf351

Browse files
fix #960: add a --force-write-version-files flag for the cli
1 parent 0c22186 commit 1ecf351

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
### Added
3+
4+
- fix #960: add a ``--force-write-version-files`` flag for the cli
5+
6+
-->
7+
<!--
8+
### Changed
9+
10+
- A bullet item for the Changed category.
11+
12+
-->
13+
<!--
14+
### Deprecated
15+
16+
- A bullet item for the Deprecated category.
17+
18+
-->
19+
<!--
20+
### Fixed
21+
22+
- A bullet item for the Fixed category.
23+
24+
-->
25+
<!--
26+
### Security
27+
28+
- A bullet item for the Security category.
29+
30+
-->

src/setuptools_scm/_cli.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def main(args: list[str] | None = None) -> None:
3131
)
3232
config = Configuration(inferred_root)
3333

34-
version = _get_version(config, force_write_version_files=False)
34+
version = _get_version(
35+
config, force_write_version_files=opts.force_write_version_files
36+
)
3537
if version is None:
3638
raise SystemExit("ERROR: no version found for", opts)
3739
if opts.strip_dev:
@@ -67,6 +69,12 @@ def _get_cli_opts(args: list[str] | None) -> argparse.Namespace:
6769
action="store_true",
6870
help="remove the dev/local parts of the version before printing the version",
6971
)
72+
parser.add_argument(
73+
"--force-write-version-files",
74+
action="store_true",
75+
help="trigger to write the content of the version files\n"
76+
"its recommended to use normal/editable installation instead)",
77+
)
7078
sub = parser.add_subparsers(title="extra commands", dest="command", metavar="")
7179
# We avoid `metavar` to prevent printing repetitive information
7280
desc = "List files managed by the SCM"

testing/test_cli.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,31 @@ def test_cli_find_pyproject(
5656
with warns_cli_root_override:
5757
out = get_output(["-c", PYPROJECT_TOML, "--root=."])
5858
assert out.startswith("0.1.dev1+")
59+
60+
61+
def test_cli_force_version_files(
62+
wd: WorkDir, monkeypatch: pytest.MonkeyPatch, debug_mode: DebugMode
63+
) -> None:
64+
debug_mode.disable()
65+
wd.commit_testfile()
66+
wd.write(
67+
PYPROJECT_TOML,
68+
"""
69+
[project]
70+
name = "test"
71+
[tool.setuptools_scm]
72+
version_file = "ver.py"
73+
""",
74+
)
75+
monkeypatch.chdir(wd.cwd)
76+
77+
version_file = wd.cwd.joinpath("ver.py")
78+
assert not version_file.exists()
79+
80+
get_output([])
81+
assert not version_file.exists()
82+
83+
output = get_output(["--force-write-version-files"])
84+
assert version_file.exists()
85+
86+
assert output[:5] in version_file.read_text("utf-8")

0 commit comments

Comments
 (0)