setting permissions of python module (python setup install)

I am configuring a distutils-based 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 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

Any other suggestions?

Asked by: Kevin559 | Posted: 06-12-2021

Answer 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

Answered by: Caroline289 | Posted: 07-01-2022

Answer 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, in

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 and it works great. Good luck!

Answered by: Ryan949 | Posted: 07-01-2022

Answer 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

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

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

Answered by: Daisy913 | Posted: 07-01-2022

Similar questions

zip - Set permissions on a compressed file in python

I have a file test.txt that is inside a zip archive The permissions on test.txt are out of my control when it's compressed, but now I want them to be group-writeable. I am extracting the file with Python, and don't want to escape out to the shell. EDIT: Here's what I've got so far: import zipfile z = zipfile.ZipFile('', 'w'...

python - Will Django be a good choice for a permissions based web-app?

I've been exploring the details of Django for about a week now and like what I see. However I've come upon some.. negativity in relation to fine-grained control of permissions to the CRUD interface. What I'm writing is an Intranet client management web-app. The organisation is about 6 tiers, and I need to restrict access to client groups based on tiers. Continually expanding. I have a fairly good idea how I'm going...

python - Amazon S3 permissions

Trying to understand S3...How do you limit access to a file you upload to S3? For example, from a web application, each user has files they can upload, but how do you limit access so only that user has access to that file? It seems like the query string authentication requires an expiration date and that won't work for me, is there another way to do this?

chmod - check permissions of directories in python

i want a python program that given a directory, it will return all directories within that directory that have 775 (rwxrwxr-x) permissions thanks!

python - Permissions for a site only

I have a multilingual Django project. Every language is a different subdomain. So we've decided to use the "sites" application and to create one different site for every language. On that project, I also have a "pages" application, which is quite similar to a CMS. The user can create pages with content and they'll be displayed in the appropriate language site. Now I'm looking to be able to manage advanced p...

python - DB Permissions with Django unit testing

Disclaimer: I'm very new to Django. I must say that so far I really like it. :) (now for the "but"...) But, there seems to be something I'm missing related to unit testing. I'm working on a new project with an Oracle backend. When you run the unit tests, it immediately gives a permissions error when trying to create the schema. So, I get what it's trying to do (create a clean sandbox), but what...

python - How do I change permissions to a socket?

I am trying to run a simple Python based web server given here. And I get the following error message: Traceback (most recent call last): File "", line 63, in <module> main() File "", line 55, in main server = HTTPServer(('', 80), MyHandler) File "/usr/lib/python2.5/SocketSe...

linux - Dropping Root Permissions In Python

I'd like to have a Python program start listening on port 80, but after that execute without root permissions. Is there a way to drop root or to get port 80 without it?

python - Django 1.2 object level permissions - third party solutions?

python - Django Inlines user permissions + view only - permissions issues

I'm not sure if this is a bug or I'm just missing something (although I have already parsed the documentation about inlines), but: Let's say I have a model A. Model A is an inline of model B. User U has full access to model B, but only change permissions to model A (so, no add, nor delete). However, when editing model B, user U can still see the "Add another A" link at the bottom, although U hasn't add perm...

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python