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

[Enhancement] Automatic version number #62

Closed
the01 opened this issue May 30, 2015 · 2 comments
Closed

[Enhancement] Automatic version number #62

the01 opened this issue May 30, 2015 · 2 comments

Comments

@the01
Copy link

the01 commented May 30, 2015

I would like to propose a way to automatically load the version info from the package (init.py) into setup.py:

def get_version():
    import os
    import re
    init_file = os.path.join("html2text", "__init__.py")
    init_lines = open(init_file, 'rt').readlines()
    version_re = r"^__version__ = ['\"]([^'\"]*)['\"]"
    for line in init_lines:
        mo = re.search(version_re, line, re.M)
        if mo:
            return mo.group(1)
    raise RuntimeError(u"Unable to find version string in {}".format(init_file))

and then you just do

setup(
    name="html2text",
    version=get_version(),
    ...
)

Adapted from stackoverflow.com

@the01 the01 changed the title Automatic version number [Enhancement] Automatic version number May 30, 2015
@Alir3z4
Copy link
Owner

Alir3z4 commented May 30, 2015

Good idea, I do this in other projects that I maintain.

lemme know what you think about it ;)

@the01
Copy link
Author

the01 commented May 30, 2015

Using import() with .version is certainly cleaner, but the problem is that you actually import that file, meaning you are running code here. Say if you had some further imports in the init-file, those would get imported too and so on and so on. You might end up with race conditions or difficulties with relative imports...
That's why I went for the more inelegant version of parsing the file line by line while applying a regex.
Well, my 2 cents on the topic..

@Alir3z4 Alir3z4 closed this as completed in 0d32483 Jun 5, 2015
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