Skip to content

Commit

Permalink
Fix circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
stefsmeets committed Aug 27, 2024
1 parent fbca1d4 commit aa9c485
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
17 changes: 17 additions & 0 deletions src/proteus/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from __future__ import annotations

import sys
from pathlib import Path

if sys.version_info < (3, 11):
import toml

read_config = toml.load
else:
import tomllib

def read_config(path: Path | str) -> dict:
"""Read config file from path"""
with open(path, 'rb') as f:
config = tomllib.load(f)
return config
3 changes: 1 addition & 2 deletions src/proteus/plot/_cpl_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


def get_handler_from_argv(default: str = 'init_coupler.toml') -> Proteus:
"""Attempts to get handler from argv, otherwise defaults to default
"""
"""Attempts to get handler from argv, otherwise defaults to default"""
config_path = sys.argv[1] if len(sys.argv) == 2 else default
handler = Proteus(config_path=config_path)

Expand Down
14 changes: 1 addition & 13 deletions src/proteus/proteus.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from proteus.atmos_clim import RunAtmosphere
from proteus.atmos_clim.agni import DeallocAtmos
from proteus.atmos_clim.wrapper_atmosphere import atm
from proteus.config import read_config
from proteus.utils.constants import (
AU,
L_sun,
Expand Down Expand Up @@ -60,19 +61,6 @@
get_target_from_pressures,
)

if sys.version_info < (3, 11):
import toml

read_config = toml.load
else:
import tomllib

def read_config(path: Path | str) -> dict:
"""Read config file from path"""
with open(path, 'rb') as f:
config = tomllib.load(f)
return config


class Proteus:
def __init__(self, *, config_path: Path | str) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/proteus/utils/plot_offchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import numpy as np

from proteus.proteus import read_config
from proteus.config import read_config


def offchem_read_year(output_dir, year_int, mx_clip_min=1e-30, mx_clip_max=1.0, read_const=False):
Expand Down Expand Up @@ -124,7 +124,7 @@ def ytoint(ypath):
grid_years.append(gp_years)

# OPTIONS dictionary
options = read_config(fol + "/init_coupler.cfg")
options = read_config(fol + "/init_coupler.toml")

gp_opts = dict(options[0])
grid_opts.append(gp_opts)
Expand Down

0 comments on commit aa9c485

Please sign in to comment.