Skip to content

Commit

Permalink
Use new ruff config syntax and fix the errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tbhaxor committed May 9, 2024
1 parent 8e217b0 commit 2dac20d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
13 changes: 5 additions & 8 deletions astro_plasma/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import logging
import os

if not os.getenv("PY_ENV", "").startswith("test"):
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.DEBUG if os.getenv("ASTRO_PLASMA_DEBUG", "false") == "true" else logging.INFO,
)
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.DEBUG if os.getenv("ASTRO_PLASMA_DEBUG", "false") == "true" else logging.INFO,
)

from .core import ionization, spectrum # noqa
from .core.download_database import initialize_data # noqa
from .core import ionization, spectrum # noqa: E721,E402


log = logging.getLogger(__name__)

__all__ = ["Ionization", "EmissionSpectrum"]


Ionization = ionization.Ionization()
EmissionSpectrum = spectrum.EmissionSpectrum()
4 changes: 2 additions & 2 deletions astro_plasma/core/download_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"""
from __future__ import annotations

import logging

# Built-in imports
import re
import logging
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path

Expand Down Expand Up @@ -48,7 +48,7 @@ def download_datafiles(filename_format: str, download_links_url: str, download_d
generate_hashes = kwargs.get("generate_hashes", False)
hash_list_url = kwargs.get("hash_list_file_url")
file_ids = [0] if initialize else kwargs.get("file_ids", [])
if file_ids and type(file_ids) is not list:
if file_ids and type(file_ids) is not list: # noqa: E721
file_ids = list(file_ids)
links_response = requests.get(download_links_url)
download_links = np.array(re.split(r"\r?\n", links_response.text.strip()))
Expand Down
12 changes: 5 additions & 7 deletions astro_plasma/core/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
NumericOrArrayType = Type[float | int | list[int | float] | np.ndarray]


def cooling_approx(temperature: NumericOrArrayType, metallicity: NumericOrArrayType) -> NumericOrArrayType:
def cooling_approx(_temperature: NumericOrArrayType, _metallicity: NumericOrArrayType) -> NumericOrArrayType:
"""
Cooling function of an Astrophysical plasma.
Generated with a HM12 Xray-UV background.
Expand All @@ -25,9 +25,9 @@ def cooling_approx(temperature: NumericOrArrayType, metallicity: NumericOrArrayT
Parameters
----------
temperature : NumericOrArrayType
_temperature : NumericOrArrayType
Temperature of the plasma.
metallicity : NumericOrArrayType
_metallicity : NumericOrArrayType
Metallicity of the plasma with respect to Solar.
Returns
Expand All @@ -36,10 +36,8 @@ def cooling_approx(temperature: NumericOrArrayType, metallicity: NumericOrArrayT
Plasma cooling function normalized by nH^2.
"""
if type(temperature) is list:
temperature = np.array(temperature)
if type(metallicity) is list:
metallicity = np.array(metallicity)
temperature = np.array(_temperature) if type(_temperature) is list else _temperature # noqa: E721
metallicity = np.array(_metallicity) if type(_metallicity) is list else _metallicity # noqa: E721

if type(temperature) is np.ndarray and temperature.ndim > 1:
raise ValueError("Temperature ndarray dimension should be 1.")
Expand Down
6 changes: 3 additions & 3 deletions astro_plasma/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def parse(predicate: str | int | AtmElement) -> "AtmElement":

# TODO: Use function overloads in this case for better documentation
# When the type of the predicate is int, then it means user has passed the atomic number of the element
value_index = int(type(predicate) is int)
value_index = int(type(predicate) is int) # noqa: E721
error_label = "atomic number" if value_index == 1 else "symbol"

for element in AtmElement:
Expand Down Expand Up @@ -149,12 +149,12 @@ def parse_atomic_number_and_ion(element: int | AtmElement | str, ion=1) -> tuple
"""

# _element = 1: H, 2: He, 3: Li, ... 30: Zn
if type(element) is int and element not in range(1, AtmElement.Zinc.atomic_number + 1):
if type(element) is int and element not in range(1, AtmElement.Zinc.atomic_number + 1): # noqa: E721
raise ValueError(f"Invalid atomic number {element}.")

def validate_ion(_ion, _atm_no: int):
# _ion = 1 : neutral, 2: +, 3: ++ .... (element+1): (++++... _element times)
if type(_ion) is not int:
if type(_ion) is not int: # noqa: E721
return 1
elif _ion in range(1, _atm_no + 1):
return _ion
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ build-backend = "poetry.core.masonry.api"

# Ruff configurations
[tool.ruff]
select = ["E", "F", "Q"]
line-length = 160

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
[tool.ruff.lint]
select = ["E", "F", "Q"]

# Black formatter configuration
[tool.black]
Expand Down

0 comments on commit 2dac20d

Please sign in to comment.