Commit 6cb2046
authored
[ENH] feat :replacing
#### Reference Issues/PRs
Fixes #416.
#### What does this implement/fix? Explain your changes.
This PR migrates the codebase from using `print()` statements for
progress and debug reporting to the standard Python `logging` module.
This allows library consumers to control log verbosity programmatically
and prevents cluttering `stdout` in production environments.
**Key Changes:**
* **Module-level Loggers:** Added `logger = logging.getLogger(__name__)`
to `mcts/_algorithm.py`, `aptatrans/_pipeline.py`, and
`aptatrans/_model.py`.
* **Logging levels:**
* Used `logger.debug()` for high-frequency MCTS round updates and
internal search progress.
* Used `logger.info()` for lifecycle events like model weight loading,
downloads, and final candidate recommendations.
* **Performance Optimization:** Implemented
`logger.isEnabledFor(logging.DEBUG)` guards in the MCTS hot loop (`run`
method) to avoid unnecessary string formatting overhead when debug
logging is disabled.
* **Ruff Enforcement:** Updated `pyproject.toml` to include the `T20`
(flake8-print) rule set in the Ruff configuration. This will cause
linting to fail if `print()` or `pprint()` statements are accidentally
reintroduced in the future.
#### What should a reviewer concentrate their feedback on?
* Verify that the chosen log levels (`DEBUG` vs `INFO`) are appropriate
for the respective output.
* Check the implementation of the performance guards in
`pyaptamer/mcts/_algorithm.py`.
#### Did you add any tests for the change?
The changes were verified by running `ruff check pyaptamer/ --select
T20` to ensure that no `print()` statements remain in the library code
and that the new linting rule is active. Syntax correctness was verified
with a full AST parse check of the modified files.
#### PR checklist
- [x] The PR title starts with either [ENH], [MNT], [DOC], or [BUG].
- [ ] Added/modified tests
- [x] Used pre-commit hooks when committing to ensure that code is
compliant with hooks.print() statements with Python logging module. (#477)1 parent e975325 commit 6cb2046
6 files changed
Lines changed: 48 additions & 12 deletions
File tree
- pyaptamer
- aptatrans
- mcts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
273 | | - | |
| 274 | + | |
274 | 275 | | |
275 | 276 | | |
276 | | - | |
| 277 | + | |
277 | 278 | | |
278 | 279 | | |
279 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
246 | 248 | | |
247 | 249 | | |
248 | 250 | | |
249 | | - | |
250 | | - | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
251 | 256 | | |
252 | 257 | | |
253 | 258 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| |||
296 | 299 | | |
297 | 300 | | |
298 | 301 | | |
299 | | - | |
300 | | - | |
| 302 | + | |
| 303 | + | |
301 | 304 | | |
302 | 305 | | |
303 | 306 | | |
| |||
315 | 318 | | |
316 | 319 | | |
317 | 320 | | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
323 | 327 | | |
324 | 328 | | |
325 | 329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
0 commit comments