From ad2cf1788e20448bacca29219e3167a0c950f492 Mon Sep 17 00:00:00 2001 From: Teagan Date: Thu, 16 May 2024 08:47:46 -0600 Subject: [PATCH] pyupgrade fixeas --- cupid/build.py | 8 +++++--- cupid/util.py | 13 ++++++++----- docs/conf.py | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cupid/build.py b/cupid/build.py index 7962170..69d35a1 100755 --- a/cupid/build.py +++ b/cupid/build.py @@ -36,15 +36,17 @@ def build(config_path): None """ - with open(config_path, "r") as fid: + with open(config_path) as fid: control = yaml.safe_load(fid) sname = control["data_sources"]["sname"] run_dir = control["data_sources"]["run_dir"] - subprocess.run(["jupyter-book", "clean", f"{run_dir}/computed_notebooks/{sname}"]) subprocess.run( - ["jupyter-book", "build", f"{run_dir}/computed_notebooks/{sname}", "--all"], + ["jupyter-book", "clean", f"{run_dir}/computed_notebooks/{sname}"]) + subprocess.run( + ["jupyter-book", "build", + f"{run_dir}/computed_notebooks/{sname}", "--all"], ) # Originally used this code to copy jupyter book HTML to a location to host it online diff --git a/cupid/util.py b/cupid/util.py index 0f774a7..68aea12 100644 --- a/cupid/util.py +++ b/cupid/util.py @@ -47,13 +47,14 @@ def execute_managed_notebook(cls, nb_man, kernel_name, **kwargs): def get_control_dict(config_path): """Get control dictionary from configuration file""" try: - with open(config_path, "r") as fid: + with open(config_path) as fid: control = yaml.safe_load(fid) except FileNotFoundError: print(f"ERROR: {config_path} not found") sys.exit(1) - default_kernel_name = control["computation_config"].pop("default_kernel_name", None) + default_kernel_name = control["computation_config"].pop( + "default_kernel_name", None) control["env_check"] = dict() @@ -61,7 +62,8 @@ def get_control_dict(config_path): for nb_category in control["compute_notebooks"].values(): # pylint: disable=invalid-name for nb, info in nb_category.items(): - info["kernel_name"] = info.get("kernel_name", default_kernel_name) + info["kernel_name"] = info.get( + `"kernel_name", default_kernel_name) if info["kernel_name"] is None: info["kernel_name"] = "cupid-analysis" warnings.warn( @@ -76,7 +78,8 @@ def get_control_dict(config_path): if "compute_scripts" in control: for script_category in control["compute_scripts"].values(): for script, info in script_category.items(): - info["kernel_name"] = info.get("kernel_name", default_kernel_name) + info["kernel_name"] = info.get( + "kernel_name", default_kernel_name) if info["kernel_name"] is None: info["kernel_name"] = "cupid-analysis" warnings.warn( @@ -120,7 +123,7 @@ def setup_book(config_path): path_to_here = os.path.dirname(os.path.realpath(__file__)) - with open(f"{path_to_here}/_jupyter-book-config-defaults.yml", "r") as fid: + with open(f"{path_to_here}/_jupyter-book-config-defaults.yml") as fid: config = yaml.safe_load(fid) # update defaults diff --git a/docs/conf.py b/docs/conf.py index d72d5ca..49a0894 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -26,7 +26,7 @@ os.system(f"cp ../{file} ./") # Remove any images from the first line of the file - with open(file, "r") as f: + with open(file) as f: file1 = f.readline() file1 = re.sub(" ", "", file1) file_rest = f.read()