|
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 |
|
8 | 9 | from typing import Pattern |
9 | 10 |
|
10 | 11 | from . import _config |
| 12 | +from . import _entrypoints |
| 13 | +from . import _run_cmd |
11 | 14 | from . import _types as _t |
12 | 15 | from ._config import Configuration |
13 | | -from ._entrypoints import _version_from_entrypoints |
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 | | - return _version_from_entrypoints(config) |
| 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 |
31 | 41 |
|
32 | 42 |
|
33 | 43 | def parse_fallback_version(config: Configuration) -> ScmVersion | None: |
34 | | - return _version_from_entrypoints(config, fallback=True) |
| 44 | + entrypoint = "setuptools_scm.parse_scm_fallback" |
| 45 | + root = config.fallback_root |
| 46 | + return _entrypoints.version_from_entrypoint(config, entrypoint, root) |
35 | 47 |
|
36 | 48 |
|
37 | 49 | def _do_parse(config: Configuration) -> ScmVersion | None: |
|
0 commit comments