Closed sugatoray closed 3 years ago
Hi, thank you for the feedback!
Indeed, there is no method or attribute that captures the current version in pyteomics. It should be fairly easy to add one for convenience.
However, version info can be extracted fairly easily in Python, like with any other package. See e.g. this answer on SO.
Demo:
In [1]: import pkg_resources
In [2]: pkg_resources.get_distribution('pyteomics').version
Out[2]: '4.4.0.dev1'
Also, on Python 3.8 and newer:
In [1]: from importlib.metadata import version
In [2]: version('pyteomics')
Out[2]: '4.4.0.dev1'
Looking more into this, I find that I cannot easily add anything to pyteomics/__init__.py
, as Pyteomics is a namespace package. Best I can do then is make it available under pyteomics.auxiliary
(which is not as easy to find) or perhaps create a module called pyteomics.version
. Does anyone have any suggestions? @sugatoray @mobiusklein
I think a pyteomics.version
submodule is probably the safest and cleanest way if we want to support this without requiring the user import the those tools (not that we can't try to import and use them ourselves to get it). The top-level module having a __version__
attribute is convenient, but not all packages can support it anyway, and it's not actually part of Python, just a convention.
If there absolutely has to be a __version__
attribute on pyteomics
, we can force that to happen if the user imports at least one submodule first, and then have submodules import the following monkey-patching module
import sys
import pkg_resources
version = pkg_resources.get_distribution('pyteomics').version
sys.modules['pyteomics'].__version__ = version
But this would lead to unexpected behavior when the user just tries to read that attribute off a top-level import of pyteomics
alone.
I tried to find a repo that has some similarity to pyteomics
. Though I am not sure if it is a good example or not, I would suggest you take a look at mendley
repo as an alternative.
They also use a version file (version.py
) that introduces a package.__version__
attribute.
Typically python packages have a dunder method for version:
package.__version__
.It helps to check and log the version of the package under use in an analysis. However, I could not find any such
pyteomics.__version__
method to access the version. I see that you have a fileVERSION
in the repo and thesetup.py
file accesses the current version information from here.Please add a
pyteomics.__version__
method to dynamically provide the version of the package.If however, I have missed out on something or am mistaken please let me know.
Thank you.