示例#1
0
 def lockfile(self) -> dict:
     if not self._lockfile:
         if not self.lockfile_file.is_file():
             raise ProjectError("Lock file does not exist.")
         data = atoml.parse(self.lockfile_file.read_text("utf-8"))
         self._lockfile = data
     return self._lockfile
示例#2
0
def load_config(file_path: Path) -> Dict[str, Any]:
    """Load a nested TOML document into key-value paires

    E.g. ["python"]["path"] will be loaded as "python.path" key.
    """
    def get_item(sub_data: Dict[str, Any]) -> Dict[str, Any]:
        result = {}
        for k, v in sub_data.items():
            if getattr(v, "items", None) is not None:
                result.update({
                    f"{k}.{sub_k}": sub_v
                    for sub_k, sub_v in get_item(v).items()
                })
            else:
                result.update({k: v})
        return result

    if not file_path.is_file():
        return {}
    return get_item(dict(atoml.parse(file_path.read_text("utf-8"))))
示例#3
0
 def pyproject(self) -> Optional[dict]:
     if not self._pyproject and self.pyproject_file.exists():
         data = atoml.parse(self.pyproject_file.read_text("utf-8"))
         self._pyproject = data
     return self._pyproject
示例#4
0
 def pyproject(self) -> dict | None:
     if not self._pyproject and self.pyproject_file.exists():
         data = atoml.parse(self.pyproject_file.read_text("utf-8"))
         self._pyproject = cast(dict, data)
     return self._pyproject