Skip to content
Draft
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
18 changes: 3 additions & 15 deletions cli_core_yo/certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ def resolve_https_certs(
cert_path: str | Path | None = None,
key_path: str | Path | None = None,
env: dict[str, str] | None = None,
legacy_cert_env_vars: tuple[str, ...] = (),
legacy_key_env_vars: tuple[str, ...] = (),
shared_certs_dir: str | Path | None = None,
fallback_certs_dir: str | Path | None = None,
hosts: tuple[str, ...] = ("localhost", "127.0.0.1", "::1"),
Expand All @@ -171,10 +169,9 @@ def resolve_https_certs(
Resolution order:
1. Explicit ``cert_path`` / ``key_path``
2. Generic env ``SSL_CERT_FILE`` / ``SSL_KEY_FILE``
3. Service-specific legacy env vars
4. Existing files in ``shared_certs_dir``
5. Existing files in ``fallback_certs_dir``
6. Optional mkcert generation, preferring ``shared_certs_dir``
3. Existing files in ``shared_certs_dir``
4. Existing files in ``fallback_certs_dir``
5. Optional mkcert generation, preferring ``shared_certs_dir``
"""
env_map = os.environ if env is None else env
resolved = _resolve_explicit_pair(cert_path, key_path, source="CLI flags")
Expand All @@ -190,15 +187,6 @@ def resolve_https_certs(
if resolved is not None:
return _validated_paths(*resolved, source="env")

resolved = _resolve_env_pair(
env_map,
cert_env_vars=legacy_cert_env_vars,
key_env_vars=legacy_key_env_vars,
source="legacy SSL env",
)
if resolved is not None:
return _validated_paths(*resolved, source="legacy-env")

shared_dir = Path(shared_certs_dir).expanduser() if shared_certs_dir else None
if shared_dir is not None:
existing = _existing_cert_pair(shared_dir)
Expand Down
2 changes: 0 additions & 2 deletions cli_core_yo/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class XdgSpec:
"""XDG Base Directory configuration."""

app_dir_name: str
legacy_macos_config_dir: str | None = None
legacy_copy_files: list[str] = field(default_factory=list)


@dataclass(frozen=True)
Expand Down
16 changes: 4 additions & 12 deletions cli_core_yo/xdg.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""XDG Base Directory path resolution (§6.4).
"""XDG Base Directory path resolution.

Supports optional legacy macOS config migration.
Resolves config, data, state, and cache directories per the XDG spec,
with macOS-specific paths for Library/Application Support.
"""

from __future__ import annotations

import os
import platform
import shutil

from dataclasses import dataclass
from pathlib import Path

Expand Down Expand Up @@ -75,13 +76,4 @@ def resolve_paths(xdg_spec: XdgSpec) -> XdgPaths:
for d in (config_dir, data_dir, state_dir, cache_dir):
d.mkdir(parents=True, exist_ok=True)

# Legacy macOS migration (§6.4)
if xdg_spec.legacy_macos_config_dir and macos:
legacy_dir = Path(xdg_spec.legacy_macos_config_dir).expanduser()
for filename in xdg_spec.legacy_copy_files:
legacy_file = legacy_dir / filename
target_file = config_dir / filename
if legacy_file.exists() and not target_file.exists():
shutil.copy2(str(legacy_file), str(target_file))

return XdgPaths(config=config_dir, data=data_dir, state=state_dir, cache=cache_dir)
1 change: 0 additions & 1 deletion environment.yml

This file was deleted.

10 changes: 10 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: CLI_CORE_YO-local
channels:
- conda-forge
- defaults
dependencies:
- python=3.12
- pip
- setuptools<81
- pip:
- -e .[dev]
2 changes: 0 additions & 2 deletions tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class TestXdgSpec:
def test_minimal(self):
spec = XdgSpec(app_dir_name="myapp")
assert spec.app_dir_name == "myapp"
assert spec.legacy_macos_config_dir is None
assert spec.legacy_copy_files == []

def test_frozen(self):
spec = XdgSpec(app_dir_name="myapp")
Expand Down
61 changes: 0 additions & 61 deletions tests/test_xdg.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,64 +63,3 @@ def test_macos_defaults(self, tmp_path: Path, xdg_spec: XdgSpec):
assert paths.state == tmp_path / "Library" / "Logs" / "testapp"
assert paths.cache == tmp_path / "Library" / "Caches" / "testapp"


class TestLegacyMigration:
def test_copies_legacy_file(self, tmp_path: Path):
legacy_dir = tmp_path / "legacy"
legacy_dir.mkdir()
(legacy_dir / "old.json").write_text('{"key": "val"}')

spec = XdgSpec(
app_dir_name="testapp",
legacy_macos_config_dir=str(legacy_dir),
legacy_copy_files=["old.json"],
)
env = {"XDG_CONFIG_HOME": str(tmp_path / "cfg")}
with (
patch.dict(os.environ, env, clear=False),
patch("cli_core_yo.xdg._is_macos", return_value=True),
):
paths = resolve_paths(spec)
target = paths.config / "old.json"
assert target.exists()
assert target.read_text() == '{"key": "val"}'

def test_does_not_overwrite_existing(self, tmp_path: Path):
legacy_dir = tmp_path / "legacy"
legacy_dir.mkdir()
(legacy_dir / "old.json").write_text("legacy")

cfg_dir = tmp_path / "cfg" / "testapp"
cfg_dir.mkdir(parents=True)
(cfg_dir / "old.json").write_text("existing")

spec = XdgSpec(
app_dir_name="testapp",
legacy_macos_config_dir=str(legacy_dir),
legacy_copy_files=["old.json"],
)
env = {"XDG_CONFIG_HOME": str(tmp_path / "cfg")}
with (
patch.dict(os.environ, env, clear=False),
patch("cli_core_yo.xdg._is_macos", return_value=True),
):
paths = resolve_paths(spec)
assert (paths.config / "old.json").read_text() == "existing"

def test_skips_on_linux(self, tmp_path: Path):
legacy_dir = tmp_path / "legacy"
legacy_dir.mkdir()
(legacy_dir / "old.json").write_text("legacy")

spec = XdgSpec(
app_dir_name="testapp",
legacy_macos_config_dir=str(legacy_dir),
legacy_copy_files=["old.json"],
)
env = {"XDG_CONFIG_HOME": str(tmp_path / "cfg")}
with (
patch.dict(os.environ, env, clear=False),
patch("cli_core_yo.xdg._is_macos", return_value=False),
):
paths = resolve_paths(spec)
assert not (paths.config / "old.json").exists()
Loading