| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 |
|
| 20 | import os
|
| 21 | import site
|
| 22 | import sys
|
| 23 |
|
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 |
|
| 37 | major_minor = '{}.{}'.format(*sys.version_info)
|
| 38 | site_packages_prefix = os.path.join(
|
| 39 | 'lib', 'python' + major_minor, 'site-packages')
|
| 40 | python_site = os.path.normpath(os.path.join(sys.prefix, site_packages_prefix))
|
| 41 |
|
| 42 | try:
|
| 43 | all_sites_raw = os.environ['GUIX_PYTHONPATH'].split(os.path.pathsep)
|
| 44 | except KeyError:
|
| 45 | all_sites_raw = []
|
| 46 | |
| 47 | all_sites_norm = [os.path.normpath(p) for p in all_sites_raw]
|
| 48 | matching_sites = [p for p in all_sites_norm
|
| 49 | if p.endswith(site_packages_prefix)]
|
| 50 |
|
| 51 | if matching_sites:
|
| 52 | |
| 53 | |
| 54 | for s in matching_sites:
|
| 55 | site.addsitedir(s)
|
| 56 |
|
| 57 | |
| 58 | |
| 59 | |
| 60 | python_site_index = sys.path.index(python_site)
|
| 61 | new_site_start_index = sys.path.index(matching_sites[0])
|
| 62 | if python_site_index < new_site_start_index:
|
| 63 | sys.path = (sys.path[:python_site_index]
|
| 64 | + sys.path[new_site_start_index:]
|
| 65 | + sys.path[python_site_index:new_site_start_index])
|