Skip to content

Commit 088c652

Browse files
add --strip-dev flag to command
fixes #222
1 parent f98050a commit 088c652

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* better handling of setuptools install command deprecation
1313
* consider ``pyproject.tomls`` when running as command
1414
* use list in git describe command to avoid shell expansions while supporting both windows and posix
15+
* add ``--strip-dev`` flag to ``python -m setuptools_scm`` to print the next guessed version cleanly
16+
1517

1618
6.3.2
1719
=====

src/setuptools_scm/__main__.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import argparse
22
import os
3-
import warnings
3+
import sys
44

55
from setuptools_scm import _get_version
66
from setuptools_scm.config import Configuration
@@ -15,14 +15,21 @@ def main() -> None:
1515
try:
1616
pyproject = opts.config or _find_pyproject(root)
1717
root = opts.root or os.path.relpath(os.path.dirname(pyproject))
18-
config = Configuration.from_file(pyproject)
19-
config.root = root
18+
config = Configuration.from_file(pyproject, root=root)
2019
except (LookupError, FileNotFoundError) as ex:
2120
# no pyproject.toml OR no [tool.setuptools_scm]
22-
warnings.warn(f"{ex}. Using default configuration.")
23-
config = Configuration(root)
21+
print(
22+
f"Warning: could not use {os.path.relpath(pyproject)},"
23+
" using default configuration.\n"
24+
f" Reason: {ex}.",
25+
file=sys.stderr,
26+
)
27+
config = Configuration(root=root)
2428

25-
print(_get_version(config))
29+
version = _get_version(config)
30+
if opts.strip_dev:
31+
version = version.partition(".dev")[0]
32+
print(version)
2633

2734
if opts.command == "ls":
2835
for fname in find_files(config.root):
@@ -48,6 +55,11 @@ def _get_cli_opts():
4855
help="path to 'pyproject.toml' with setuptools_scm config, "
4956
"default: looked up in the current or parent directories",
5057
)
58+
parser.add_argument(
59+
"--strip-dev",
60+
action="store_true",
61+
help="remove the dev/local parts of the version before printing the version",
62+
)
5163
sub = parser.add_subparsers(title="extra commands", dest="command", metavar="")
5264
# We avoid `metavar` to prevent printing repetitive information
5365
desc = "List files managed by the SCM"

src/setuptools_scm/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def from_file(
168168
name: str = "pyproject.toml",
169169
dist_name=None, # type: str | None
170170
_load_toml=_lazy_tomli_load,
171+
**kwargs,
171172
):
172173
"""
173174
Read Configuration from pyproject.toml (or similar).
@@ -198,7 +199,7 @@ def from_file(
198199
if dist_name is None:
199200
dist_name = _read_dist_name_from_setup_cfg()
200201

201-
return cls(dist_name=dist_name, **section)
202+
return cls(dist_name=dist_name, **section, **kwargs)
202203

203204

204205
def _read_dist_name_from_setup_cfg():

0 commit comments

Comments
 (0)