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

LookupError: setuptools-scm was unable to detect version (due to no git installation) #363

Closed
kratsg opened this issue Oct 18, 2019 · 7 comments
Labels

Comments

@kratsg
Copy link

kratsg commented Oct 18, 2019

Hi,

I'm using this to provide dev versions (which is nice). I have a .gitlab-ci.yml configuration like so:

package:
  image: python:3.7-alpine
  stage: package
  before_script:
    - python -m pip install pep517 --user
  script:
    - python -m pep517.build --source --binary --out-dir dist/ .
  artifacts:
    paths:
      - dist/

for packaging. As it turns out, in the alpine docker images, there is no git (not surprising). What is a little misleading is the error message associated with the fact that git doesn't exist:

$ python -m pep517.build --source --binary --out-dir dist/ .
/tmp/pep517-build-env-6rj6j5_k/lib/python3.7/site-packages/setuptools_scm/utils.py:119: UserWarning: 'git' was not found
  warnings.warn("%r was not found" % name)
Traceback (most recent call last):
  File "/root/.local/lib/python3.7/site-packages/pep517/_in_process.py", line 257, in <module>
    main()
  File "/root/.local/lib/python3.7/site-packages/pep517/_in_process.py", line 240, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
  File "/root/.local/lib/python3.7/site-packages/pep517/_in_process.py", line 213, in build_sdist
    return backend.build_sdist(sdist_directory, config_settings)
  File "/tmp/pep517-build-env-6rj6j5_k/lib/python3.7/site-packages/setuptools/build_meta.py", line 214, in build_sdist
    config_settings)
  File "/tmp/pep517-build-env-6rj6j5_k/lib/python3.7/site-packages/setuptools/build_meta.py", line 194, in _build_with_temp_dir
    self.run_setup()
  File "/tmp/pep517-build-env-6rj6j5_k/lib/python3.7/site-packages/setuptools/build_meta.py", line 142, in run_setup
    exec(compile(code, __file__, 'exec'), locals())
  File "setup.py", line 87, in <module>
    dependency_links=[],
  File "/tmp/pep517-build-env-6rj6j5_k/lib/python3.7/site-packages/setuptools/__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "/usr/local/lib/python3.7/distutils/core.py", line 108, in setup
    _setup_distribution = dist = klass(attrs)
  File "/tmp/pep517-build-env-6rj6j5_k/lib/python3.7/site-packages/setuptools/dist.py", line 447, in __init__
    k: v for k, v in attrs.items()
  File "/usr/local/lib/python3.7/distutils/dist.py", line 292, in __init__
    self.finalize_options()
  File "/tmp/pep517-build-env-6rj6j5_k/lib/python3.7/site-packages/setuptools/dist.py", line 735, in finalize_options
    ep.load()(self, ep.name, value)
  File "/tmp/pep517-build-env-6rj6j5_k/lib/python3.7/site-packages/setuptools_scm/integration.py", line 17, in version_keyword
    dist.metadata.version = get_version(**value)
  File "/tmp/pep517-build-env-6rj6j5_k/lib/python3.7/site-packages/setuptools_scm/__init__.py", line 150, in get_version
    parsed_version = _do_parse(config)
  File "/tmp/pep517-build-env-6rj6j5_k/lib/python3.7/site-packages/setuptools_scm/__init__.py", line 113, in _do_parse
    "use git+https://github.com/user/proj.git#egg=proj" % config.absolute_root
LookupError: setuptools-scm was unable to detect version for '/builds/scipp/itkdb'.

Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work.

For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/root/.local/lib/python3.7/site-packages/pep517/build.py", line 124, in <module>
    main(parser.parse_args())
  File "/root/.local/lib/python3.7/site-packages/pep517/build.py", line 120, in main
    build(args.source_dir, dist, args.out_dir)
  File "/root/.local/lib/python3.7/site-packages/pep517/build.py", line 88, in build
    _do_build(hooks, env, dist, dest)
  File "/root/.local/lib/python3.7/site-packages/pep517/build.py", line 71, in _do_build
    filename = build(td, {})
  File "/root/.local/lib/python3.7/site-packages/pep517/wrappers.py", line 216, in build_sdist
    'config_settings': config_settings,
  File "/root/.local/lib/python3.7/site-packages/pep517/wrappers.py", line 248, in _call_hook
    extra_environ=extra_environ
  File "/root/.local/lib/python3.7/site-packages/pep517/wrappers.py", line 57, in default_subprocess_runner
    check_call(cmd, cwd=cwd, env=env)
  File "/usr/local/lib/python3.7/subprocess.py", line 347, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/local/bin/python', '/root/.local/lib/python3.7/site-packages/pep517/_in_process.py', 'build_sdist', '/tmp/tmph3jvovmt']' returned non-zero exit status 1.

This is probably an easy check to catch if git doesn't exist before trying to use it? To fix this is a simple apk --no-cache add git before trying to run anything else.

@kratsg kratsg changed the title LookupError: setuptools-scm was unable to detect version LookupError: setuptools-scm was unable to detect version (due to missing git) Oct 18, 2019
@kratsg kratsg changed the title LookupError: setuptools-scm was unable to detect version (due to missing git) LookupError: setuptools-scm was unable to detect version (due to no git installation) Oct 18, 2019
@RonnyPfannschmidt
Copy link
Contributor

good find, this should check better

@ddelange
Copy link

would be awesome if this can be a different error when git is not installed, took me a while before I figured this one out :)

@RonnyPfannschmidt
Copy link
Contributor

it should be, i'm currently not in a position to make the required amount of time for setuptools_scm, this likely changes next month

@matthijskooijman
Copy link

matthijskooijman commented May 4, 2020

Rather than checking if git exists, I would suggest trying to execute and treating the error that results from no installed git specially (Assuming subprocess can be made to throw some specific exception in this case, rather than just returning a non-zero exit code, which makes it indistinguishable from git returning the same exit code...).

@RonnyPfannschmidt
Copy link
Contributor

i think this one and #339 an collapse into a single action item

the plan would be to check tool existence in the tool triggered hooks and ensure detailed errors there
(something like a cli_tool_required helper)

@RonnyPfannschmidt
Copy link
Contributor

closing as duplicate of #339

@SoundDesignerToBe
Copy link

Took me hours of trial and error until I clicked on the link to this amazing solution: installing git on the image used in the CI pipeline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

5 participants