Skip to main content
added 254 characters in body
Source Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228

If the path is only pointing to executables you call, you should consider putting links in standard locations during install (/usr/bin/ or /usr/local/bin) and have the executable find out where they were invoked from and then have them derive the path to any data files from that.

You would use the following:

/usr/bin/myprog    
/opt/myprog/bin/myprog
/opt/myprog/data/picture_01.img

have /usr/bin/myprog be a link to /opt/myprog/bin/myprog and /opt/myprog/bin/ should not be in your $PATH. Setup the link by doing sudo ln -s /opt/myprog/bin/myprog /usr/bin, and have in /opt/myprog/bin/myprog do:

import sys
import os

base_dir = os.path.realpath(sys.argv[0]).rsplit('/bin/', 1)[0]

To determine /opt/myprog dynamically at run-time


If the python API is based on some included module, make sure that module gets installed in the PYTHONPATH search path of a systems python, then you can just do import yourapimodule in a python executable and use it.


If these are data files that can be installed anywhere, consider having a configuration file that you read and that could be ~/.config/yourapimodule/config.ini, ~/.yourapimodule/config.ini or ~/.yourapimodule.ini.¹ (Instead of .ini you could use other formats like .json, whatever you prefer).

¹ Shameless plug: If you are using Python's argparse to handle commandline arguments, then have a look at the package ruamel.appconfig, that I wrote, it sets up the config for you and allows you to specify defaults in the config file for commandline parsing.

If the path is only pointing to executables you call, you should consider putting links in standard locations during install (/usr/bin/ or /usr/local/bin) and have the executable find out where they were invoked from and then have them derive the path to any data files from that.

You would use the following:

/usr/bin/myprog    
/opt/myprog/bin/myprog
/opt/myprog/data/picture_01.img

have /usr/bin/myprog be a link to /opt/myprog/bin/myprog and /opt/myprog/bin/ should not be in your $PATH.


If the python API is based on some included module, make sure that module gets installed in the PYTHONPATH search path of a systems python, then you can just do import yourapimodule in a python executable and use it.


If these are data files that can be installed anywhere, consider having a configuration file that you read and that could be ~/.config/yourapimodule/config.ini, ~/.yourapimodule/config.ini or ~/.yourapimodule.ini.¹ (Instead of .ini you could use other formats like .json, whatever you prefer).

¹ Shameless plug: If you are using Python's argparse to handle commandline arguments, then have a look at the package ruamel.appconfig, that I wrote, it sets up the config for you and allows you to specify defaults in the config file for commandline parsing.

If the path is only pointing to executables you call, you should consider putting links in standard locations during install (/usr/bin/ or /usr/local/bin) and have the executable find out where they were invoked from and then have them derive the path to any data files from that.

You would use the following:

/usr/bin/myprog    
/opt/myprog/bin/myprog
/opt/myprog/data/picture_01.img

have /usr/bin/myprog be a link to /opt/myprog/bin/myprog and /opt/myprog/bin/ should not be in your $PATH. Setup the link by doing sudo ln -s /opt/myprog/bin/myprog /usr/bin, and have in /opt/myprog/bin/myprog do:

import sys
import os

base_dir = os.path.realpath(sys.argv[0]).rsplit('/bin/', 1)[0]

To determine /opt/myprog dynamically at run-time


If the python API is based on some included module, make sure that module gets installed in the PYTHONPATH search path of a systems python, then you can just do import yourapimodule in a python executable and use it.


If these are data files that can be installed anywhere, consider having a configuration file that you read and that could be ~/.config/yourapimodule/config.ini, ~/.yourapimodule/config.ini or ~/.yourapimodule.ini.¹ (Instead of .ini you could use other formats like .json, whatever you prefer).

¹ Shameless plug: If you are using Python's argparse to handle commandline arguments, then have a look at the package ruamel.appconfig, that I wrote, it sets up the config for you and allows you to specify defaults in the config file for commandline parsing.

added 254 characters in body
Source Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228

If the path is only pointing to executables you call, you should consider putting links in standard locations during install (/usr/bin/ or /usr/local/bin) and have the executable find out where they were invoked from and then have them derive the path to any data files from that.

You would use the following:

/usr/bin/myprog    
/opt/myprog/bin/myprog
/opt/myprog/data/picture_01.img

have /usr/bin/myprog be a link to /opt/myprog/bin/myprog and /opt/myprog/bin/ should not be in your $PATH.


If the python API is based on some included module, make sure that module gets installed in the PYTHONPATH search path of a systems python, then you can just do import yourapimodule in a python executable and use it.

 

If these are data files that can be installed anywhere, consider having a configuration file that you read and that could be ~/.config/yourapimodule/config.ini, ~/.yourapimodule/config.ini or ~/.yourapimodule.ini.¹ (Instead of .ini you could use other formats like .json, whatever you prefer).

¹ Shameless plug: If you are using Python's argparse to handle commandline arguments, then have a look at the package ruamel.appconfig, that I wrote, it sets up the config for you and allows you to specify defaults in the config file for commandline parsing.

If the path is only pointing to executables you call, you should consider putting links in standard locations during install (/usr/bin/ or /usr/local/bin) and have the executable find out where they were invoked from and then have them derive the path to any data files from that.

If the python API is based on some included module, make sure that module gets installed in the PYTHONPATH search path of a systems python, then you can just do import yourapimodule in a python executable and use it.

If these are data files that can be installed anywhere, consider having a configuration file that you read and that could be ~/.config/yourapimodule/config.ini, ~/.yourapimodule/config.ini or ~/.yourapimodule.ini.¹ (Instead of .ini you could use other formats like .json, whatever you prefer).

¹ Shameless plug: If you are using Python's argparse to handle commandline arguments, then have a look at the package ruamel.appconfig, that I wrote, it sets up the config for you and allows you to specify defaults in the config file for commandline parsing.

If the path is only pointing to executables you call, you should consider putting links in standard locations during install (/usr/bin/ or /usr/local/bin) and have the executable find out where they were invoked from and then have them derive the path to any data files from that.

You would use the following:

/usr/bin/myprog    
/opt/myprog/bin/myprog
/opt/myprog/data/picture_01.img

have /usr/bin/myprog be a link to /opt/myprog/bin/myprog and /opt/myprog/bin/ should not be in your $PATH.


If the python API is based on some included module, make sure that module gets installed in the PYTHONPATH search path of a systems python, then you can just do import yourapimodule in a python executable and use it.

 

If these are data files that can be installed anywhere, consider having a configuration file that you read and that could be ~/.config/yourapimodule/config.ini, ~/.yourapimodule/config.ini or ~/.yourapimodule.ini.¹ (Instead of .ini you could use other formats like .json, whatever you prefer).

¹ Shameless plug: If you are using Python's argparse to handle commandline arguments, then have a look at the package ruamel.appconfig, that I wrote, it sets up the config for you and allows you to specify defaults in the config file for commandline parsing.

Source Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228

If the path is only pointing to executables you call, you should consider putting links in standard locations during install (/usr/bin/ or /usr/local/bin) and have the executable find out where they were invoked from and then have them derive the path to any data files from that.

If the python API is based on some included module, make sure that module gets installed in the PYTHONPATH search path of a systems python, then you can just do import yourapimodule in a python executable and use it.

If these are data files that can be installed anywhere, consider having a configuration file that you read and that could be ~/.config/yourapimodule/config.ini, ~/.yourapimodule/config.ini or ~/.yourapimodule.ini.¹ (Instead of .ini you could use other formats like .json, whatever you prefer).

¹ Shameless plug: If you are using Python's argparse to handle commandline arguments, then have a look at the package ruamel.appconfig, that I wrote, it sets up the config for you and allows you to specify defaults in the config file for commandline parsing.