kayahr
kayahr

Reputation: 22050

Replace symbols in python script on distribution

I have a python script that outputs the program name, version number and the author when called with command line arguments like --help or --version. Currently this information is hardcoded in the python script itself. But I use distutils for building/packaging the application so all this information is already present in the setup.py. Is it possible to let distutils write metadata like version and author name/email to the built python script so I only need to maintain this data in the setup.py file? Or is there another standard mechanism to handle stuff like that?

Upvotes: 2

Views: 205

Answers (3)

TryPyPy
TryPyPy

Reputation: 6434

Have a file __version__.py in your package's root, create it on build with setup.py and fetch version information from it for --help or --version. That's how Mercurial rolls.

Upvotes: 2

user355252
user355252

Reputation:

Do it the other way around. Add the version number, the author name and other metadata you need in the script to the script itself. Then import or execfile() the script in setup.py, and use the metadata defined in the script as arguments to the setup() function.

Upvotes: 3

Leo Izen
Leo Izen

Reputation: 4289

You could always use sed. The man page for sed is Here.

Do get that for windows (if you're using windows) it is right Here. It usually comes pre-installed on Linux, Unix, and OS X.

Upvotes: 0

Related Questions