23andMe / Yamale

A schema and validator for YAML.
MIT License
679 stars 88 forks source link

Feature Enhancement: yamale.__version__ #194

Closed tjlaboss closed 2 years ago

tjlaboss commented 2 years ago

Python packages frequently have a __version__ attribute. For example:

>>> import numpy as np
>>> np.__version__
'1.20.1'
>>> import yaml
>>> yaml.__version__
'5.4.1'

There is no yamale.__version__ yet.

mildebrandt commented 2 years ago

Hi, thanks for using Yamale!

I don't mind supporting this change if we can keep the version definition in one place. It's currently in setup.py https://github.com/23andMe/Yamale/blob/master/setup.py#L9

If you'd like to submit a PR, please first write a description of the changes you'd make to ensure it's something we can support in the future.

If you're using Python 3.8 or higher, you can do the following:

>>> from importlib.metadata import version
>>> version("yamale")
'4.0.3'

Once Python 3.7 is EOL, yamale can use that same mechanism to provide the __version__ attribute if another solution isn't implemented before then.

tjlaboss commented 2 years ago

I like the idea of placing a VERSION file in the Yamale directory, like this:

setup.py
yamale/
 --| version.py
 --| VERSION
 --| __init__.py

__init__.py would do: from .version import __version__

version.py would look something like this:

import os.path
FNAME = "VERSION"
root = os.path.basename(os.path.abspath(__file__))
with open(os.path.join(root, FNAME), 'r') as f:
    __version__ = f.read().strip()

setup.py would implement something similar.

mildebrandt commented 2 years ago

Sounds good to me!

tjlaboss commented 2 years ago

Resolved with PR #195.