Skip to content

Commit 589fa0d

Browse files
committed
Refactor: centralize matplotlib setup and split job/core.py
1 parent 5b5a77a commit 589fa0d

9 files changed

Lines changed: 565 additions & 598 deletions

File tree

.github/copilot-instructions.md

Lines changed: 0 additions & 168 deletions
This file was deleted.

src/jsrc/core.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ def parse_gff_attributes(attr_string: str) -> dict[str, str]:
4646
return attrs
4747

4848

49+
def setup_matplotlib():
50+
"""Configure matplotlib to use Agg backend for headless operation."""
51+
import matplotlib
52+
53+
matplotlib.use("Agg")
54+
import matplotlib.pyplot as plt
55+
56+
return plt
57+
58+
4959
def open_text(path: str | Path) -> IO[str]:
5060
path_str = str(path)
5161
if path_str.endswith(".gz"):

src/jsrc/job/config.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Job module configuration and path management."""
2+
3+
import os
4+
from pathlib import Path
5+
6+
7+
def config_home() -> Path:
8+
"""Get XDG config home directory."""
9+
xdg = os.getenv("XDG_CONFIG_HOME")
10+
if xdg:
11+
return Path(xdg).expanduser() / "jsrc"
12+
return Path.home() / ".config" / "jsrc"
13+
14+
15+
def data_home() -> Path:
16+
"""Get XDG data home directory."""
17+
xdg = os.getenv("XDG_DATA_HOME")
18+
if xdg:
19+
return Path(xdg).expanduser() / "jsrc"
20+
return Path.home() / ".local" / "share" / "jsrc"
21+
22+
23+
def history_path() -> Path:
24+
"""Get job history file path."""
25+
override = os.getenv("JSRC_JOBS_FILE", "")
26+
if override:
27+
return Path(override).expanduser()
28+
return config_home() / "job" / "history"
29+
30+
31+
def default_log_dir() -> Path:
32+
"""Get default directory for job log files."""
33+
return data_home() / "job-logs"
34+
35+
36+
def state_dir() -> Path:
37+
"""Get directory for job state files."""
38+
return data_home() / "job-state"
39+
40+
41+
def ensure_dirs() -> None:
42+
"""Create all required directories if they don't exist."""
43+
history_path().parent.mkdir(parents=True, exist_ok=True)
44+
default_log_dir().mkdir(parents=True, exist_ok=True)
45+
state_dir().mkdir(parents=True, exist_ok=True)
46+
47+
48+
def _migrate_old_history() -> None:
49+
"""Migrate old history file to new location."""
50+
old = data_home() / "jobs"
51+
new = history_path()
52+
if old.exists() and not new.exists():
53+
new.parent.mkdir(parents=True, exist_ok=True)
54+
old.rename(new)

0 commit comments

Comments
 (0)