Note that there are some explanatory texts on larger screens.

plurals
  1. POcorrect way to find scripts directory from setup.py in Python distutils?
    primarykey
    data
    text
    <p>I am distributing a package that has this structure:</p> <pre><code>mymodule: mymodule/__init__.py mymodule/code.py scripts/script1.py scripts/script2.py </code></pre> <p>The <code>mymodule</code> subdir of <code>mymodule</code> contains code, and the <code>scripts</code> subdir contains scripts that should be executable by the user.</p> <p>When describing a package installation in <code>setup.py</code>, I use: </p> <pre><code>scripts=['myscripts/script1.py'] </code></pre> <p>To specify where scripts should go. During installation they typically go in some platform/user specific <code>bin</code> directory. The code that I have in <code>mymodule/mymodule</code> needs to make calls to the scripts though. What is the correct way to then find the full path to these scripts? Ideally they should be on the user's path at that point, so if I want to call them out from the shell, I should be able to do:</p> <pre><code>os.system('script1.py args') </code></pre> <p>But I want to call the script by its absolute path, and not rely on the platform specific bin directory being on the <code>PATH</code>, as in:</p> <pre><code># get the directory where the scripts reside in current installation scripts_dir = get_scripts_dir() script1_path = os.path.join(scripts_dir, "script1.py") os.system("%s args" %(script1_path)) </code></pre> <p>How can this be done? thanks.</p> <p><strong>EDIT</strong> removing the code outside of a script is not a practical solution for me. the reason is that I distribute jobs to a cluster system and the way I usually do it is like this: imagine you have a set of tasks you want to run on. I have a script that takes all tasks as input and then calls another script, which runs only on the given task. Something like:</p> <pre><code>main.py: for task in tasks: cmd = "python script.py %s" %(task) execute_on_system(cmd) </code></pre> <p>so <code>main.py</code> needs to know where <code>script.py</code> is, because it needs to be a command executable by <code>execute_on_system</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload