mtkennerly / dunamai

Dynamic versioning library and CLI
https://dunamai.readthedocs.io/en/latest
MIT License
321 stars 23 forks source link

Packaging Exception #23

Closed marcossantiago closed 3 years ago

marcossantiago commented 3 years ago

Hi there,

Thanks for the cool project! I really appreciate it.

I have been testing on a small python project, but I am facing some issues when installing the package that uses dunamai for Version control. Is this supported or am I missing something ?

This is the setup.py:

from setuptools import find_packages, setup
from dunamai import Version, Style

setup(
    name="add_custom_dataplatform",
    version=Version.from_any_vcs().serialize(metadata=False, style=Style.SemVer),
    packages=find_packages()
)

It works great when I create the package or run the commands locally:

$ python setup.py sdist
...
Creating tar archive
removing 'add_custom_dataplatform-0.0.0.post40' (and everything under it)

But fails when I try to install it

$ pip install add_custom_dataplatform-0.0.0.post40.tar.gz
    ERROR: Command errored out with exit status 1:
     command: /Users/user/.virtualenvs/virtualenv/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/wy/p3h2_r9d1kq_rv3wv25yh89r0000gp/T/pip-install-0pyil6o8/add-custom-dataplatform_ce9d669dee4947d58133cffb5e8fec5b/setup.py'"'"'; __file__='"'"'/private/var/folders/wy/p3h2_r9d1kq_rv3wv25yh89r0000gp/T/pip-install-0pyil6o8/add-custom-dataplatform_ce9d669dee4947d58133cffb5e8fec5b/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/wy/p3h2_r9d1kq_rv3wv25yh89r0000gp/T/pip-pip-egg-info-1d0oahm_
         cwd: /private/var/folders/wy/p3h2_r9d1kq_rv3wv25yh89r0000gp/T/pip-install-0pyil6o8/add-custom-dataplatform_ce9d669dee4947d58133cffb5e8fec5b/
    Complete output (9 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/wy/p3h2_r9d1kq_rv3wv25yh89r0000gp/T/pip-install-0pyil6o8/add-custom-dataplatform_ce9d669dee4947d58133cffb5e8fec5b/setup.py", line 6, in <module>
        version=Version.from_git().serialize(metadata=False, style=Style.SemVer),
      File "/Users/user/.virtualenvs/virtualenv/lib/python3.8/site-packages/dunamai/__init__.py", line 485, in from_git
        _detect_vcs(Vcs.Git)
      File "/Users/user/.virtualenvs/virtualenv/lib/python3.8/site-packages/dunamai/__init__.py", line 175, in _detect_vcs
        raise RuntimeError(
    RuntimeError: This does not appear to be a Git project

Please the installation works fine if I set a static version.

mtkennerly commented 3 years ago

One option would be to use wheels instead of an sdist, since the wheel will include the raw version rather than having to re-execute the code to get it.

If you need sdists, then it would probably be best to write an external script that dumps the dynamic version into setup.py (hard-coded as a string) and then reverts it after packaging.

marcossantiago commented 3 years ago

Makes sense. Thank you @mtkennerly. Appreciate.