1
1
import argparse
2
2
import os
3
- import warnings
3
+ import sys
4
4
5
5
from setuptools_scm import _get_version
6
6
from setuptools_scm .config import Configuration
@@ -15,14 +15,21 @@ def main() -> None:
15
15
try :
16
16
pyproject = opts .config or _find_pyproject (root )
17
17
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 )
20
19
except (LookupError , FileNotFoundError ) as ex :
21
20
# 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 )
24
28
25
- print (_get_version (config ))
29
+ version = _get_version (config )
30
+ if opts .strip_dev :
31
+ version = version .partition (".dev" )[0 ]
32
+ print (version )
26
33
27
34
if opts .command == "ls" :
28
35
for fname in find_files (config .root ):
@@ -48,6 +55,11 @@ def _get_cli_opts():
48
55
help = "path to 'pyproject.toml' with setuptools_scm config, "
49
56
"default: looked up in the current or parent directories" ,
50
57
)
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
+ )
51
63
sub = parser .add_subparsers (title = "extra commands" , dest = "command" , metavar = "" )
52
64
# We avoid `metavar` to prevent printing repetitive information
53
65
desc = "List files managed by the SCM"
0 commit comments