Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Add farm.__version__ #760

@johann-petrak

Description

@johann-petrak

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions