Tutorial :setting permissions of python module (python setup install)



Question:

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?


Solution:1

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


Solution:2

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!


Solution:3

I find that the module is installed without o+rx permissions using disutils

I don’t remember right now if distutils copies the files with their rights as is or if it just copies the contents.

(in spite of setting umask ahead of running setup.py)

I’m not sure how umask and file copying from Python should interact; does umask apply to the system calls or does it need to be explicitly heeded by Python code?

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

There is one, a bit convoluted. What would you do with that information?


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »