1

I am writing Flask based module with standard setup.py in root directory:

#!/usr/bin/env python
from distutils.core import setup

setup(name=modulename,
      version='0.2.16.dev0',
      description='...',
      author='...',
      ...
     )

I am willing to expose module version using Flask API. What is the correct way to access my own module version programmatically?

Thanks

Update: I forgot to mention that the module is not necessary installed as a standard module and may not be available in PYTHONPATH. This is why this question is not like this and this

1
  • Setting a version in some variable and passing that variable to setup() is not an option, because I am using release tool which automatically sets this version.... Commented Aug 30, 2017 at 11:38

1 Answer 1

0

Put version in version.py or __version__.py or such (inside the package) and import it both in setup.py and the application:

from distutils.core import setup
from mypackage.version import version

setup(…
      version=version,
      …
     )

If importing your package in setup.py causes unwanted side effects you can just read mypackage/version.py and parse it or exec() or import it alone (without the package) with the trick:

from imp import load_source
from os.path import abspath, dirname, join

versionpath = join(abspath(dirname(__file__)), "mypackage", "__version__.py")
load_source("mapackage_version", versionpath)
from mapackage_version import version
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.