Skip to content

Code hygiene: logging instead of print, bare excepts, hardcoded paths, dead code #11

Description

@bernalde

Goal

Address pervasive code-hygiene issues that hurt debuggability and reliability. Part of #3. These are independent, low-risk cleanups suitable for several small PRs.

Findings

  1. print() used for diagnostics (~75 occurrences). e.g. SimExec.py:79-83, Phases.py:148-153, Commons.py:319-321. No way to control verbosity. → Replace with the logging module (module-level loggers, levels).
  2. Bare except: clauses that swallow all errors. e.g. ThermoModule.py:82, StatsModule.py:413, Crystallizers.py:124. → Catch specific exceptions; re-raise or log.
  3. Hardcoded relative data paths that break once installed/moved. e.g. Streams.py:292 ('../../data/evaporator/compounds_evap.json'), ParamEstim.py:1339 ('../data/englezos_example.csv'), SolidLiquidSep.py:1346 ('../../../publications/...'). → Resolve via importlib.resources / package data, or require explicit paths.
  4. Commented-out / dead code (e.g. stale JAX/autograd blocks Crystallizers.py:37-46, 120-125) and unnecessary # -*- coding: utf-8 -*- headers. → Remove.

Tasks

  • Introduce a package logger and convert diagnostic prints (keep genuine user-facing output deliberate).
  • Replace bare excepts with specific exception handling.
  • Fix hardcoded data paths to be installation-safe.
  • Remove dead/commented code blocks.

Acceptance criteria

  • No bare except: remain (enforced by a lint rule, e.g. flake8 E722).
  • Library emits via logging, silent by default for importers.
  • Data files resolve correctly when PharmaPy is pip-installed outside the source tree.

Suggested split

Do these as 3-4 separate PRs (logging, excepts, paths, dead code) to keep diffs reviewable.


Upstream PR

Wave 2 — split into separate small upstream PRs (logging / bare excepts / paths / dead code). Never bundle with a formatting pass — that mixing is what triggered the #107 revert. See #3.

Metadata

Metadata

Assignees

Labels

area:architectureShared abstractions, base classes, constants, or project structurerefactor:mpvOverlaps the MultiPhaseVessel refactor; revalidate after mergestatus:plannedPlanned roadmap or maintenance work, not a verified bug reporttech-debtCode health and refactoring

Type

No type

Projects

Status
No status

Relationships

None yet

Development

No branches or pull requests

Issue actions