Skip to content

Commit

Permalink
Create dummy modules for all python package attributes
Browse files Browse the repository at this point in the history
This is potentially very slow so it's guarded behind a function that a
user has to call.
  • Loading branch information
adisbladis authored and t184256 committed Jul 23, 2019
1 parent 6912df3 commit e97db7e
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion nixpkgs/__init__.py
Expand Up @@ -112,8 +112,10 @@ class NixPackage:
Returned in place of an actual module
Used to supply a namespace for all python modules in a nix package
"""
def __init__(self, name):
def __init__(self, name, doc=None):
self.__name__ = name
if doc is not None:
self.__doc__ = doc

def __repr__(self):
return ''.join((
Expand Down Expand Up @@ -199,4 +201,25 @@ def load_module(self, name):
sys.path = old_path


def init_module():
"""
Initialise module
This creates completions with docstrings for all derivations in the python package set
"""

attr_path = "python3%sPackages" % sys.version_info.minor
expr = """
with import <nixpkgs> {}; let
drvAttrs = lib.filterAttrs (k: v: (builtins.tryEval v).success && builtins.typeOf v == "set") %s;
meta = builtins.mapAttrs (k: v: if builtins.hasAttr "meta" v then v.meta else {}) drvAttrs;
in builtins.mapAttrs (k: v: if builtins.hasAttr "description" v then v.description else "") meta
""" % attr_path

g = globals()
for attr, desc in nix.eval(expr).items():
if attr not in g:
g[attr] = NixPackage(attr, doc=desc)


sys.meta_path.append(NixpkgsFinder())

0 comments on commit e97db7e

Please sign in to comment.