|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +import logging |
3 | 4 | import re
|
4 | 5 | import warnings
|
5 | 6 | from pathlib import Path
|
|
9 | 10 |
|
10 | 11 | from . import _config
|
11 | 12 | from . import _entrypoints
|
| 13 | +from . import _run_cmd |
12 | 14 | from . import _types as _t
|
13 | 15 | from ._config import Configuration
|
14 | 16 | from ._overrides import _read_pretended_version_for
|
15 | 17 | from ._version_cls import _validate_version_cls
|
16 | 18 | from .version import format_version as _format_version
|
17 | 19 | from .version import ScmVersion
|
18 | 20 |
|
| 21 | +_log = logging.getLogger(__name__) |
| 22 | + |
19 | 23 |
|
20 | 24 | def parse_scm_version(config: Configuration) -> ScmVersion | None:
|
21 |
| - if config.parse is not None: |
22 |
| - parse_result = config.parse(config.absolute_root, config=config) |
23 |
| - if parse_result is not None and not isinstance(parse_result, ScmVersion): |
24 |
| - raise TypeError( |
25 |
| - f"version parse result was {str!r}\n" |
26 |
| - "please return a parsed version (ScmVersion)" |
27 |
| - ) |
28 |
| - return parse_result |
29 |
| - else: |
30 |
| - entrypoint = "setuptools_scm.parse_scm" |
31 |
| - root = config.absolute_root |
32 |
| - return _entrypoints.version_from_entrypoint(config, entrypoint, root) |
| 25 | + try: |
| 26 | + if config.parse is not None: |
| 27 | + parse_result = config.parse(config.absolute_root, config=config) |
| 28 | + if parse_result is not None and not isinstance(parse_result, ScmVersion): |
| 29 | + raise TypeError( |
| 30 | + f"version parse result was {str!r}\n" |
| 31 | + "please return a parsed version (ScmVersion)" |
| 32 | + ) |
| 33 | + return parse_result |
| 34 | + else: |
| 35 | + entrypoint = "setuptools_scm.parse_scm" |
| 36 | + root = config.absolute_root |
| 37 | + return _entrypoints.version_from_entrypoint(config, entrypoint, root) |
| 38 | + except _run_cmd.CommandNotFoundError as e: |
| 39 | + _log.exception("command %s not found while parsing the scm, using fallbacks", e) |
| 40 | + return None |
33 | 41 |
|
34 | 42 |
|
35 | 43 | def parse_fallback_version(config: Configuration) -> ScmVersion | None:
|
|
0 commit comments