bastibe / PySoundCard

PySoundCard is an audio library based on PortAudio, CFFI and NumPy
BSD 3-Clause "New" or "Revised" License
87 stars 9 forks source link

adding __version__ #42

Closed peircej closed 8 years ago

peircej commented 9 years ago

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

mgeier commented 9 years ago

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.

peircej commented 9 years ago

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

mgeier commented 9 years ago

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?

mgeier commented 9 years ago

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 ...

peircej commented 9 years ago

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!

peircej commented 8 years ago

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.

bastibe commented 8 years ago

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

bastibe commented 8 years ago

OK, should be implemented now.

peircej commented 8 years ago

many thanks :-)