MCPcopy Create free account
hub / github.com/dask/dask / save_config

Function save_config

dask/cli.py:114–154  ·  view source on GitHub ↗

Save new config values to dask config file, return new config and path to file.

(
    key: str,
    value: Any,
    config_file: pathlib.Path | None = None,
)

Source from the content-addressed store, hash-verified

112
113
114def save_config(
115 key: str,
116 value: Any,
117 config_file: pathlib.Path | None = None,
118) -> tuple[dict, pathlib.Path]:
119 """
120 Save new config values to dask config file,
121 return new config and path to file.
122 """
123 # If explicit config file wasn't supplied, try finding the first existing
124 # config file w/ this key, falling back to the default config path
125 if config_file is None:
126 config_file = next(
127 dask.config.paths_containing_key(key),
128 pathlib.Path(dask.config.PATH) / "dask.yaml",
129 )
130 config_file.parent.mkdir(exist_ok=True, parents=True)
131
132 if config_file.exists():
133 config = yaml.safe_load(config_file.read_text()) or {}
134 else:
135 config = {}
136
137 dask.config.set({key: value}, config=config)
138 try:
139 config_file.write_text(yaml.dump(config))
140 except OSError as e:
141 raise RuntimeError(f"""
142
143For some reason we couldn't write config to {config_file}.
144Perhaps you don't have permissions here?
145
146You can change the directory where Dask writes config files
147to somewhere else using the DASK_CONFIG environment variable.
148
149For example, you could set the following:
150
151 export DASK_CONFIG=~/.dask
152""") from e
153
154 return config, config_file
155
156
157@config.command(name="list")

Callers 1

config_setFunction · 0.85

Calls 1

setMethod · 0.80

Tested by

no test coverage detected