use pathlib everywhere
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
import argparse
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Any, get_origin
|
||||
@@ -285,8 +284,8 @@ def set_option(
|
||||
current[option_path_store[-1]] = casted
|
||||
|
||||
# check if there is an existing config file
|
||||
if os.path.exists(settings_file):
|
||||
with open(settings_file) as f:
|
||||
if settings_file.exists():
|
||||
with settings_file.open() as f:
|
||||
current_config = json.load(f)
|
||||
else:
|
||||
current_config = {}
|
||||
@@ -294,7 +293,7 @@ def set_option(
|
||||
# merge and save the new config file
|
||||
new_config = merge(current_config, result)
|
||||
settings_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(settings_file, "w") as f:
|
||||
with settings_file.open("w") as f:
|
||||
json.dump(new_config, f, indent=2)
|
||||
print(file=f) # add newline at the end of the file to make git happy
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ def config_for_machine(flake_dir: Path, machine_name: str) -> dict:
|
||||
settings_path = machine_settings_file(flake_dir, machine_name)
|
||||
if not settings_path.exists():
|
||||
return {}
|
||||
with open(settings_path) as f:
|
||||
with settings_path.open() as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ def set_config_for_machine(flake_dir: Path, machine_name: str, config: dict) ->
|
||||
# write the config to a json file located at {flake}/machines/{machine_name}/settings.json
|
||||
settings_path = machine_settings_file(flake_dir, machine_name)
|
||||
settings_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(settings_path, "w") as f:
|
||||
with settings_path.open("w") as f:
|
||||
json.dump(config, f)
|
||||
|
||||
if flake_dir is not None:
|
||||
|
||||
Reference in New Issue
Block a user