4577
Comment: changed prefix format
|
← Revision 7 as of 2009-11-24 11:28:40 ⇥
4738
Incorporated changes suggested by ronny
|
Deletions are marked like this. | Additions are marked like this. |
Line 24: | Line 24: |
Valid identifiers must adhere to the regular expression `^$[a-z_]+`, i.e a `$` followed by any combination of lowercase ASCII characters and the underscore. | Valid identifiers must adhere to the regular expression `^[a-z_]+`, i.e any combination of lowercase ASCII characters and the underscore. |
Line 29: | Line 29: |
The full path for the prefix identifier for this distribution. A `/` seperated path will be used regardless of the target system. All paths except those for `$base` and `$platbase` are relative to those two as detailed below. |
The path for the prefix identifier for this distribution. A `/` seperated path will be used regardless of the target system. The path definition can be either absolute or prefixed with one of the identifiers defined below. An absolute path is only used if the installation location is not relative to sys.prefix ($base) or sys.exec_prefix ($platbase). |
Line 66: | Line 69: |
}}} Custom installation scheme: {{{ base,/home/sirrobin/.local platbase,/home/sirrobin/.local purelib,$base/lib/pythonX.Y/site-packages platlib,$platbase/lib/pythonX.Y/site-packages scripts,/usr/local/bin data,/usr/local/share/ |
|
Line 104: | Line 118: |
The Distribution class will get the following new methods: | The Distribution class will get a new attribute `prefixes` which holds a dictionary mapping prefix identifiers to their absolute paths. |
Line 106: | Line 121: |
* `get_prefixes()` returns a dictionary with prefix identifiers as keys and local absolute paths as values * `get_prefix(identifier)` returns the local absolute path for prefix with given identifier |
|
Line 111: | Line 124: |
>>> prefixes = pkgutil.get_distribution('foo').get_prefixes() >>> prefixes['$base'] |
>>> foo_dist = pkgutil.get_distribution('foo') >>> foo_dist.prefixes['$base'] |
Line 114: | Line 127: |
>>> prefixes[$data'] | >>> foo_dist.prefixes['$data'] |
Line 116: | Line 129: |
>>> ni_wish = open(os.path.join(prefixes['$data'], 'foo', 'shrubbery.jpg')) >>> foo_dist = pkgutil.get_distribution('foo') >>> foo_dist.get_prefix('$base') '/usr' >>> unladen = open(os.path.join(foo_dist.get_prefix('$data'), 'foo', 'european.swallow')) |
>>> ni_wish = open(os.path.join(foo_dist.prefixes.get('$data'), 'foo', 'shrubbery.jpg')) >>> unladen = open(os.path.join(foo_dist.prefixes['$data'], 'foo', 'european.swallow')) |
Rationale
It is not possible to retrieve the installation paths of data, or other, files for all installation schemes supported by distutils right now. I propose the inclusion of a PREFIX file within the .egg-info directory that holds information on all prefixes set at installation time and a suitable API within pkgutil.
Proposal
PREFIX
The RECORD file is a CSV file, composed of records, one line per prefix. The csv module is used to read the file, with these options:
field delimiter : ,
quoting char : "
line terminator : os.linesep (so \r\n or \n)
Each record is composed of two elements:
prefix identifier
- Prefix identifiers differentiate between the various prefixes used within the installation process.
Valid identifiers must adhere to the regular expression ^[a-z_]+, i.e any combination of lowercase ASCII characters and the underscore.
- Prefix identifiers differentiate between the various prefixes used within the installation process.
path
- The path for the prefix identifier for this distribution.
A / seperated path will be used regardless of the target system. The path definition can be either absolute or prefixed with one of the identifiers defined below. An absolute path is only used if the installation location is not relative to sys.prefix ($base) or sys.exec_prefix ($platbase).
- The path for the prefix identifier for this distribution.
Identifiers
The list of standard identifiers comprises:
$base - Base prefix
$platbase - Platform specific base prefix
$purelib - Pure Python distribution
$platlib - Non-pure Python distribution (i.e one with extensions)
$scripts - Executable Python scripts
$data - Data files
Example
Standard scheme installation on posix:
base,/usr platbase,/usr purelib,$base/lib/pythonX.Y/site-packages platlib,$platbase/lib/pythonX.Y/site-packages scripts,$base/bin data,$base/share
User scheme installation on posix:
base,/home/sirrobin/.local platbase,/home/sirrobin/.local purelib,$base/lib/pythonX.Y/site-packages platlib,$platbase/lib/pythonX.Y/site-packages scripts,$base/bin data,share
Custom installation scheme:
base,/home/sirrobin/.local platbase,/home/sirrobin/.local purelib,$base/lib/pythonX.Y/site-packages platlib,$platbase/lib/pythonX.Y/site-packages scripts,/usr/local/bin data,/usr/local/share/
Default values
Tables summarising the default values on different operating systems:
posix
Prefix identifier |
Default value: Standard scheme |
Default value: User scheme |
Environment variable |
Command line option |
$base |
sys.prefix |
~/.local |
$PYDIST_BASE |
--prefix |
$platbase |
sys.exec_prefix |
~/.local |
$PYDIST_PLATBASE |
--exec-prefix |
$purelib |
$base/lib/pythonX.Y/site-packages |
$base/lib/pythonX.Y/site-packages |
$PYDIST_PURELIB |
--install-purelib |
$platlib |
$platbase/lib/pythonX.Y/site-packages |
$platbase/lib/pythonX.Y/site-packages |
$PYDIST_PLATLIB |
--install-platlib |
$scripts |
$base/bin |
$base/bin |
$PYDIST_SCRIPTS |
--install-scripts |
$data |
$base/share |
$base/share |
$PYDIST_DATA |
--install-data |
nt
Prefix identifier |
Default value: Standard scheme |
Default value: User scheme |
Environment variable |
Command line option |
$base |
sys.prefix |
os.environ.get('%APPDATA%') |
$PYDIST_BASE |
--prefix |
$platbase |
sys.exec_prefix |
os.environ.get('%APPDATA%') |
$PYDIST_PLATBASE |
--exec-prefix |
$purelib |
$base/Python |
$base/Python/PythonXY/site-packages |
$PYDIST_PURELIB |
--install-purelib |
$platlib |
$platbase/Python |
$platbase/Python/PythonXY/site-packages |
$PYDIST_PLATLIB |
--install-platlib |
$scripts |
$base/Scripts |
$base/Python/Scripts |
$PYDIST_SCRIPTS |
--install-scripts |
$data |
$base/Data |
$base/Python/Python26 |
$PYDIST_DATA |
--install-data |
mac
os2
ce
java
riscos
API
The Distribution class will get a new attribute prefixes which holds a dictionary mapping prefix identifiers to their absolute paths.
Usage example:
>>> foo_dist = pkgutil.get_distribution('foo') >>> foo_dist.prefixes['$base'] '/usr' >>> foo_dist.prefixes['$data'] '/usr/share' >>> ni_wish = open(os.path.join(foo_dist.prefixes.get('$data'), 'foo', 'shrubbery.jpg')) >>> unladen = open(os.path.join(foo_dist.prefixes['$data'], 'foo', 'european.swallow'))