-
Notifications
You must be signed in to change notification settings - Fork 248
Add farm.__version__ #760
Description
Instead of putting the version just into setup.py, it would be great to make the version in use available through farm.__version__ as it is common practice with Python packages.
There are many ways to achieve this, one simple way is to have a file farm/_version.py which sets the variable __version__ to the version string and then import that variable into farm/__init__.py
The setup.py script could then load the version from farm/_version.py as well something similar to:
import os
import re
def versionfromfile(*filepath):
infile = os.path.join(here, *filepath)
with open(infile) as fp:
version_match = re.search(
r"^__version__\s*=\s*['\"]([^'\"]*)['\"]", fp.read(), re.M
)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string in {}.".format(infile))
# ...
setup(..., version=versionfromfile("farm/_version.py"), ...)
Whenever the version number needs to get changed, the _version.py file is the only place to change.
(Also the version number could be set to something indiciating non-release versions at all times except when an actual version that gets released on pypi is getting tagged).
I find this approach quite useful and easy to implement in my own packages e.g. gatenlp and a number of popular projects are using similar approaches AFAIK.