Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff tardis/io #2827

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tardis/io/atom_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Getting and handling the atomic data.
Getting and handling the atomic data.
"""

from tardis.io.atom_data.base import AtomData
from tardis.io.atom_data.atom_web_download import download_atom_data
from tardis.io.atom_data.base import AtomData
4 changes: 2 additions & 2 deletions tardis/io/atom_data/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
from dataclasses import dataclass

import numpy as np
import pandas as pd
from astropy.units import Quantity
from dataclasses import dataclass

from tardis import constants as const
from tardis.io.atom_data.collision_data import (
Expand Down Expand Up @@ -264,7 +264,7 @@ def from_hdf(cls, fname=None):
)
if nonavailable:
logger.info(
"Non provided Atomic Data: {0}".format(
"Non provided Atomic Data: {}".format(
", ".join(nonavailable)
)
)
Expand Down
10 changes: 4 additions & 6 deletions tardis/io/atom_data/util.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import os
import logging
import os
from pathlib import Path

from tardis.io.configuration.config_internal import get_data_dir
from tardis.io.atom_data.atom_web_download import (
get_atomic_repo_config,
download_atom_data,
)
from tardis.io.configuration.config_internal import get_data_dir

logger = logging.getLogger(__name__)

Expand All @@ -25,7 +24,6 @@
: Path
resolved fpath
"""

fname = Path(fname)
if os.path.exists(fname):
return fname
Expand All @@ -41,13 +39,13 @@
atom_data_name = fname.stem
atom_repo_config = get_atomic_repo_config()
if atom_data_name in atom_repo_config:
raise IOError(
raise OSError(

Check warning on line 42 in tardis/io/atom_data/util.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/atom_data/util.py#L42

Added line #L42 was not covered by tests
f"Atom Data {fname} not found in path or in TARDIS data repo - it is available as download:\n"
f"from tardis.io.atom_data.util import download_atom_data\n"
f"download_atom_data('{atom_data_name}')"
)

raise IOError(
raise OSError(

Check warning on line 48 in tardis/io/atom_data/util.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/atom_data/util.py#L48

Added line #L48 was not covered by tests
f"Atom Data {fname} is not found in current path or in TARDIS data repo. {atom_data_name} "
"is also not a standard known TARDIS atom dataset."
)
10 changes: 6 additions & 4 deletions tardis/io/configuration/config_internal.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging, shutil
import yaml
import logging
import os
import shutil
from pathlib import Path

from tardis import __path__ as TARDIS_PATH
import yaml
from astropy.config import get_config_dir

from tardis import __path__ as TARDIS_PATH

TARDIS_PATH = Path(TARDIS_PATH[0])
DEFAULT_CONFIG_PATH = (
TARDIS_PATH / "data" / "default_tardis_internal_config.yml"
Expand Down Expand Up @@ -46,6 +48,6 @@
data_dir = DEFAULT_DATA_DIR

if not os.path.exists(data_dir):
raise IOError(f"Data directory specified in {data_dir} does not exist")
raise OSError(f"Data directory specified in {data_dir} does not exist")

Check warning on line 51 in tardis/io/configuration/config_internal.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/configuration/config_internal.py#L51

Added line #L51 was not covered by tests

return Path(data_dir)
8 changes: 4 additions & 4 deletions tardis/io/configuration/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, value=None):
"Cannot specify both model and csvy_model in main config file."
)
if hasattr(self, "csvy_model"):
model = dict()
model = {}
csvy_model_path = os.path.join(self.config_dirname, self.csvy_model)
csvy_yml = load_yaml_from_csvy(csvy_model_path)
if "v_inner_boundary" in csvy_yml:
Expand All @@ -109,13 +109,13 @@ def __setitem__(self, key, value):
dict.__setitem__(self, key, value)

def __getitem__(self, key):
return super(ConfigurationNameSpace, self).__getitem__(key)
return super().__getitem__(key)

def __getattr__(self, item):
if item in self:
return self[item]
else:
super(ConfigurationNameSpace, self).__getattribute__(item)
super().__getattribute__(item)

__setattr__ = __setitem__

Expand Down Expand Up @@ -447,7 +447,7 @@ def parse_convergence_section(convergence_section_dict):
return convergence_section_dict

def __init__(self, config_dict):
super(Configuration, self).__init__(config_dict)
super().__init__(config_dict)


def quantity_representer(dumper, data):
Expand Down
5 changes: 2 additions & 3 deletions tardis/io/configuration/config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ def set_defaults(validator, properties, instance, schema):
if "default" in subschema:
instance.setdefault(property, subschema["default"])

for error in validate_properties(
yield from validate_properties(
validator,
properties,
instance,
schema,
):
yield error
)

return validators.extend(
validator_class,
Expand Down
10 changes: 4 additions & 6 deletions tardis/io/configuration/tests/test_config_reader.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# tests for the config reader module
import os
from attr import validate
import pytest
import pandas as pd
from numpy.testing import assert_almost_equal
import pytest
from astropy.units import Quantity
from jsonschema.exceptions import ValidationError
from numpy.testing import assert_almost_equal

from tardis.io.configuration import config_reader
from astropy.units import Quantity
from tardis.io.configuration.config_reader import Configuration
from tardis.plasma.exceptions import PlasmaConfigError
from tardis.plasma.assembly.legacy_assembly import assemble_plasma
from tardis.plasma.exceptions import PlasmaConfigError


def test_convergence_section_parser():
Expand Down
7 changes: 4 additions & 3 deletions tardis/io/configuration/tests/test_configuration_namespace.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from tardis.io.configuration.config_reader import ConfigurationNameSpace
import pytest
from astropy import units as u
import os

import pytest
from astropy import units as u
from numpy.testing import assert_almost_equal

from tardis.io.configuration.config_reader import ConfigurationNameSpace

simple_config_dict = {
"a": {"b": {"param1": 1, "param2": [0, 1, 2 * u.km], "param3": 4.0 * u.km}}
}
Expand Down
2 changes: 1 addition & 1 deletion tardis/io/logger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""
Managing the logging output.
Managing the logging output.
"""
1 change: 0 additions & 1 deletion tardis/io/logger/colored_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,3 @@ def __init__(self, name):
console.setFormatter(color_formatter)

self.addHandler(console)
return
7 changes: 3 additions & 4 deletions tardis/io/logger/logger.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import sys

from tardis.io.logger.colored_logger import ColoredFormatter, formatter_message
from tardis.io.logger.colored_logger import ColoredFormatter

logging.captureWarnings(True)
logger = logging.getLogger("tardis")
Expand All @@ -25,7 +25,7 @@
DEFAULT_SPECIFIC_STATE = False


class FilterLog(object):
class FilterLog:
"""
Filter Log Class for Filtering Logging Output
to a particular level
Expand Down Expand Up @@ -77,7 +77,6 @@ def logging_state(log_level, tardis_config, specific_log_level):
specific_log_level: boolean
Allows to set specific logging levels. Logs of the `log_level` level would be output.
"""

if "debug" in tardis_config:
specific_log_level = (
tardis_config["debug"]["specific_log_level"]
Expand Down Expand Up @@ -115,7 +114,7 @@ def logging_state(log_level, tardis_config, specific_log_level):
specific_log_level = tardis_config["debug"]["specific_log_level"]

logging_level = logging_level.upper()
if not logging_level in LOGGING_LEVELS:
if logging_level not in LOGGING_LEVELS:
raise ValueError(
f"Passed Value for log_level = {logging_level} is Invalid. Must be one of the following {list(LOGGING_LEVELS.keys())}"
)
Expand Down
1 change: 0 additions & 1 deletion tardis/io/logger/montecarlo_tracking.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from functools import wraps

DEBUG_MODE = False
LOG_FILE = False
Expand Down
14 changes: 7 additions & 7 deletions tardis/io/logger/tests/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest
import logging

import pytest

from tardis import run_tardis
from tardis.io.configuration.config_reader import Configuration
from tardis.simulation import Simulation
from tardis.io.logger.logger import LOGGING_LEVELS
from tardis import run_tardis
import pytest
from tardis.simulation import Simulation

pytestmark = pytest.mark.skip(
reason="logging testing slow and disabled for now"
Expand Down Expand Up @@ -67,7 +67,7 @@
specific_log_level=specific_log_level,
)
for record in caplog.records:
if specific_log_level == True:
if specific_log_level is True:

Check warning on line 70 in tardis/io/logger/tests/test_logging.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/logger/tests/test_logging.py#L70

Added line #L70 was not covered by tests
assert record.levelno == LOGGING_LEVELS[log_level.upper()]
else:
assert record.levelno >= LOGGING_LEVELS[log_level.upper()]
Expand All @@ -85,7 +85,7 @@
caplog.clear()
run_tardis(config=config)
for record in caplog.records:
if specific_log_level == True:
if specific_log_level is True:

Check warning on line 88 in tardis/io/logger/tests/test_logging.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/logger/tests/test_logging.py#L88

Added line #L88 was not covered by tests
assert record.levelno == LOGGING_LEVELS[log_level.upper()]
else:
assert record.levelno >= LOGGING_LEVELS[log_level.upper()]
Expand All @@ -107,7 +107,7 @@
specific_log_level=specific_log_level,
)
for record in caplog.records:
if specific_log_level == True:
if specific_log_level is True:

Check warning on line 110 in tardis/io/logger/tests/test_logging.py

View check run for this annotation

Codecov / codecov/patch

tardis/io/logger/tests/test_logging.py#L110

Added line #L110 was not covered by tests
assert record.levelno == LOGGING_LEVELS[log_level.upper()]
else:
assert record.levelno >= LOGGING_LEVELS[log_level.upper()]
3 changes: 1 addition & 2 deletions tardis/io/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from tardis.io.model.readers.stella import read_stella_model

# from tardis.io.model.stella import read_stella_model
from tardis.io.model.readers.cmfgen import read_cmfgen_model
from tardis.io.model.readers.stella import read_stella_model
Loading
Loading