0

For various not-very-good-but-unfortunately-necessary reasons I'm using a setup.py file to manage some binary assets.

During py setup.py build or install I would like to create a .py file in the "normal" Python package being installed by setup.py which contains some details about these binary assets (their absolute path, version information, etc).

What's the best way to create that file?

For example, I'd like it to work something like this:

$ cd my-python-package
$ py setup.py install
...
Installing version 1.23 of my_binary_assets to /some/path...
...
$ python -c "from  my_python_package import binary_asset_version_info as info; print info"
{"path": "/some/path", "version": "1.23"}

(note: I'm using the cmdclass argument to setup(…) to manage the building + installation of the binary assets… I'd just like to know how to create the binary_asset_version_info.py file used in the example)

2
  • Hi David. Can you paste (an edited version of) the setup script and a dump of your tree? Commented Dec 21, 2011 at 16:33
  • Hey Éric. Here's the setup.py I'm using right now, with only the binary file build/install specific stuff removed, and the contents of the my_pkg directory at the bottom: paste.pocoo.org/show/524112 Commented Dec 21, 2011 at 18:11

1 Answer 1

1

At first sight, there is a catch-22 in your requirements: The most obvious place to create this .py file would be in the build or build_py command (to get usual distutils operations like byte-compilation), but you want that file to contain the paths to the installed assets, so you’d have to create it during the install step. I see two ways to solve that:

a) Create your info.py file during build_py, and use distutils machinery to get the installation paths of the assets files

b) Create info.py during install and call distutils.util.byte_compile to byte-compile it

I find both ideas distasteful, but well :) Now, do you know how to fill in the file (i.e. get the install paths from distutils)?

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, neither is ideal. But I think (b) should work. But I don't know: how do I get the install paths from distutils? Right now I'm using os.environ["VIRTUAL_ENV"] which… “works”…
I’ll get back to you on this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.