Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions nixpkgs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ def try_nixpkgs(topmost_name):
if not os.path.exists(store_paths[0]):
raise ex

# Guess sys.path-usable subpaths from them (and flatten the list)
return sum((
glob.glob(os.path.join(p, 'lib', 'py*', '*-packages'))
for p in store_paths
), [])
return store_paths

except Exception as e:
raise ImportError(e)
Expand All @@ -102,10 +98,24 @@ def find_module(self, module_name, package_path):
'''
if module_name.startswith('nixpkgs.'):
try_name = module_name.split('.')[1]
required_paths = try_nixpkgs(try_name)
if required_paths:
store_paths = try_nixpkgs(try_name)
self._add_bin_paths(store_paths)
if store_paths:
# Guess sys.path-usable subpaths from them (and flatten the list)
required_paths = sum((
glob.glob(os.path.join(p, 'lib', 'py*', '*-packages'))
for p in store_paths
), [])
return FromExtraPathsLoader(required_paths)

def _add_bin_paths(self, store_paths):
paths = os.environ['PATH'].split(':')
for store_path in store_paths:
bin_path = os.path.join(store_path, 'bin')
if bin_path not in paths and os.path.isdir(bin_path):
paths.insert(0, bin_path)
os.environ['PATH'] = ':'.join(paths)


class NixPackage:
"""
Expand Down