Skip to content

Commit

Permalink
pyupgrade fixeas
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaganKing committed May 16, 2024
1 parent 2381668 commit ad2cf17
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
8 changes: 5 additions & 3 deletions cupid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions cupid/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,23 @@ 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()

if "compute_notebooks" in control:
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(
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<img.*?> ", "", file1)
file_rest = f.read()
Expand Down

0 comments on commit ad2cf17

Please sign in to comment.