def add_config(name: str, config_item: ConfigItem) -> None: """Add a config item to the configuration class. Args: name (str): The name of the config item config_item (pdm.project.config.ConfigItem): The config item to add """ Config.add_config(name, config_item)
def __init__( self, core: Core, root_path: str | Path | None, is_global: bool = False, global_config: str | Path | None = None, ) -> None: self._pyproject: dict | None = None self._lockfile: dict | None = None self._environment: Environment | None = None self._python: PythonInfo | None = None self.core = core if global_config is None: global_config = Path.home() / ".pdm/config.toml" self.global_config = Config(Path(global_config), is_global=True) global_project = Path(self.global_config["global_project.path"]) if root_path is None: root_path = ( find_project_root(max_depth=self.global_config["project_max_depth"]) if not is_global else global_project ) if ( not is_global and root_path is None and self.global_config["global_project.fallback"] ): self.core.ui.echo( "Project is not found, fallback to the global project", fg="yellow", err=True, ) root_path = global_project is_global = True self.root = Path(root_path or "").absolute() self.is_global = is_global self.init_global_project() self._lockfile_file = self.root / "pdm.lock"
def project_config(self) -> Config: """Read-and-writable configuration dict for project settings""" return Config(self.root / ".pdm.toml")
def global_config(self) -> Config: """Read-and-writable configuration dict for global settings""" return Config(Path.home() / ".pdm" / "config.toml", is_global=True)
def add_config(name: str, config_item: ConfigItem) -> None: """Add a config item to the configuration class""" Config.add_config(name, config_item)
def global_config(self): return Config(self.root / ".pdm-home" / "config.toml", is_global=True)
def config(self) -> Config: if not self._config: self._config = Config(self.root) return self._config