bastibe/PySoundCard

adding __version__

Closed this issue · 9 comments

At the moment I can't find a way to see what version of PySoundCard/File is installed. Could you add a __version__ attribute?

In another project I used something like this to avoid specifying the version number at two different places:

# this is inside of setup.py

# "import" __version__
for line in open("pysoundcard.py"):
    if line.startswith("__version__"):
        exec(line)
        break

setup(..., version=__version__, ...)

Would this be feasible for our case?

I know that exec() is generally dangerous, but would it be safe enough in this very case?

I found other solutions to this problem, often using regular expressions, but all of them adding large amounts of complicated code to setup.py.

For a first pass it's really simple to do with:
from pysoundcard import __version__
in the setup.py

This imports the module before the requirements are checked, i.e. if requirements are missing, they can never be installed.
In other words, this only works if PySoundCard is already installed (or at least all the dependencies).

Or am I missing something?

Here's a link to the official documentation providing a few solutions to this problem:
https://packaging.python.org/en/latest/single_source_version.html

I think my solution is simpler than any of them and not less secure than the one using exec()/execfile().

But I may be completely wrong ...

I see what you're saying, yes. In the package I develop the top layer of
import (an __init__.py file) does very little except for setting up
__version__ and a couple of really core functions

But for pysoundcard, with all the functionality in the one file I can
see this isn't ideal.

Or have a file called version that gets read by both setup.py and
pysoundcard.py:

with open('version') as f:
     __version__ = f.read().split()[0]

But this is overcomplicating things; it is a pretty limited use of
exec() and I'm sure it won't hurt!

Is there still no version info in the package? I'm trying to use pysoundcard as a dependency of a larger package but it makes it really hard given that the API is still changing and I can't detect which version a user has installed.

Oh, I'm sorry. I forgot about this issue. I'll fix it tomorrow.

OK, should be implemented now.

many thanks :-)