zestsoftware / zest.releaser

Python software releasing made easy and repeatable
https://zestreleaser.readthedocs.io
GNU General Public License v2.0
198 stars 62 forks source link

single-quoting a version-number leads to incorrect -<version>- #332

Closed woutervh closed 5 years ago

woutervh commented 5 years ago

I recently started to put my version-numbers inside the package like this

init.py: from version import __version__

version.py: version = "x.y.dev0"

in my setup.py, I parse the version.py (not importing anything)

` def read(*names, **kwargs): r"""Return the contents of a file.

Default encoding is UTF-8, unless specified otherwise.

Args:
    - names (list, required): list of strings, parts of the path.
      the path might be relative to the current file.

Keyword Args:
    **kwargs: Arbitrary keyword arguments.

Returns:
      str: the content of the file.

Examples:
    >>> read("docs/readme.rst")
        "Overview\n--------\n..."

    >>> read("docs", "readme.rst")
        "Overview\n--------\n..."

"""
fn = os.path.join(os.path.dirname(__file__), *names)
with io.open(fn, encoding=kwargs.get("encoding", "utf8")) as fd:
    return fd.read()

def read_version(*names): """ Returns: str: the version-number of the package.

Examples:
    >>> read_version("src/foo/version.py")
        "0.1dev0"

"""
lines = read(*names).split("\n")
for line in lines:
    if line.startswith("__version__"):
        version = line.split("=")[1].strip().strip('"')
        return version

raise RuntimeError("Unable to find version string.")

version = read_version("src/foo/version.py") `

in my setup.cfg I have a section: [zest.releaser] ... python-file-with-version = src/foo/version.py

This works fine.

Now when I make a release with zest.releaser (usually latest version) the version gets written back single-quoted instead of double-quoted

so version = "x.y.dev0" becomes version = 'x.z.dev0'

but the change in quote-style now leads to a version-number
-x.z.dev0- instead of x.z.dev0

when I pip-install my dev-package it reports the version as -x.z.dev0- which cannot be parsed as a version-number. Therefore it cannot be compared, or compared incorrectly, to other versions

the released packages are named foo--x.z-.tar.gz foo-_x.z_-py2.py3-none-any.whl instead of foo-x.z.tar.gz foo-x.z-py2.py3-none-any.whl

I currently don't yet know where the dashes are added and why that would happen. It's also a first for me where I see differences in functionality coming from a difference in quoting-style.

SOLUTION: use double quotes, (black also prefers double quotes)

reinout commented 5 years ago

a) yes, double quotes are the way to go. In some places, I think we actually look at the existing style, but apparently not here. Anyway, double quotes are a nicer default.

b) I think you can work around the problem by also stripping off single quotes:

version = line.split("=")[1].strip().strip('"').strip("'")  # now that's a challenge to type right :-)

The version now gets passed including the single quotes. And python replaces all non-numerical (and abrc) characters with underscores. So that's why you get a such a funny version number.

woutervh commented 5 years ago

Aah , I was not expecting the single-quotes and not stripping them.

This can be closed.