@@ -31,25 +31,31 @@ def version_from_scm(root):
3131 config = Configuration ()
3232 config .root = root
3333 # TODO: Is it API?
34- return _version_from_entrypoint (config , "setuptools_scm.parse_scm" )
34+ return _version_from_entrypoints (config )
3535
3636
37- def _call_entrypoint_fn (config , fn ):
37+ def _call_entrypoint_fn (root , config , fn ):
3838 if function_has_arg (fn , "config" ):
39- return fn (config . absolute_root , config = config )
39+ return fn (root , config = config )
4040 else :
4141 warnings .warn (
4242 "parse functions are required to provide a named argument"
4343 " 'config' in the future." ,
4444 category = PendingDeprecationWarning ,
4545 stacklevel = 2 ,
4646 )
47- return fn (config . absolute_root )
47+ return fn (root )
4848
4949
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 ())
5359
5460 if version :
5561 return version
@@ -81,20 +87,16 @@ def _do_parse(config):
8187 return meta (tag = pretended , preformatted = True , config = config )
8288
8389 if config .parse :
84- parse_result = _call_entrypoint_fn (config , config .parse )
90+ parse_result = _call_entrypoint_fn (config . absolute_root , config , config .parse )
8591 if isinstance (parse_result , string_types ):
8692 raise TypeError (
8793 "version parse result was a string\n please return a parsed version"
8894 )
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 )
9296 else :
9397 # 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
98100 )
99101
100102 if version :
@@ -121,6 +123,7 @@ def get_version(
121123 relative_to = None ,
122124 tag_regex = None ,
123125 fallback_version = None ,
126+ fallback_root = "." ,
124127 parse = None ,
125128 git_describe_command = None ,
126129):
@@ -133,6 +136,7 @@ def get_version(
133136
134137 config = Configuration ()
135138 config .root = root
139+ config .fallback_root = fallback_root
136140 config .version_scheme = version_scheme
137141 config .local_scheme = local_scheme
138142 config .write_to = write_to
0 commit comments