Menu

#22 Adding PYTHONPATH to STAFEnv.sh

Unstable (example)
open
Lang:: Perl (5)
5
2008-08-26
2008-06-20
j_collado
No

STAFInst is used to generate STAFEnv.sh file during installation. STAFEnv.sh, in turn, is used to set PATH, LD_LIBRARY_PATH, etc. properly to use staf without much trouble. Just adding "source <installation_path>/STAFEnv.sh" in .bashrc is needed.

However, if some Python development is going to be done, PYTHONPATH environment variable must be properly modified to be able to import PySTAF module. This isn't a very difficult thing to do, though it would be better to have it in STAFEnv.sh and don't having to worry about anything else.

This patch, just does this. It changes STAFInst file for Unix installations to generate a new STAFEnv.sh file that adds STAF installation directory to PYTHONPAH so that PySTAF module can be imported in python. The change doesn't make any test so this change in PYTHONPATH will be applied even if no python support has been compiled for staf. However, this should not make any harm at all in such a case.

By the way, category should be 'Lang::sh' and group 'STAFv3.2.5', but proper options don't seem to be available.

Discussion

  • j_collado

    j_collado - 2008-06-20

    Patch for STAFInst file

     
  • Sharon Lucas

    Sharon Lucas - 2008-08-26
    • assigned_to: nobody --> slucas
     
  • j_collado

    j_collado - 2008-09-01

    Logged In: YES
    user_id=1879218
    Originator: YES

    Hello,

    I've noticed that the patch that I wrote doesn't work in some cases such as running a python script from staf cron service without using a new shell. To solve this, I've found that is much better to add a site-specific configuration file (http://docs.python.org/lib/module-site.html) that would take effect for all users regardless of their shell interpreter. Do you agree?

    Best regards,
    Javier

     
  • Sharon Lucas

    Sharon Lucas - 2008-09-04

    Logged In: YES
    user_id=285070
    Originator: NO

    I don't understand. Could you provide more information? e.g. How did you "add a site-specific configuration file"?

     
  • j_collado

    j_collado - 2008-09-12

    Hello,

    The main idea is that has a module called "site" that is imported automatically each time the interpreter is started unless "-S" option is used. This module is used to set configuration that isn't specific to any user, but that applies to the whole machine. One example of such a configuration is the path the the interpreter uses to locate modules (sys.path). When site module is imported on startup, it looks for ".pth" files to extend the path. For example, in my case, I created a file /usr/local/lib64/python2.4/site-packages/PySTAF.pth whose contents is just:
    # Path for STAF module
    <staf_lib_directory>

    where <staf_lib_directory> is the directory where PySTAF module is located.

    I think that this approach is much better than changing STAFEnv.sh since it applies changes to all users at once without having to change their .bashrc files. So probably patch that I submitted isn't interesting anymore and another one looking adding PySTAF.pth would be better.

    Best regards,
    Javier

     

Log in to post a comment.

MongoDB Logo MongoDB