22 from __future__
import annotations
24 __all__ = (
"PexConfigFormatter", )
34 from lsst.pex.config
import Config
35 from lsst.daf.butler.formatters.file
import FileFormatter
39 """Interface for reading and writing pex.config.Config objects from disk.
43 def _readFile(self, path: str, pytype: Optional[Type[Any]] =
None) -> Any:
44 """Read a pex.config.Config instance from the given file.
49 Path to use to open the file.
50 pytype : `type`, optional
51 Class to use to read the config file.
55 data : `lsst.pex.config.Config`
56 Instance of class ``pytype`` read from config file. `None`
57 if the file could not be opened.
59 if not os.path.exists(path):
63 with open(path,
"r")
as fd:
65 return Config._fromPython(config_py)
67 def _writeFile(self, inMemoryDataset: Any) ->
None:
68 """Write the in memory dataset to file on disk.
72 inMemoryDataset : `object`
78 The file could not be written.
80 inMemoryDataset.save(self.fileDescriptor.location.path)