MCPcopy Create free account
hub / github.com/ipython/traitlets / _load_config_files

Method _load_config_files

traitlets/config/application.py:892–947  ·  view source on GitHub ↗

Load config files (py,json) by filename and path. yield each config object in turn.

(
        cls,
        basefilename: str,
        path: str | t.Sequence[str | None] | None,
        log: AnyLogger | None = None,
        raise_config_file_errors: bool = False,
    )

Source from the content-addressed store, hash-verified

890
891 @classmethod
892 def _load_config_files(
893 cls,
894 basefilename: str,
895 path: str | t.Sequence[str | None] | None,
896 log: AnyLogger | None = None,
897 raise_config_file_errors: bool = False,
898 ) -> t.Generator[t.Any, None, None]:
899 """Load config files (py,json) by filename and path.
900
901 yield each config object in turn.
902 """
903 if os.path.isabs(basefilename):
904 path = [None]
905 if isinstance(path, str) or path is None:
906 path = [path]
907 for current in reversed(path):
908 # path list is in descending priority order, so load files backwards:
909 pyloader = cls.python_config_loader_class(basefilename + ".py", path=current, log=log)
910 if log:
911 log.debug("Looking for %s in %s", basefilename, current or os.getcwd())
912 jsonloader = cls.json_config_loader_class(basefilename + ".json", path=current, log=log)
913 loaded: list[t.Any] = []
914 filenames: list[str] = []
915 for loader in [pyloader, jsonloader]:
916 config = None
917 try:
918 config = loader.load_config()
919 except ConfigFileNotFound:
920 pass
921 except Exception:
922 # try to get the full filename, but it will be empty in the
923 # unlikely event that the error raised before filefind finished
924 filename = loader.full_filename or basefilename
925 # problem while running the file
926 if raise_config_file_errors:
927 raise
928 if log:
929 log.error("Exception while loading config file %s", filename, exc_info=True) # noqa: G201
930 else:
931 if log:
932 log.debug("Loaded config file: %s", loader.full_filename)
933 if config:
934 for filename, earlier_config in zip(filenames, loaded):
935 collisions = earlier_config.collisions(config)
936 if collisions and log:
937 log.warning(
938 "Collisions detected in {0} and {1} config files." # noqa: G001
939 " {1} has higher priority: {2}".format(
940 filename,
941 loader.full_filename,
942 json.dumps(collisions, indent=2),
943 )
944 )
945 yield (config, loader.full_filename)
946 loaded.append(config)
947 filenames.append(loader.full_filename)
948
949 @property

Callers 1

load_config_fileMethod · 0.95

Calls 5

errorMethod · 0.80
collisionsMethod · 0.80
formatMethod · 0.80
appendMethod · 0.80
load_configMethod · 0.45

Tested by

no test coverage detected