How to specify scripting rights using Python Setuptools

I have a Python package that I created and I use setuptools.setup() to install it. The package includes executable scripts that use the scripts parameter of the setup() function.

I install the following:

 sudo python setup.py install 

After installation, executable scripts are located in /usr/local/bin . The only problem is that permissions:

 -rwxr-x--- 1 root root 57 Aug 23 15:13 example_script* 

Instead:

 -rwxr-xr-x 1 root root 57 Aug 23 15:13 example_script* 

Does anyone know how I can specify the permissions of the output executable files or why by default it is not allowed for anyone to execute?

FYI: My umask is 0027 , and the resolution is /usr/local/bin/ is drwxr-xr-x (owner = root group = root). All executable scripts have -rwxr-xr-x permissions in the development area.

+5
source share
1 answer

This question is a bit outdated, but I hope that my answer will be useful to anyone who finds it the same way I do.

I had the same problem with my package. Apparently, neither setuptools nor pip (my peak 1.5.6 ) explicitly allow permissions. Your option is either permission to change manually, or the transition from scripts to the entry_points parameter.

1) Change file permissions manually

It is complex and complete enough, but should work. The idea is that if the installation process puts your executable in /usr/local/bin , it also has permissions on the chmod file to enable executable flags. From setup.py after your setup() sentence, run something like:

 execpath = '/usr/local/bin/yourexec' if os.name is 'posix' and os.path.exists(execpath): os.chmod(execpath, int('755', 8)) 

2) Migration to entry_points

setuptools offers an option for your setup() called entry_points . It accepts a dictionary with the keys console_scripts and gui_scripts , which you can use as follows:

 setup( # Package name, version, author, links, classifiers, etc entry_points = { 'console_scripts': [ 'myexecfile = mypackage.mymainmodule:mymainfunction' ] } ) 

This statement will automatically generate the myexecfile , which calls mymainfunction from mymainmodule of mypackage , which can be easily distributed by you.

The mymainfunction you should know is that entry point functions ( mymainfunction in this example) may not have any arguments. If you passed sys.argv your main function from your executable as an argument, you must rewrite the function to extract and parse sys.argv yourself.

Chris Warrick wrote a good article about this feature called Python Apps Right Way , which may seem useful to you.

+6
source

Source: https://habr.com/ru/post/1200998/


All Articles