resolve static analysis warnings#12
Conversation
…quantification_accuracy(B101)
… for safe URL scheme validation(B310)
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can customize the tone of the review comments and chat replies.Configure the |
There was a problem hiding this comment.
Pull request overview
This PR addresses static-analysis findings across the codebase (tests, library modules, and benchmark scripts) to satisfy tools like flake8, pylint, bandit, and opengrep, with a focus on removing unused code, tightening security around downloads/SQL, and silencing flagged patterns.
Changes:
- Removed unused imports/variables and adjusted function signatures/defaults to satisfy static analyzers.
- Replaced flagged patterns (e.g.,
urlretrievedownloads, string-built SQL) with safer alternatives (scheme validation, parameterized DuckDBread_parquet(?)). - Updated benchmark/test scripts to avoid linter/security flags (including switching a benchmark runner from
subprocesstorunpy).
Reviewed changes
Copilot reviewed 53 out of 53 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_tmm_normalization.py | Avoid unused variable by discarding fit_transform result. |
| tests/test_quantification_accuracy.py | Replace urlretrieve with opener-based download + scheme validation; replace some f-strings/asserts. |
| tests/test_peptide_normalize.py | Avoid unused variable by discarding return value. |
| tests/test_hierarchical_normalization.py | Avoid unused variable by discarding fit_transform result. |
| tests/test_file_utils.py | Replace assert with explicit AssertionError raising (Bandit B101). |
| tests/test_batch_correction_integration.py | Remove unused imports. |
| mokume/reports/workflow_comparison.py | Remove unused imports. |
| mokume/reports/interactive.py | Remove unused plotly Python import (HTML uses Plotly CDN). |
| mokume/reports/init.py | Use importlib.util.find_spec for optional dependency detection. |
| mokume/quantification/ratio.py | Replace string-interpolated parquet scan with parameterized read_parquet(?) approach. |
| mokume/quantification/maxlfq.py | Replace optional dependency import check with find_spec. |
| mokume/quantification/ibaq.py | Remove unused import. |
| mokume/quantification/directlfq.py | Replace optional dependency import check with find_spec. |
| mokume/preprocessing/filters/run_qc.py | Remove unused imports / typing cleanup. |
| mokume/preprocessing/filters/protein.py | Remove unused typing imports. |
| mokume/preprocessing/filters/pipeline.py | Remove unused typing imports. |
| mokume/preprocessing/filters/peptide.py | Remove unused typing imports. |
| mokume/preprocessing/filters/base.py | Remove unused typing imports. |
| mokume/postprocessing/batch_correction.py | Replace optional dependency import check with find_spec; remove unused imports. |
| mokume/plotting/init.py | Use find_spec to detect optional plotting dependencies. |
| mokume/pipeline/stages.py | Remove unused import. |
| mokume/pipeline/features_to_proteins.py | Remove unused import. |
| mokume/normalization/tmm.py | Remove unused typing import. |
| mokume/normalization/peptide.py | Remove unused imports/constants; add explicit __all__ re-exports. |
| mokume/mokume_cli.py | Add defaults to Click-invoked command function parameters. |
| mokume/commands/visualize.py | Add defaults to Click-invoked command function parameters. |
| mokume/analysis/differential_expression.py | Remove unused imports. |
| environment.yaml | Adjust NumPy pin; add plotly/statsmodels to conda env. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/run_benchmark.py | Replace subprocess.run with runpy.run_path; index-based step execution. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/12_optimal_pipeline.py | Remove unused import. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/11_preprocessing_filters.py | Remove unused vars/clean up prints. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/10_imputation_benchmark.py | Remove unused imports/vars; small cleanup. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/09_quant_norm_interaction.py | Remove unused imports/vars; small cleanup. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/08_normalization_grid.py | Remove unused vars; small cleanup. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/07_tmm_normalization_benchmark.py | Remove unused import. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/05_cross_technology_correlation.py | Remove unused imports. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/04_stability_metrics.py | Remove unused imports. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/03_fold_change_accuracy.py | Remove unused imports/vars; small cleanup. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/02_variance_decomposition.py | Replace bare except with logged warning; import logging. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/01_grid_search_methods.py | Replace f-string without placeholders. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/00_generate_ibaq.py | Replace urlretrieve with opener-based download + scheme validation. |
| benchmarks/quant-pxd007683-tmt-vs-lfq/scripts/00_download_data.py | Replace urlretrieve/urlopen with opener-based download + scheme validation + progress loop. |
| benchmarks/quant-hela-method-comparison/scripts/run_benchmark.py | Remove unused import. |
| benchmarks/quant-hela-method-comparison/scripts/config.py | Remove unused imports/typing. |
| benchmarks/quant-hela-method-comparison/scripts/06_method_correlation_plots.py | Remove unused imports/vars; minor cleanup. |
| benchmarks/quant-hela-method-comparison/scripts/05_generate_plots.py | Remove unused imports/constants. |
| benchmarks/quant-hela-method-comparison/scripts/04_compute_metrics.py | Minor print cleanup / typing cleanup. |
| benchmarks/quant-hela-method-comparison/scripts/03_run_quantification.py | Remove unused imports/constants; minor print cleanup. |
| benchmarks/quant-hela-method-comparison/scripts/02_prepare_peptides.py | Remove unused imports/vars. |
| benchmarks/quant-hela-method-comparison/scripts/01_download_data.py | Replace urlretrieve/urlopen with opener-based download + scheme validation; tighten exception handling. |
| benchmarks/batch-quartet-multilab/scripts/run_benchmark.py | Replace bare except with logged warning; remove unused imports/vars. |
| benchmarks/batch-quartet-multilab/scripts/plot_results.py | Remove unused import. |
| benchmarks/batch-quartet-multilab/scripts/comprehensive_analysis.py | Remove unused imports/vars; minor cleanup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| if urllib.parse.urlparse(PRIDE_DATASET_URL).scheme not in ("http", "https"): | ||
| raise ValueError(f"URL scheme not allowed: {PRIDE_DATASET_URL}") | ||
| _opener = urllib.request.build_opener() | ||
| with _opener.open(PRIDE_DATASET_URL) as response, open(zip_path, "wb") as out_file: | ||
| shutil.copyfileobj(response, out_file) |
| validated = _validate_step(step_index) | ||
| if validated is None: | ||
| return False |
| def _is_directlfq_available() -> bool: | ||
| """Check if DirectLFQ package is installed.""" | ||
| try: | ||
| import directlfq | ||
| return True | ||
| except ImportError: | ||
| return False | ||
| import importlib.util | ||
| return importlib.util.find_spec("directlfq") is not None | ||
|
|
mokume/mokume_cli.py
Outdated
| help="Write log to this file.", | ||
| ) | ||
| def cli(log_level: str, log_file: Path): | ||
| def cli(log_level: str = "debug", log_file: Path = None): |
| dependencies: | ||
| - python>=3.9 | ||
| - scikit-learn | ||
| - pyopenms |
| if urllib.parse.urlparse(base_url).scheme not in ("http", "https"): | ||
| raise ValueError(f"URL scheme not allowed: {base_url}") | ||
| response = _opener.open(base_url, timeout=30) | ||
| content = response.read().decode('utf-8') |
… without command injection
Fix all static analysis warnings detected by flake8, bandit, pylint, and opengrep:
Listimportassertwithif not: raise AssertionErrorurlretrieve/urlopenwithbuild_opener().open()+ URL scheme validationsubprocess.runwithrunpy.run_path()read_parquet(?); replace+concatenation withstr.joinlogging.warning()