Skip to content

Modernize packaging, add test suite, remove shell-string system calls#42

Merged
caleblareau merged 1 commit into
masterfrom
modernize-refactor
Jul 6, 2026
Merged

Modernize packaging, add test suite, remove shell-string system calls#42
caleblareau merged 1 commit into
masterfrom
modernize-refactor

Conversation

@caleblareau

Copy link
Copy Markdown
Owner

Refactors the codebase in three steps, as requested.

Step 1 — Dependencies & packaging

  • Replace setup.py/setup.cfg with a PEP 621 pyproject.toml. Fixes the distutils import (removed in Python 3.12+), de-duplicates biopython, drops the obsolete py2 universal wheel, sets requires-python >= 3.9, and moves pytest to a [test] extra.
  • Replace deprecated pkg_resources.get_distribution with importlib.metadata via a new bap_version() helper; make @click.version_option() explicit.

Step 2 — Testing + documentation

  • New pytest suite: test_helpers.py (pure functions + run_cmd), test_cli_smoke.py (hermetic CliRunner checks), and test_integration.py (end-to-end bap2 bam, auto-skips when samtools/bedtools/R/snakemake are absent).
  • GitHub Actions CI across Python 3.9–3.12 (.github/workflows/ci.yml).
  • Rewrote tests/README.md into a real testing guide; added a Testing section to the main README.

Step 3 — Refactor (no shell-string system calls)

  • Added a run_cmd() subprocess wrapper (no shell). Replaced every os.system("..."), os.popen('ls ...'), and os.system("cp ...") in the active CLIs with run_cmd([...]), glob.glob, and shutil.copyfile; child scripts launch via sys.executable.
  • Migrated YAML writing from the removed ruamel.yaml RoundTripDumper API to the modern YAML() API.
  • Fixed latent bugs: Python-2 itertools.imap in string_hamming_distance, abs_fileabs_path, missing import subprocess, undefined macs2_genome_size/bs_genome, and import-time PyYAML dependency.

Out of scope (intentionally unchanged): the deprecated v1 bap command (cli_old_dontEdit.py) and the genuine shell pipelines inside the Snakemake run: blocks.

Verification

  • pip install -e .[test] succeeds on modern Python; all console scripts report their version.
  • pytest → 41 passed, 1 skipped (integration auto-skip). os.system/os.popen remain only in the legacy v1 CLI.

🤖 Generated with Claude Code

Step 1 - Dependencies & packaging:
- Replace setup.py/setup.cfg with PEP 621 pyproject.toml (fixes distutils
  import removed in Python 3.12+, dedupes biopython, drops py2 universal wheel,
  requires-python >=3.9, pytest moved to a [test] extra)
- Replace deprecated pkg_resources with importlib.metadata (bap_version helper)

Step 2 - Testing:
- Add pytest suite: unit tests (test_helpers.py), hermetic CLI smoke tests
  (test_cli_smoke.py), and auto-skipping end-to-end tests (test_integration.py)
- Add GitHub Actions CI across Python 3.9-3.12
- Rewrite tests/README.md into a real testing guide

Step 3 - Refactor (no shell-string system calls) in active CLIs:
- Add run_cmd() subprocess wrapper; replace os.system()/os.popen()/cp with
  subprocess arg-lists, glob, and shutil; launch child scripts via sys.executable
- Migrate ruamel.yaml dumping to the modern YAML() API
- Fix latent bugs: Python-2 itertools.imap in string_hamming_distance,
  abs_file->abs_path, missing import subprocess, undefined macs2_genome_size/
  bs_genome, and import-time PyYAML dependency

Legacy v1 CLI (cli_old_dontEdit.py) and Snakefile shell pipelines are
intentionally left unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@caleblareau caleblareau merged commit 56db0d8 into master Jul 6, 2026
4 checks passed
@caleblareau caleblareau deleted the modernize-refactor branch July 6, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant