Skip to content

Conversation

anarcat
Copy link
Contributor

@anarcat anarcat commented Oct 5, 2016

before this, SETUPTOOLS_SCM_PRETEND_VERSION make setuptools_scm fail
to write the write_to file correctly. this was apparently to avoid
issues with archives, which we believe is not a problem anymore.

this is, however, a problem for other tools like Debian packaging:
there, we use the pretend mechanism to import the version number from
the Debian packaging system (from debian/changelog, usually). this
works at setup time: setuptools_scm has the proper environment and
detects the version. but if the software was written to depend on the
write_to file, it will fail to find that version at runtime because
setup.py will not have written the write_to file properly at build
time.

this patch simply makes sure that the version is written even if the
provided version number is a string, which is usually the case for
pretend version numbers. a fixed test case is also provided.

Closes: #101

before this, SETUPTOOLS_SCM_PRETEND_VERSION make setuptools_scm fail
to write the `write_to` file correctly. this was apparently to avoid
issues with archives, which we believe is not a problem anymore.

this *is*, however, a problem for other tools like Debian packaging:
there, we use the pretend mechanism to import the version number from
the Debian packaging system (from `debian/changelog`, usually). this
works at setup time: setuptools_scm has the proper environment and
detects the version. but if the software was written to depend on the
`write_to` file, it will fail to find that version at runtime because
`setup.py` will not have written the `write_to` file properly at build
time.

this patch simply makes sure that the version is written even if the
provided version number is a string, which is usually the case for
pretend version numbers. a fixed test case is also provided.

Closes: #101
@anarcat
Copy link
Contributor Author

anarcat commented Oct 5, 2016

test before patch:

[1039]anarcat@angela:setuptools_scm130$ py.test testing/test_functions.py 
=================================================== test session starts ====================================================
platform linux2 -- Python 2.7.9 -- py-1.4.25 -- pytest-2.6.3
setuptools version 28.0.0
setuptools_scm version 1.11.1
collected 15 items 

testing/test_functions.py ..............F

========================================================= FAILURES =========================================================
___________________________________________ test_dump_version_works_with_pretend ___________________________________________

tmpdir = local('/tmp/pytest-10/test_dump_version_works_with_p0')
monkeypatch = <_pytest.monkeypatch.monkeypatch instance at 0x7f6ff3a77908>

    def test_dump_version_works_with_pretend(tmpdir, monkeypatch):
        monkeypatch.setenv(PRETEND_KEY, '1.0')
        get_version(write_to=str(tmpdir.join('VERSION.txt')))
>       assert tmpdir.join('VERSION.txt').read() == '1.0'

testing/test_functions.py:64: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python2.7/dist-packages/py/_path/common.py:131: in read
    with self.open(mode) as f:
/usr/lib/python2.7/dist-packages/py/_path/local.py:344: in open
    return py.error.checked_call(open, self.strpath, mode)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <py._error.ErrorMaker object at 0x7f6ff3d3e650>, func = <built-in function open>
args = ('/tmp/pytest-10/test_dump_version_works_with_p0/VERSION.txt', 'r'), kwargs = {}, __tracebackhide__ = False
cls = <class 'py.error.ENOENT'>, value = IOError(2, 'No such file or directory'), tb = <traceback object at 0x7f6ff3a77ab8>
errno = 2

    def checked_call(self, func, *args, **kwargs):
        """ call a function and raise an errno-exception if applicable. """
        __tracebackhide__ = True
        try:
            return func(*args, **kwargs)
        except self.Error:
            raise
        except (OSError, EnvironmentError):
            cls, value, tb = sys.exc_info()
            if not hasattr(value, 'errno'):
                raise
            __tracebackhide__ = False
            errno = value.errno
            try:
                if not isinstance(value, WindowsError):
                    raise NameError
            except NameError:
                # we are not on Windows, or we got a proper OSError
                cls = self._geterrnoclass(errno)
            else:
                try:
                    cls = self._geterrnoclass(_winerrnomap[errno])
                except KeyError:
                    raise value
>           raise cls("%s%r" % (func.__name__, args))
E           ENOENT: [No such file or directory]: open('/tmp/pytest-10/test_dump_version_works_with_p0/VERSION.txt', 'r')

/usr/lib/python2.7/dist-packages/py/_error.py:84: ENOENT
--------------------------------------------------- Captured stdout call ---------------------------------------------------
root '/home/anarcat/src/setuptools_scm'
=========================================== 1 failed, 14 passed in 0.26 seconds ============================================

test after patch:

[1040]anarcat@angela:setuptools_scm1$ PYTHONPATH=. py.test testing/test_functions.py 
=================================================== test session starts ====================================================
platform linux2 -- Python 2.7.9 -- py-1.4.25 -- pytest-2.6.3
setuptools version 28.0.0
setuptools_scm version 1.11.1
collected 15 items 

testing/test_functions.py ...............

================================================ 15 passed in 0.21 seconds =================================================

@RonnyPfannschmidt
Copy link
Contributor

well done

@RonnyPfannschmidt RonnyPfannschmidt merged commit 58e1f22 into pypa:master Oct 5, 2016
@anarcat anarcat deleted the pretend-write branch October 5, 2016 15:10
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

Successfully merging this pull request may close these issues.

SETUPTOOLS_SCM_PRETEND_VERSION doesn't write_to

2 participants