Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fallback_version if SCM isn't found #549

Closed
CharlesB2 opened this issue Mar 29, 2021 · 6 comments · Fixed by #901
Closed

Use fallback_version if SCM isn't found #549

CharlesB2 opened this issue Mar 29, 2021 · 6 comments · Fixed by #901
Labels

Comments

@CharlesB2
Copy link

I'm in some situation (testing my package in Docker) where git isn't available, and thought I could just use fallback_version argument, but it turns out I still get an exception OSError: 'git' was not found.

I found I can overcome this by defining the SETUPTOOLS_SCM_PRETEND_VERSION environment variable, but I thought it would be easier to use fallback_version in this case as well?

I'm not sure I understood the different cases where one should use SETUPTOOLS_SCM_PRETEND_VERSION or fallback_version?

@RonnyPfannschmidt
Copy link
Contributor

please post the full output of the build process when export SETUPTOOLS_SCM_DEBUG=1 is used
also what version is being used
there should not be a error on missing git commands

fallback is supposed to be used when all else fails, so when git fails it should be used
pretend is supposed to be used instead of figuring it, so distros can manage their envs

@CharlesB2
Copy link
Author

Sorry I wasn't clear, I didn't want to report any error as using SETUPTOOLS_SCM_PRETEND_VERSION works when git isn't available.

It was more a suggestion to simplify things from a usage point of view, as for me after reading the docs I was thinking that fallback_version would work. It can be also completing the docs, e.g. to document the different cases where both SETUPTOOLS_SCM_PRETEND_VERSION and fallback_version apply

@RonnyPfannschmidt
Copy link
Contributor

let me be clear, if setuptools_scm fails with fallback set, it is a bug and needs to be fixed

fallback is something you use more as a author
pretend is something you use as a packager

@CharlesB2
Copy link
Author

CharlesB2 commented Mar 30, 2021

OK then, here's the trace for the error I get when fallback_version is defined, and git not installed:

>>> import setuptools_scm
>>> setuptools_scm.get_version(fallback_version="TEST")
l {'root': '.', 'relative_to': None}
root '/work'
relative_to None
dist name: None
looking for ep setuptools_scm.parse_scm /work
found ep .git = setuptools_scm.git:parse
<class 'FileNotFoundError'> [Errno 2] No such file or directory: 'git' <traceback object at 0x7f15e2a4c5c0>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/setuptools_scm/__init__.py", line 169, in get_version
    return _get_version(config)
  File "/usr/local/lib/python3.9/site-packages/setuptools_scm/__init__.py", line 173, in _get_version
    parsed_version = _do_parse(config)
  File "/usr/local/lib/python3.9/site-packages/setuptools_scm/__init__.py", line 127, in _do_parse
    version = _version_from_entrypoints(config) or _version_from_entrypoints(
  File "/usr/local/lib/python3.9/site-packages/setuptools_scm/__init__.py", line 65, in _version_from_entrypoints
    version = _call_entrypoint_fn(root, config, ep.load())
  File "/usr/local/lib/python3.9/site-packages/setuptools_scm/__init__.py", line 46, in _call_entrypoint_fn
    return fn(root, config=config)
  File "/usr/local/lib/python3.9/site-packages/setuptools_scm/git.py", line 115, in parse
    require_command("git")
  File "/usr/local/lib/python3.9/site-packages/setuptools_scm/utils.py", line 142, in require_command
    raise OSError("%r was not found" % name)
OSError: 'git' was not found

Version used is 6.0.1, installed from pip.

@RonnyPfannschmidt
Copy link
Contributor

thanks, the controll flow is indeed incorrect, i'll need to add a test that validates this so i dont introduce it by accident

kszucs added a commit to apache/arrow that referenced this issue May 17, 2021
There is a fallback_version configuration option for setuptools_scm which we don't use: https://github.com/pypa/setuptools_scm#configuration-parameters

Although this setting seems to have issues according to pypa/setuptools_scm#549
We already have a workaround in setup.py for the functionality of the fallback_version option, but it is disabled for the case of sdist: https://github.com/apache/arrow/blob/master/python/setup.py#L529

Closes #10342 from kszucs/ARROW-12619

Authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
Signed-off-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
kszucs added a commit to apache/arrow that referenced this issue May 17, 2021
There is a fallback_version configuration option for setuptools_scm which we don't use: https://github.com/pypa/setuptools_scm#configuration-parameters

Although this setting seems to have issues according to pypa/setuptools_scm#549
We already have a workaround in setup.py for the functionality of the fallback_version option, but it is disabled for the case of sdist: https://github.com/apache/arrow/blob/master/python/setup.py#L529

Closes #10342 from kszucs/ARROW-12619

Authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
Signed-off-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
michalursa pushed a commit to michalursa/arrow that referenced this issue Jun 13, 2021
There is a fallback_version configuration option for setuptools_scm which we don't use: https://github.com/pypa/setuptools_scm#configuration-parameters

Although this setting seems to have issues according to pypa/setuptools_scm#549
We already have a workaround in setup.py for the functionality of the fallback_version option, but it is disabled for the case of sdist: https://github.com/apache/arrow/blob/master/python/setup.py#L529

Closes apache#10342 from kszucs/ARROW-12619

Authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
Signed-off-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
@P403n1x87
Copy link

P403n1x87 commented Nov 26, 2021

I'm also trying to use fallback_version from setup.py inside a git submodle and it seems that the configuration argument is completely ignored as I still get a LookupError as if I didn't set fallback_version at all.

My setup.py has

use_scm_version={"fallback_version": "0.0.0"},

and the debug logs give

    l {'root': '.', 'relative_to': None}
    root '/private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt'
    relative_to None
    dist name: ddtrace
    looking for ep setuptools_scm.parse_scm /private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt
    found ep EntryPoint(name='.git', value='setuptools_scm.git:parse', group='setuptools_scm.parse_scm') in /private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt
    GIT_ASKPASS /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass.sh
    cmd 'git rev-parse --show-prefix'
     in /private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt
    GIT_ASKPASS /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass.sh
    err b'fatal: not a git repository: /private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt/../../.git/modules/prof-probe/slydog-dd-trace-py\n'
    ret 128
    EntryPoint(name='.git', value='setuptools_scm.git:parse', group='setuptools_scm.parse_scm') None
    looking for ep setuptools_scm.parse_scm_fallback /private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt
    found ep EntryPoint(name='setup.py', value='setuptools_scm.hacks:fallback_version', group='setuptools_scm.parse_scm_fallback') in /private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt
    version 0.0.0 -> 0.0.0
    EntryPoint(name='setup.py', value='setuptools_scm.hacks:fallback_version', group='setuptools_scm.parse_scm_fallback') <ScmVersion 0.0.0 d=None n=None d=False b=None>
    scm version <ScmVersion 0.0.0 d=None n=None d=False b=None>
    config {'version_scheme': 'guess-next-dev', 'local_scheme': 'node-and-date'}
    l {'root': '.', 'relative_to': None}
    root '/private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt'
    relative_to None
    dist name: ddtrace
    looking for ep setuptools_scm.parse_scm /private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt
    found ep EntryPoint(name='.git', value='setuptools_scm.git:parse', group='setuptools_scm.parse_scm') in /private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt
    GIT_ASKPASS /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass.sh
    cmd 'git rev-parse --show-prefix'
     in /private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt
    GIT_ASKPASS /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass.sh
    err b'fatal: not a git repository: /private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt/../../.git/modules/prof-probe/slydog-dd-trace-py\n'
    ret 128
    EntryPoint(name='.git', value='setuptools_scm.git:parse', group='setuptools_scm.parse_scm') None
    looking for ep setuptools_scm.parse_scm_fallback /private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt
    found ep EntryPoint(name='setup.py', value='setuptools_scm.hacks:fallback_version', group='setuptools_scm.parse_scm_fallback') in /private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt
    EntryPoint(name='setup.py', value='setuptools_scm.hacks:fallback_version', group='setuptools_scm.parse_scm_fallback') None
    Traceback (most recent call last):
      File "/private/tmp/foo/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 349, in <module>
        main()
      File "/private/tmp/foo/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 331, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
      File "/private/tmp/foo/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 151, in prepare_metadata_for_build_wheel
        return hook(metadata_directory, config_settings)
      File "/private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-build-env-99xv5rim/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 174, in prepare_metadata_for_build_wheel
        self.run_setup()
      File "/private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-build-env-99xv5rim/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 158, in run_setup
        exec(compile(code, __file__, 'exec'), locals())
      File "setup.py", line 150, in <module>
        setup(
      File "/private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-build-env-99xv5rim/overlay/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
        return distutils.core.setup(**attrs)
      File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-build-env-99xv5rim/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 453, in __init__
        _Distribution.__init__(
      File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 292, in __init__
        self.finalize_options()
      File "/private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-build-env-99xv5rim/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 831, in finalize_options
        ep(self)
      File "/private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-build-env-99xv5rim/overlay/lib/python3.9/site-packages/setuptools_scm/integration.py", line 94, in infer_version
        dist.metadata.version = _get_version(config)
      File "/private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-build-env-99xv5rim/overlay/lib/python3.9/site-packages/setuptools_scm/__init__.py", line 177, in _get_version
        parsed_version = _do_parse(config)
      File "/private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-build-env-99xv5rim/overlay/lib/python3.9/site-packages/setuptools_scm/__init__.py", line 135, in _do_parse
        raise LookupError(
    LookupError: setuptools-scm was unable to detect version for '/private/var/folders/zm/3z1wy1b135721pl0l6n61yt00000gn/T/pip-req-build-nc68aatt'.

This seems to be caused by the presence of a pyproject.toml file. The first fallback version (from the setup.py) is overridden by the pyproject.toml, which in my case had no fallback version specified.

davvid added a commit to davvid/git-cola-debian that referenced this issue Jan 23, 2023
We are using SETUPTOOLS_SCM_PRETEND_VERSION because the fallback_version
feature in setuptools_scm does not work when git commands return errors
(eg. when building from a tarball or git repo where no tags are present).

Add a link to the upstream issue adjacent to where
SETUPTOOLS_SCM_PRETEND_VERSION is specified.

Upstream will start providing fallback_version in the next
release so we should be able to remove the environment variable once
the upstream setuptools_scm issue has been resolved.

Signed-off-by: David Aguilar <davvid@gmail.com>
RonnyPfannschmidt added a commit to RonnyPfannschmidt/setuptools_scm that referenced this issue Sep 13, 2023
arvidma pushed a commit to arvidma/setuptools_scm that referenced this issue Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants