Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure logger.getLogger() is used instead of logging directly via logging.debug() #91

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

tfenne
Copy link
Member

@tfenne tfenne commented Nov 15, 2024

This small PR ensures that anywhere that prymer logs it first gets a logger via logging.getLogger(__name__), rather than just doing logging.debug(....).

The problem with logging.debug() (and similar methods directly on the logging module) is that they are side-effecting on the logging configuration. E.g. here's the debug() function in logging:

def debug(msg, *args, **kwargs):
    """
    Log a message with severity 'DEBUG' on the root logger. If the logger has
    no handlers, call basicConfig() to add a console handler with a pre-defined
    format.
    """
    if len(root.handlers) == 0:
        basicConfig()
    root.debug(msg, *args, **kwargs)

This was causing me issues in a repo that uses prymer, where after the first one of these calls, I then received duplicate log messages for every subsequent log in my code.

@tfenne tfenne requested review from msto and emmcauley November 15, 2024 12:37
@tfenne tfenne requested a review from nh13 as a code owner November 15, 2024 12:37
Copy link

coderabbitai bot commented Nov 15, 2024

Walkthrough

The pull request introduces several changes across multiple files in the prymer module. In prymer/api/picking.py, the score() and build_primer_pairs() methods are updated for improved clarity and error handling. The score() method's documentation is enhanced, detailing scoring criteria, while build_primer_pairs() now includes checks for the presence of primers and raises ValueError exceptions for mismatched reference names. In prymer/api/variant_lookup.py, logging enhancements are made to the VariantLookup class, utilizing logging.getLogger(__name__) for better log context. Similar logging updates occur in the Primer3 class within prymer/primer3/primer3.py, alongside improvements in error handling and method restructuring. The Primer3FailureReason class also sees a logging update in the parse_failures method. Lastly, the ExecutableRunner class in prymer/util/executable_runner.py receives logging enhancements without altering its core functionality.

Possibly related PRs

Suggested reviewers

  • nh13
  • msto

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 98dda5d and b1212cc.

📒 Files selected for processing (1)
  • prymer/api/variant_lookup.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • prymer/api/variant_lookup.py

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
prymer/util/executable_runner.py (1)

147-159: Add subprocess details to debug messages.

Add process ID and command name to messages for better traceability.

-                log.debug("Subprocess terminated successfully.")
+                log.debug(f"Subprocess {self._name} (pid={self._subprocess.pid}) terminated successfully.")
-                log.debug("Subprocess failed to terminate.")
+                log.debug(f"Subprocess {self._name} (pid={self._subprocess.pid}) failed to terminate.")
-            log.debug("Subprocess is not running.")
+            log.debug(f"Subprocess {self._name} is not running.")
prymer/api/picking.py (1)

Line range hint 151-154: Use Path object directly instead of f-string.

Replace f"{fasta_path}" with str(fasta_path) for proper path handling.

-    with FastaFile(f"{fasta_path}") as fasta:
+    with FastaFile(str(fasta_path)) as fasta:
prymer/primer3/primer3.py (1)

Line range hint 317-318: Address the 'FIXME' comment

The # FIXME comment indicates that this code requires attention. Please resolve it before merging.

Do you need assistance in addressing this issue or would you like me to open a GitHub issue to track it?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8c39970 and 98dda5d.

📒 Files selected for processing (5)
  • prymer/api/picking.py (1 hunks)
  • prymer/api/variant_lookup.py (3 hunks)
  • prymer/primer3/primer3.py (1 hunks)
  • prymer/primer3/primer3_failure_reason.py (1 hunks)
  • prymer/util/executable_runner.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • prymer/primer3/primer3_failure_reason.py
🔇 Additional comments (7)
prymer/util/executable_runner.py (1)

73-75: LGTM. Logging change matches PR objectives.

prymer/api/picking.py (1)

Line range hint 144-148: LGTM: Improved input validation.

Early return and reference validation prevent invalid primer combinations.

prymer/api/variant_lookup.py (3)

285-287: LGTM: Logging change aligns with PR objectives.

Changed from direct logging to getLogger(__name__).


316-316: LGTM: Logging change aligns with PR objectives.

Changed from direct logging to getLogger(__name__).


377-379: LGTM: Logging change aligns with PR objectives.

Changed from direct logging to getLogger(__name__).

prymer/primer3/primer3.py (2)

271-271: Good use of logger instances for logging

Updating the logging to use logging.getLogger(__name__) is a good practice.


Line range hint 366-383: Ensure compatibility with Python 3.10+

The use of match statements requires Python 3.10 or higher. Confirm that the project supports Python 3.10+.

Run the following script to check the Python version specified in the project's configuration:

✅ Verification successful

Python version requirement is met

Project requires Python 3.11+, which fully supports match statements. No compatibility issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the Python version requirements in setup.py and pyproject.toml.

# Search for 'python_requires' in setup.py
if [ -f setup.py ]; then
  grep 'python_requires' setup.py
fi

# Search for 'requires-python' in pyproject.toml
if [ -f pyproject.toml ]; then
  grep 'requires-python' pyproject.toml
fi

# Search for Python classifiers in setup.py
if [ -f setup.py ]; then
  grep 'Programming Language :: Python ::' setup.py
fi

Length of output: 109


Script:

#!/bin/bash
# Check for Python version requirements in any configuration files
fd -e toml -e cfg -e ini -x cat {} \; | grep -i "python"

# Check for imports of Python 3.10+ features
rg "from \| import.*match" -A 2

# Look for CI configuration files that might specify Python versions
fd "\.github|tox.ini|\.travis" --type f -x cat {}

Length of output: 484

Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.

Project coverage is 96.66%. Comparing base (8c39970) to head (b1212cc).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
prymer/primer3/primer3.py 0.00% 1 Missing ⚠️
prymer/util/executable_runner.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #91   +/-   ##
=======================================
  Coverage   96.66%   96.66%           
=======================================
  Files          26       26           
  Lines        1707     1709    +2     
  Branches      331      331           
=======================================
+ Hits         1650     1652    +2     
  Misses         31       31           
  Partials       26       26           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

prymer/api/variant_lookup.py Outdated Show resolved Hide resolved
@tfenne tfenne merged commit 1011c7d into main Nov 15, 2024
6 of 7 checks passed
@tfenne tfenne deleted the tf_use_get_logger branch November 15, 2024 21:36
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.

2 participants