@@ -31,25 +31,31 @@ def version_from_scm(root):
31
31
config = Configuration ()
32
32
config .root = root
33
33
# TODO: Is it API?
34
- return _version_from_entrypoint (config , "setuptools_scm.parse_scm" )
34
+ return _version_from_entrypoints (config )
35
35
36
36
37
- def _call_entrypoint_fn (config , fn ):
37
+ def _call_entrypoint_fn (root , config , fn ):
38
38
if function_has_arg (fn , "config" ):
39
- return fn (config . absolute_root , config = config )
39
+ return fn (root , config = config )
40
40
else :
41
41
warnings .warn (
42
42
"parse functions are required to provide a named argument"
43
43
" 'config' in the future." ,
44
44
category = PendingDeprecationWarning ,
45
45
stacklevel = 2 ,
46
46
)
47
- return fn (config . absolute_root )
47
+ return fn (root )
48
48
49
49
50
- def _version_from_entrypoint (config , entrypoint ):
51
- for ep in iter_matching_entrypoints (config .absolute_root , entrypoint ):
52
- version = _call_entrypoint_fn (config , ep .load ())
50
+ def _version_from_entrypoints (config , fallback = False ):
51
+ if fallback :
52
+ entrypoint = "setuptools_scm.parse_scm_fallback"
53
+ root = config .fallback_root
54
+ else :
55
+ entrypoint = "setuptools_scm.parse_scm"
56
+ root = config .absolute_root
57
+ for ep in iter_matching_entrypoints (root , entrypoint ):
58
+ version = _call_entrypoint_fn (root , config , ep .load ())
53
59
54
60
if version :
55
61
return version
@@ -81,20 +87,16 @@ def _do_parse(config):
81
87
return meta (tag = pretended , preformatted = True , config = config )
82
88
83
89
if config .parse :
84
- parse_result = _call_entrypoint_fn (config , config .parse )
90
+ parse_result = _call_entrypoint_fn (config . absolute_root , config , config .parse )
85
91
if isinstance (parse_result , string_types ):
86
92
raise TypeError (
87
93
"version parse result was a string\n please return a parsed version"
88
94
)
89
- version = parse_result or _version_from_entrypoint (
90
- config , "setuptools_scm.parse_scm_fallback"
91
- )
95
+ version = parse_result or _version_from_entrypoints (config , fallback = True )
92
96
else :
93
97
# include fallbacks after dropping them from the main entrypoint
94
- version = _version_from_entrypoint (
95
- config , "setuptools_scm.parse_scm"
96
- ) or _version_from_entrypoint (
97
- config , "setuptools_scm.parse_scm_fallback"
98
+ version = _version_from_entrypoints (config ) or _version_from_entrypoints (
99
+ config , fallback = True
98
100
)
99
101
100
102
if version :
@@ -121,6 +123,7 @@ def get_version(
121
123
relative_to = None ,
122
124
tag_regex = None ,
123
125
fallback_version = None ,
126
+ fallback_root = "." ,
124
127
parse = None ,
125
128
git_describe_command = None ,
126
129
):
@@ -133,6 +136,7 @@ def get_version(
133
136
134
137
config = Configuration ()
135
138
config .root = root
139
+ config .fallback_root = fallback_root
136
140
config .version_scheme = version_scheme
137
141
config .local_scheme = local_scheme
138
142
config .write_to = write_to
0 commit comments