LSST Applications g0265f82a02+c6dfa2ddaf,g1162b98a3f+b2075782a9,g2079a07aa2+1b2e822518,g2bbee38e9b+c6dfa2ddaf,g337abbeb29+c6dfa2ddaf,g3ddfee87b4+a60788ef87,g50ff169b8f+2eb0e556e8,g52b1c1532d+90ebb246c7,g555ede804d+a60788ef87,g591dd9f2cf+ba8caea58f,g5ec818987f+864ee9cddb,g858d7b2824+9ee1ab4172,g876c692160+a40945ebb7,g8a8a8dda67+90ebb246c7,g8cdfe0ae6a+4fd9e222a8,g99cad8db69+5e309b7bc6,g9ddcbc5298+a1346535a5,ga1e77700b3+df8f93165b,ga8c6da7877+aa12a14d27,gae46bcf261+c6dfa2ddaf,gb0e22166c9+8634eb87fb,gb3f2274832+d0da15e3be,gba4ed39666+1ac82b564f,gbb8dafda3b+5dfd9c994b,gbeb006f7da+97157f9740,gc28159a63d+c6dfa2ddaf,gc86a011abf+9ee1ab4172,gcf0d15dbbd+a60788ef87,gdaeeff99f8+1cafcb7cd4,gdc0c513512+9ee1ab4172,ge79ae78c31+c6dfa2ddaf,geb67518f79+ba1859f325,geb961e4c1e+f9439d1e6f,gee10cc3b42+90ebb246c7,gf1cff7945b+9ee1ab4172,w.2024.12
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
lsst.pex.config.config.RecordingImporter Class Reference

Public Member Functions

 __init__ (self)
 
 __enter__ (self)
 
 __exit__ (self, *args)
 
 uninstall (self)
 
 find_spec (self, fullname, path, target=None)
 
 getModules (self)
 

Public Attributes

 origMetaPath
 

Protected Attributes

 _modules
 

Detailed Description

Importer (for `sys.meta_path`) that records which modules are being
imported.

*This class does not do any importing itself.*

Examples
--------
Use this class as a context manager to ensure it is properly uninstalled
when done:

>>> with RecordingImporter() as importer:
...     # import stuff
...     import numpy as np
... print("Imported: " + importer.getModules())

Definition at line 873 of file config.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pex.config.config.RecordingImporter.__init__ ( self)

Definition at line 890 of file config.py.

890 def __init__(self):
891 self._modules = set()
892
daf::base::PropertySet * set
Definition fits.cc:931

Member Function Documentation

◆ __enter__()

lsst.pex.config.config.RecordingImporter.__enter__ ( self)

Definition at line 893 of file config.py.

893 def __enter__(self):
894 self.origMetaPath = sys.meta_path
895 sys.meta_path = [self] + sys.meta_path # type: ignore
896 return self
897

◆ __exit__()

lsst.pex.config.config.RecordingImporter.__exit__ ( self,
* args )

Definition at line 898 of file config.py.

898 def __exit__(self, *args):
899 self.uninstall()
900 return False # Don't suppress exceptions
901

◆ find_spec()

lsst.pex.config.config.RecordingImporter.find_spec ( self,
fullname,
path,
target = None )
Find a module.

Called as part of the ``import`` chain of events.

Parameters
----------
fullname : `str`
    Name of module.
path : `list` [`str`]
    Search path. Unused.
target : `~typing.Any`, optional
    Unused.

Definition at line 906 of file config.py.

906 def find_spec(self, fullname, path, target=None):
907 """Find a module.
908
909 Called as part of the ``import`` chain of events.
910
911 Parameters
912 ----------
913 fullname : `str`
914 Name of module.
915 path : `list` [`str`]
916 Search path. Unused.
917 target : `~typing.Any`, optional
918 Unused.
919 """
920 self._modules.add(fullname)
921 # Return None because we don't do any importing.
922 return None
923

◆ getModules()

lsst.pex.config.config.RecordingImporter.getModules ( self)
Get the set of modules that were imported.

Returns
-------
modules : `set` of `str`
    Set of imported module names.

Definition at line 924 of file config.py.

924 def getModules(self):
925 """Get the set of modules that were imported.
926
927 Returns
928 -------
929 modules : `set` of `str`
930 Set of imported module names.
931 """
932 return self._modules
933
934
935# type ignore because type checker thinks ConfigMeta is Generic when it is not

◆ uninstall()

lsst.pex.config.config.RecordingImporter.uninstall ( self)
Uninstall the importer.

Definition at line 902 of file config.py.

902 def uninstall(self):
903 """Uninstall the importer."""
904 sys.meta_path = self.origMetaPath
905

Member Data Documentation

◆ _modules

lsst.pex.config.config.RecordingImporter._modules
protected

Definition at line 891 of file config.py.

◆ origMetaPath

lsst.pex.config.config.RecordingImporter.origMetaPath

Definition at line 894 of file config.py.


The documentation for this class was generated from the following file: