Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ${{ matrix.platform }}
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
python-version: ["3.11", "3.12", "3.13"]
platform: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v6
Expand Down
9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ repos:
hooks:
- id: trailing-whitespace
- id: name-tests-test
args: [--pytest-test-first]
- id: end-of-file-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.0
rev: v0.15.4
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-check
args: [--fix]
- id: ruff-format
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.3.0
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/yieldplotlib_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"\n",
"def read_markdown_table(filepath):\n",
" \"\"\"Parses our markdown table file into a Pandas DataFrame.\"\"\"\n",
" with open(filepath, \"r\") as f:\n",
" with open(filepath) as f:\n",
" lines = f.readlines()\n",
" clean_lines = [line for line in lines if \"|\" in line and \"---\" not in line]\n",
" clean_data = \"\".join(clean_lines)\n",
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import nox


@nox.session(venv_backend="uv", python=["3.10", "3.11", "3.12", "3.13"])
@nox.session(venv_backend="uv", python=["3.11", "3.12", "3.13"])
def tests(session):
"""Run the test suite with pytest."""
# Install all test dependencies
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies = [
]
license = { file = "LICENSE" }
dynamic = ['readme', 'version']
requires-python = ">=3.10"
requires-python = ">=3.11"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down Expand Up @@ -69,7 +69,7 @@ test = ["nox", "pytest", "pytest-cov"]
exclude = ["src/yieldplotlib/key_map.py"]

[tool.ruff.lint]
select = ["D", "E", "F", "I"]
select = ["B", "D", "E", "F", "I", "UP", "RUF"]

[tool.ruff.lint.pydocstyle]
convention = "google"
2 changes: 1 addition & 1 deletion scripts/loader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
titles = ["EXOSIMS", "AYO"]
fig, axs = plt.subplots(1, len(runs), figsize=(15, 5))
y_range = (0.001, 200)
for i, (run, title) in enumerate(zip(runs, titles)):
for i, (run, title) in enumerate(zip(runs, titles, strict=True)):
star_L = run.get("star_L")
star_dist = run.get("star_dist")
star_comp = run.get("star_comp")
Expand Down
12 changes: 6 additions & 6 deletions src/yieldplotlib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
"""yieldplotlib - A library for plotting yield data."""

__all__ = [
"KEY_MAP",
"__version__",
"calculate_axis_limits_and_ticks",
"compare",
"fetch_ayo_data",
"fetch_exosims_data",
"fetch_yip_data",
"KEY_MAP",
"logger",
"calculate_axis_limits_and_ticks",
"get_nice_number",
"subplots",
"compare",
"logger",
"multi",
"panel",
"subplots",
"xy_grid",
"ypl_cmap",
"ypl_colors",
"ypl_cycler",
"ypl_rainbow",
"xy_grid",
]

from importlib.resources import as_file, files
Expand Down
4 changes: 2 additions & 2 deletions src/yieldplotlib/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Core module of yieldplotlib."""

__all__ = [
"DirectoryNode",
"CSVFile",
"DirectoryNode",
"FileNode",
"JSONFile",
"PickleFile",
"Node",
"PickleFile",
]

from .directory_node import DirectoryNode
Expand Down
4 changes: 2 additions & 2 deletions src/yieldplotlib/core/file_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(self, file_path: Path):

def load(self):
"""Load the JSON file into memory."""
with open(self.file_path, "r") as f:
with open(self.file_path) as f:
self.data = json.load(f)

def _get(self, key: str, **kwargs):
Expand All @@ -133,7 +133,7 @@ def json_recur(data, target_key):
values[data["name"]] = data.get(key, None)
except KeyError:
values[data["instName"]] = data.get(key, None)
elif isinstance(v, (dict, list)):
elif isinstance(v, dict | list):
json_recur(v, target_key)
elif isinstance(data, list):
for item in data:
Expand Down
20 changes: 9 additions & 11 deletions src/yieldplotlib/core/single_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class SingleInput(dict):

def __init__(self, *args, **kwargs):
"""Initialise the SingleInput class."""
super(SingleInput, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def apply(self, key, func):
"""Apply a function to all values of a given key."""
try:
self[key] = func(self.get(key))
except TypeError:
raise TypeError(f"Could not apply function to {key}")
except TypeError as err:
raise TypeError(f"Could not apply function to {key}") from err

def check_units(self, key, desired_unit):
"""Checks that all values of key have the appropriate desired unit."""
Expand All @@ -30,15 +30,13 @@ def check_units(self, key, desired_unit):
for value in iterator:
if value.unit != desired_unit:
raise AssertionError(
(
f"Value {value} for {key} does not have desired "
f"unit {desired_unit}"
)
f"Value {value} for {key} does not have desired "
f"unit {desired_unit}"
)
except AttributeError:
except AttributeError as err:
raise AttributeError(
f"{key} does not have a value of type astropy.units.Quantity"
)
) from err

except TypeError:
try:
Expand All @@ -47,10 +45,10 @@ def check_units(self, key, desired_unit):
f"Value {self.get(key)} for {key} does not have desired "
f"unit {desired_unit}"
)
except AttributeError:
except AttributeError as err:
raise AttributeError(
f"{key} does not have a value of type astropy.units.Quantity"
)
) from err

finally:
logger.info("All unit checks passed.")
5 changes: 2 additions & 3 deletions src/yieldplotlib/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io
import os
import sys
from typing import Optional

import pandas as pd
from google.oauth2 import service_account
Expand Down Expand Up @@ -53,7 +52,7 @@ def parse_args():


def download_from_google_sheets(
sheet_id: str, credentials_json_path: Optional[str] = None
sheet_id: str, credentials_json_path: str | None = None
) -> str:
"""Download a CSV file from Google Sheets.

Expand Down Expand Up @@ -128,7 +127,7 @@ def read_csv_file(file_path: str) -> str:
CSV content as a string.
"""
try:
with open(file_path, "r", encoding="utf-8") as f:
with open(file_path, encoding="utf-8") as f:
return f.read()
except Exception as e:
print(f"Error reading CSV file: {e}")
Expand Down
34 changes: 12 additions & 22 deletions src/yieldplotlib/generate_key_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ def download_from_google_sheets(sheet_id, output_path, credentials_json_path=Non
from googleapiclient.discovery import build
except ImportError:
print(
(
"Error: Google API libraries not installed. "
"Run: pip install google-auth google-auth-oauthlib"
" google-api-python-client"
)
"Error: Google API libraries not installed. "
"Run: pip install google-auth google-auth-oauthlib"
" google-api-python-client"
)
sys.exit(1)

Expand All @@ -91,7 +89,7 @@ def download_from_google_sheets(sheet_id, output_path, credentials_json_path=Non
# First check for credentials file path
if credentials_json_path:
try:
with open(credentials_json_path, "r") as f:
with open(credentials_json_path) as f:
credentials_info = json.load(f)
credentials = service_account.Credentials.from_service_account_info(
credentials_info,
Expand All @@ -106,10 +104,8 @@ def download_from_google_sheets(sheet_id, output_path, credentials_json_path=Non
credentials_b64 = os.environ.get("GOOGLE_CREDENTIALS_B64")
if not credentials_b64:
print(
(
"Error: No credentials provided. Either set GOOGLE_CREDENTIALS_B64"
" or provide --credentials"
)
"Error: No credentials provided. Either set GOOGLE_CREDENTIALS_B64"
" or provide --credentials"
)
sys.exit(1)

Expand Down Expand Up @@ -206,10 +202,8 @@ def parse_csv(input_csv):
key = exo_name
else:
print(
(
f"Warning: Row {row_num} has no 'yieldplotlib name'"
" and no clear library names. Skipping."
)
f"Warning: Row {row_num} has no 'yieldplotlib name'"
" and no clear library names. Skipping."
)
continue # Skip rows that don't meet criteria

Expand Down Expand Up @@ -255,10 +249,8 @@ def parse_csv(input_csv):
else:
# If neither library has complete info, skip the row
print(
(
f"Warning: Row {row_num} does not have complete "
"information for either library. Skipping."
)
f"Warning: Row {row_num} does not have complete "
"information for either library. Skipping."
)
continue

Expand Down Expand Up @@ -303,10 +295,8 @@ def add_to_key_map(entry, context):

if key in key_map:
print(
(
f"Warning: Duplicate key '{key}' found in {context}."
" Overwriting previous entry."
)
f"Warning: Duplicate key '{key}' found in {context}."
" Overwriting previous entry."
)

key_map[key] = map_entry
Expand Down
2 changes: 1 addition & 1 deletion src/yieldplotlib/load/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

__all__ = [
"AYODirectory",
"YIPDirectory",
"DRMDirectory",
"EXOSIMSCSVDirectory",
"EXOSIMSDirectory",
"SPCDirectory",
"YIPDirectory",
]

from .ayo_directory import AYODirectory
Expand Down
Loading