views:

36

answers:

2

I am configuring a distutils-based setup.py for a python module that is to be installed on a heterogeneous set of resources. Due to the heterogeneity, the location where the module is installed is not the same on each host however disutils picks the host-specific location.

I find that the module is installed without o+rx permissions using disutils (in spite of setting umask ahead of running setup.py). One solution is to manually correct this problem, however I would like an automated means that works on heterogeneous install targets.

For example, is there a way to extract the ending location of the installation from within setup.py?

Any other suggestions?

Thanks!

SetJmp

A: 

I'm not very knowledgeable about disutils, but I am guessing that If you dig through it until You find the place where your files are written then you will see the path variable on that line.

this page might help you

Nathan
A: 

os.path.dirname(_file_) may be what you're looking for. _file_ in a module returns the path the module was loaded from.

Assuming yourmodule is a folder containing Something.py, in setup.py:

import os
#setup(...) call here
from yourmodule import Something
print os.path.dirname(Something.__file__)

The only wrinkle with this would be if your file structure has yourmodule in the same dir as setuputils. In that case, the python loader would preferentially load yourmodule.Something from the current dir.

Two somewhat hackish but effective options to subvert that could be to either

  1. Remove the current directory from the python path, forcing it to load from the files that now exist in site-packages:

    import sys sys.path = sys.path[1:]

  2. Temporarily rename the yourmodule folder right before the import statement.

With option 1, the whole thing is:

import os
import sys

#setup(...) call here

#Remove first entry in sys.path which is current folder (probably impl dependent, but for practical purposes is consistent)
sys.path = sys.path[1:]
from yourmodule import Something
print os.path.dirname(Something.__file__)

I just tested this with one of my setup.py and it works great. Good luck!

coffeetocode