jenkins-x-plugins/jx-release-version

Add setup.py support for double quotes

sdinay opened this issue · 0 comments

The current code for finding the version in a setup.py file, only accepts single quotes around the version field.
I believe the code is on this line

pythonSetupRegexp = regexp.MustCompile(`setup\((.|\n)*version\s*=\s*'(\d|\.)*'([^\)]|\n)*\)`)

The fix might be to update the regex and add tests:
I'm sorry I don't write go code often. This is my best guess.

regexp.MustCompile(`setup\((.|\n)*version\s*=\s*['"](\d|\.)*['"]([^\)]|\n)*\)`)

To recreate the error:

jx-release-version --version
Version 2.5.0 - Revision 2ef4e951f50ed149e8b103e3d08ae1a01d848489 - Date Mon Sep 20 11:21:35 UTC 2021%

My setup.py file:

from setuptools import setup, find_packages

setup(
    name="example",
    version="0.0.1",
    author="My Name",
    author_email="my@email.com",
)

Error:

FATAL: Failed to read previous version using "from-file:setup.py": setup call not found in file [REMOVED PATH]/setup.py

The fix is to change the double quotes to single quotes around the version string.

from setuptools import setup, find_packages

setup(
    name="example",
    version='0.0.1',
    author="My Name",
    author_email="my@email.com",
)

This issue is not urgent.
It's a nice to have to add flexibility around which quote (single or double) is used primarily in the codebase.