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

Relying on git rev-parse output fragile on Cygwin+Conda installations #456

Closed
griai opened this issue Jun 20, 2020 · 3 comments
Closed

Relying on git rev-parse output fragile on Cygwin+Conda installations #456

griai opened this issue Jun 20, 2020 · 3 comments

Comments

@griai
Copy link

griai commented Jun 20, 2020

I recognized that under certain conditions setuptools_scm crashes when using Conda plus Cygwin such that the corresponding package cannot be installed easily, anymore.

My setup is the following (which might be a bit non-standard, but I find it is not too esoteric or absurd):

  • Python installed via Conda on Windows
  • git installed via Cygwin

Both, the Python interpreter of my current conda environment as well as git from Cygwin are in my PATH, such that both can be easily called.

When trying to install a package (that I develop and build myself), which uses setuptools_scm, I receive the following error after calling pip install -e . (or directly python setup.py develop):

$ python -m pdb setup.py develop
> d:\...\git-repo\setup.py(1)<module>()
-> """Setup script."""
(Pdb) c
Traceback (most recent call last):
  File "C:\...\miniconda3\lib\pdb.py", line 1703, in main
    pdb._runscript(mainpyfile)
  File "C:\...\miniconda3\lib\pdb.py", line 1572, in _runscript
    self.run(statement)
  File "C:\...\miniconda3\lib\bdb.py", line 580, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "d:\...\git-repo\setup.py", line 1, in <module>
    """Setup script."""
  File "C:\...\miniconda3\lib\site-packages\setuptools\__init__.py", line 144, in setup
    return distutils.core.setup(**attrs)
  File "C:\...\miniconda3\lib\distutils\core.py", line 108, in setup
    _setup_distribution = dist = klass(attrs)
  File "C:\...\miniconda3\lib\site-packages\setuptools\dist.py", line 425, in __init__
    _Distribution.__init__(self, {
  File "C:\...\miniconda3\lib\distutils\dist.py", line 292, in __init__
    self.finalize_options()
  File "C:\...\miniconda3\lib\site-packages\setuptools\dist.py", line 717, in finalize_options
    ep(self)
  File "C:\...\miniconda3\lib\site-packages\setuptools\dist.py", line 724, in _finalize_setup_keywords
    ep.load()(self, ep.name, value)
  File "d:\...\git-repo\.eggs\setuptools_scm-4.1.2-py3.8.egg\setuptools_scm\integration.py", line 17, in version_keyword
    dist.metadata.version = _get_version(config)
  File "d:\...\git-repo\.eggs\setuptools_scm-4.1.2-py3.8.egg\setuptools_scm\__init__.py", line 148, in _get_version
    parsed_version = _do_parse(config)
  File "d:\...\git-repo\.eggs\setuptools_scm-4.1.2-py3.8.egg\setuptools_scm\__init__.py", line 103, in _do_parse
    version = _version_from_entrypoints(config) or _version_from_entrypoints(
  File "d:\...\git-repo\.eggs\setuptools_scm-4.1.2-py3.8.egg\setuptools_scm\__init__.py", line 63, in _version_from_entrypoints
    version = _call_entrypoint_fn(root, config, ep.load())
  File "d:\...\git-repo\.eggs\setuptools_scm-4.1.2-py3.8.egg\setuptools_scm\__init__.py", line 44, in _call_entrypoint_fn
    return fn(root, config=config)
  File "d:\...\git-repo\.eggs\setuptools_scm-4.1.2-py3.8.egg\setuptools_scm\git.py", line 98, in parse
    wd = GitWorkdir.from_potential_worktree(config.absolute_root)
  File "d:\...\git-repo\.eggs\setuptools_scm-4.1.2-py3.8.egg\setuptools_scm\git.py", line 33, in from_potential_worktree
    if not samefile(real_wd, wd):
  File "C:\...\miniconda3\lib\genericpath.py", line 100, in samefile
    s1 = os.stat(f1)
FileNotFoundError: [WinError 3] ... '/cygdrive/d/.../git-repo'

The reason for this error is how from_potential_worktree is working:

(Pdb) up
> d:\...\git-repo\.eggs\setuptools_scm-4.1.2-py3.8.egg\setuptools_scm\git.py(33)from_potential_worktree()
-> if not samefile(real_wd, wd):
(Pdb) l
 28         def from_potential_worktree(cls, wd):
 29             real_wd, _, ret = do_ex("git rev-parse --show-toplevel", wd)
 30             if ret:
 31                 return
 32             trace("real root", real_wd)
 33  ->         if not samefile(real_wd, wd):
 34                 return
 35
 36             return cls(real_wd)
 37
 38         def is_dirty(self):
(Pdb) wd
'D:\\...\\git-repo'
(Pdb) real_wd
'/cygdrive/d/.../git-repo'

It is comparing the working directory wd with the output of git rev-parse. The problem is that git, which was installed via Cygwin, returns a POSIX style path whereas wd on my Windows system is a Windows style path. For the POSIX path the subsequent call to os.stat() fails with the error above.

I am not sure what should be done better instead of relying on the output of eval("git rev-parse"), but this seems to be a bit fragile to me. (Athough I agree that it also has to do with the very specific setup I use.)

@RonnyPfannschmidt
Copy link
Contributor

i feel certain this is a duplicate of #415 - can you verify

@griai
Copy link
Author

griai commented Jun 28, 2020

Yes, you are right. The initial parts of the reports read almost exactly the same. Feel free to close this issue in favor of #415.

@RonnyPfannschmidt
Copy link
Contributor

Thanks

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

No branches or pull requests

2 participants