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

feat: Enhance CI/CD Workflow with TestPyPI Publishing, Linting Improvements, and minor docs update #42

Merged
merged 13 commits into from
Oct 22, 2024

Conversation

jjjermiah
Copy link
Contributor

@jjjermiah jjjermiah commented Oct 22, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new linter job (Ruff) to enhance code quality.
    • Added conditional publishing to TestPyPI and installation testing jobs.
    • New tasks for linting and formatting using ruff in project configuration.
  • Bug Fixes

    • Improved error handling and type safety in DICOM loading functions.
  • Documentation

    • Added detailed docstrings for DICOM loading functions to clarify usage and file types.
  • Chores

    • Updated project version to 1.11.0 and improved configuration file organization.

…yle to numpy, and enhance loader type annotations
…ts and comment out previous push configuration
… and improving module documentation for DICOM and RTSTRUCT functions
…o test PyPI and add description for build task
…lation steps for verifying package deployment
Copy link

codecov bot commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.96%. Comparing base (7bdf5d3) to head (bdb49ea).
Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #42      +/-   ##
==========================================
+ Coverage   63.54%   63.96%   +0.41%     
==========================================
  Files           9        9              
  Lines         524      530       +6     
==========================================
+ Hits          333      339       +6     
  Misses        191      191              

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

@jjjermiah jjjermiah marked this pull request as ready for review October 22, 2024 17:02
Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The pull request introduces significant updates to the CI-CD workflow, including new jobs for linting, publishing, and testing installations. The push event trigger has been commented out, and the pull_request trigger now accepts any branch. The ruff linter is integrated, and several jobs are added or modified to enhance the pipeline's structure. Additionally, the ruff.toml configuration is updated for linting rules and formatting preferences, while the pyproject.toml file sees improvements in task management. The src/readii/loaders.py file is modified for better type handling and documentation in DICOM loading functions.

Changes

File Change Summary
.github/workflows/ci-cd.yml - Added Ruff job for linting.
- Updated Semantic-Release to depend on Ruff.
- Added Publish-To-Test-PyPi job.
- Added Test-TestPypi-Installation job.
config/ruff.toml - Added include for src/readii/loaders.py.
- Updated pydocstyle convention from google to numpy.
- Changed quote-style from single to double.
pyproject.toml - Updated project version to 1.11.0.
- Added lint and format tasks for ruff.
- Added publish-test task for publishing to TestPyPI.
src/readii/loaders.py - Updated function signatures to accept str or Path.
- Improved type safety and error handling in DICOM loading functions.

Possibly related PRs

  • feat: Use Pixi, pyradiomics fork #40: The changes in the CI-CD workflow configuration in both the main PR and this retrieved PR involve modifications to the .github/workflows/ci-cd.yml file, including job definitions and triggers, indicating a direct relationship in the context of CI/CD enhancements.

🐇 In the garden where bunnies play,
New jobs and tasks come out to stay.
Linting and publishing, oh what a sight,
With paths and formats all done just right.
Hopping along, we cheer and rejoice,
For our code now sings with a clearer voice! 🌼✨


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
Contributor

@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: 11

🧹 Outside diff range and nitpick comments (7)
src/readii/loaders.py (7)

1-9: Update module docstring to comply with NumPy style

The module docstring provides a good overview, but to maintain consistency with the updated linting rules and the NumPy docstring style guide, consider reformatting it accordingly.


37-39: Redundant conversion to Path

Since imgDirPath is converted to a Path object, ensure that this conversion is necessary and that all usages of imgDirPath require it. If imgDirPath is already a Path, the conversion is harmless but redundant.


68-71: Redundant conversion to Path

Ensure that converting rtstructPath and baseImageDirPath to Path objects is necessary. If they are already Path instances, the conversion is redundant but not harmful.


Line range hint 75-85: Silent exception handling without logging

In the exception block, the ValueError is caught, and an empty dictionary is returned without any logging. This could make debugging difficult if issues arise.

Consider logging the exception before returning:

 except ValueError as e:
+    logger.error(f"Failed to create ROI masks: {e}")
     return {}

111-138: Update function docstrings to comply with NumPy style

The function docstrings should be reformatted to adhere to the NumPy docstring conventions, ensuring consistency and improving readability across the codebase.


146-151: Normalize modality input for case-insensitive comparison

To make the modality checks more robust, consider converting the modality parameter to lowercase before comparison.

Apply this change:

+    modality = modality.lower()
     if modality in ["seg"]:
         # SEG handling code
     elif modality in ["rtstruct"]:
         # RTSTRUCT handling code

154-158: Ensure consistent indentation

The indentation for the raise ValueError statement and the subsequent else block should be consistent to maintain code readability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7bdf5d3 and 5d6a7f3.

⛔ Files ignored due to path filters (1)
  • pixi.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • .github/workflows/ci-cd.yml (4 hunks)
  • config/ruff.toml (3 hunks)
  • pyproject.toml (3 hunks)
  • src/readii/loaders.py (3 hunks)
🧰 Additional context used
🪛 yamllint
.github/workflows/ci-cd.yml

[error] 198-198: trailing spaces

(trailing-spaces)


[error] 220-220: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (5)
config/ruff.toml (3)

65-65: Verify quote style migration.

The change from single to double quotes will require updating all string literals in the codebase. Ensure that the auto-formatter is run across all Python files to maintain consistency.

#!/bin/bash
# Search for single quotes that might need updating
rg "'" --type py --glob '!tests/*'

61-61: Verify docstring migration from Google to NumPy style.

Changing the docstring convention from Google to NumPy style is a significant change that requires updating all existing docstrings to maintain consistency.

✅ Verification successful

Let me try a different approach to search for docstrings using ast-grep with a more specific pattern.

This will help us identify if there are Google-style docstrings that need updating and if any NumPy-style docstrings already exist, giving us a better picture of the migration status.


Based on the search results, I can now generate the final response:

No migration needed - codebase already uses NumPy docstring style

The codebase is already consistently using NumPy-style docstrings across multiple files (loaders.py, negative_controls.py, metadata.py, image_processing.py, feature_extraction.py) as evidenced by the NumPy-style section headers:

  • Parameters followed by ----------
  • Returns followed by -------
  • Raises followed by ------

No Google-style docstrings (with Args:, Returns:, Raises:) were found. The change in ruff.toml is actually aligning the configuration with the existing codebase convention.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potential Google-style docstrings that need updating
ast-grep --pattern 'def $_($$) {
  """
    Args:
      $$$
  """
  $$$
}'

Length of output: 6232


Script:

#!/bin/bash
# Search for Google-style docstrings with Args, Returns, Raises sections
rg "^\s+Args:|^\s+Returns:|^\s+Raises:" --type py --multiline

# Also search for NumPy-style docstrings to see if migration is in progress
rg "^\s+Parameters\n\s+-+|^\s+Returns\n\s+-+|^\s+Raises\n\s+-+" --type py --multiline

Length of output: 5797


30-36: Verify the impact of disabled linting rules.

While adding pydocstyle (D) is beneficial, disabling pep8-naming (N) and flake8-logging-format (G) might lead to:

  1. Inconsistent naming conventions across the codebase
  2. Inconsistent logging format patterns

Consider keeping these rules enabled to maintain code quality standards.

pyproject.toml (1)

116-126: ⚠️ Potential issue

Enhance publish-test task with authentication and validation

The TestPyPI publishing task needs additional safeguards:

  1. Add required environment variables for authentication:
 publish-test = { cmd = [
   "hatch",
   "publish",
   "--yes",
   "--repo",
   "test",
 ], inputs = [
   "dist/*",
 ], depends-on = [
   "build",
- ], env = { HATCH_CONFIG = "config/hatch.toml" }, description = "Publish to test PyPI" }
+ ], env = { 
+   "HATCH_CONFIG" = "config/hatch.toml",
+   "HATCH_INDEX_AUTH" = "${HATCH_INDEX_AUTH}",
+ }, description = "Publish to test PyPI" }
  1. Add a validation step to ensure the build artifacts exist and are valid:
 publish-test = { cmd = [
+  "sh",
+  "-c",
+  """
+  if [ ! -f "dist/*.whl" ] || [ ! -f "dist/*.tar.gz" ]; then
+    echo "Error: Build artifacts missing" >&2
+    exit 1
+  fi
   "hatch",
   "publish",
.github/workflows/ci-cd.yml (1)

5-9: Review workflow trigger configuration

The current trigger configuration might prevent automatic deployments:

  • The commented-out push trigger means the workflow won't run on direct pushes to any branch
  • This could prevent automatic releases when merging to main, as the Semantic-Release job specifically checks for refs/heads/main

Consider keeping the push trigger for the main branch:

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["*"]

…espace and ensuring proper formatting at end of file
Copy link
Contributor

@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: 6

🧹 Outside diff range and nitpick comments (2)
pyproject.toml (2)

88-91: Update format task description to match actual capabilities

The description mentions using --diff but since Pixi doesn't support command options (as per previous discussion), consider updating the description to be more accurate.

-description = "Run ruff formatter, use `--diff` to see changes only"
+description = "Run ruff formatter"

111-112: Consider using more precise branch patterns

While better than "*", the current pattern could be more precise. Consider using start/end anchors to prevent partial matches.

-match = "(main|development)"
+match = "^(main|development)$"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5d6a7f3 and a6298ab.

⛔ Files ignored due to path filters (1)
  • pixi.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • .github/workflows/ci-cd.yml (4 hunks)
  • pyproject.toml (2 hunks)
  • src/readii/loaders.py (3 hunks)
🧰 Additional context used
📓 Learnings (1)
.github/workflows/ci-cd.yml (1)
Learnt from: jjjermiah
PR: bhklab/readii#42
File: .github/workflows/ci-cd.yml:145-152
Timestamp: 2024-10-22T17:19:25.869Z
Learning: Do not suggest optimizing cache configuration in the Semantic-Release job in `.github/workflows/ci-cd.yml`.
🔇 Additional comments (7)
pyproject.toml (1)

135-145: LGTM! Well-structured TestPyPI publishing configuration

The publish-test task is properly configured with:

  • Correct dependency on the build task
  • Appropriate repository specification
  • Proper environment configuration
src/readii/loaders.py (5)

1-9: Well-structured module documentation!

The added module docstring provides clear and comprehensive documentation about the module's purpose and capabilities.


25-38: Type annotation compatibility issue persists

The use of str | Path type annotation requires Python 3.10+.


72-74: Good logging and path resolution implementation!

The addition of debug logging and proper path resolution using .resolve() improves the robustness of the function.


140-143: Improved error message clarity!

The error message now includes the actual modality value, making it more helpful for debugging.


145-147: Verify path traversal protection

The code handles user-provided paths. While using Path objects is good, let's verify that the codebase has proper path traversal protection.

✅ Verification successful

Let me check the actual implementation of path handling in loaders.py to make a more informed decision.

The initial results show path-related operations, but I need to see the actual implementation to verify if there's proper path validation. This will help determine if there are any security concerns with path handling.


Based on the code inspection, I can now provide a final response:

Path handling implementation is secure

The code implements proper path handling through:

  • Consistent conversion of input paths to Path objects
  • Use of resolve() to get absolute paths before file operations
  • Proper validation of input types and modalities
  • No direct path concatenation or manipulation that could lead to traversal

The use of Path.resolve() before file operations ensures that symbolic links are resolved and absolute paths are used, which is a good security practice. The parent directory access (Path.parent) is used safely within the context of already resolved paths.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for path validation or sanitization in the codebase
echo "Searching for path validation patterns..."
rg -l "resolve\(\)" --type py
rg -l "absolute\(\)" --type py
rg -l "Path\.parent" --type py
rg -l "pathlib\.Path" --type py

echo "Checking for potential path traversal vulnerabilities..."
rg -l "\.\./" --type py
rg -l "\.\." --type py

Length of output: 569


Script:

#!/bin/bash
# Check path handling implementation in loaders.py
echo "Checking path handling in loaders.py..."
rg "resolve\(\)" -A 5 -B 5 src/readii/loaders.py
rg "Path\.parent" -A 5 -B 5 src/readii/loaders.py

# Check how the paths are used
echo "\nChecking path usage patterns..."
rg "Path\(" -A 5 -B 5 src/readii/loaders.py

Length of output: 3446

.github/workflows/ci-cd.yml (1)

106-106: LGTM: Semantic Release job changes

The addition of the Ruff job as a dependency ensures linting passes before releases.

Also applies to: 145-152

Copy link
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (1)
pyproject.toml (1)

82-91: Clean up style tasks configuration

Minor improvements needed:

  1. Remove extra space in lint command
  2. Clarify how to use the --diff option in format task description
 [tool.pixi.feature.style.tasks.lint]
-cmd = "ruff check  --config=config/ruff.toml"
+cmd = "ruff check --config=config/ruff.toml"

 [tool.pixi.feature.style.tasks.format]
 cmd = "ruff format --config=config/ruff.toml"
 inputs = ["src", "config/ruff.toml"]
-description = "Run ruff formatter, use `--diff` to see changes only"
+description = "Run ruff formatter. Add '--diff' to preview changes without applying them"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a6298ab and bdb49ea.

⛔ Files ignored due to path filters (1)
  • pixi.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • pyproject.toml (2 hunks)
  • src/readii/loaders.py (3 hunks)
🧰 Additional context used
🔇 Additional comments (6)
pyproject.toml (1)

135-145: Enhance publish-test task configuration

The task configuration looks good but could benefit from additional documentation and error handling considerations.

Consider updating the description to be more informative:

-], env = { HATCH_CONFIG = "config/hatch.toml" }, description = "Publish to test PyPI" }
+], env = { HATCH_CONFIG = "config/hatch.toml" }, description = "Build and publish package to TestPyPI for pre-release testing" }

Ensure TestPyPI credentials are properly configured in CI:

#!/bin/bash
# Check if TestPyPI token is configured in GitHub Actions
gh api /repos/bhklab/readii/actions/secrets | jq -r '.secrets[] | select(.name | contains("PYPI")) | .name'
src/readii/loaders.py (5)

1-23: Well-structured module documentation and imports!

The comprehensive module docstring and organized imports provide clear context and maintainable structure.


Line range hint 25-44: Update type annotation for Python <3.10 compatibility

The function implementation is solid with good path handling and logging. However, as noted in previous reviews, the type annotation needs updating for broader Python version compatibility.

Apply this change:

+from typing import Union

-def loadDicomSITK(imgDirPath: str | Path) -> sitk.Image:
+def loadDicomSITK(imgDirPath: Union[str, Path]) -> sitk.Image:

Line range hint 48-103: Update type annotations for Python <3.10 compatibility

The function implementation is well-structured with proper path handling and logging. However, as noted in previous reviews, the type annotations need updating for broader Python version compatibility.

Apply this change:

+from typing import Union

-def loadRTSTRUCTSITK(
-    rtstructPath: str | Path, baseImageDirPath: str | Path, roiNames: Optional[str] = None
-) -> Dict[str, sitk.Image]:
+def loadRTSTRUCTSITK(
+    rtstructPath: Union[str, Path],
+    baseImageDirPath: Union[str, Path],
+    roiNames: Optional[str] = None
+) -> Dict[str, sitk.Image]:

140-166: Great improvements in error handling and path management!

The changes show excellent attention to detail:

  1. More informative error messages with the actual modality value
  2. Consistent path handling with explicit conversions
  3. Proper case-insensitive modality checking

106-110: ⚠️ Potential issue

Update type annotations for Python <3.10 compatibility

The function signature needs updating for broader Python version compatibility.

Apply this change:

+from typing import Union

-def loadSegmentation(
-    segImagePath: str | Path,
-    modality: str,
-    baseImageDirPath: Optional[str | Path] = None,
-    roiNames: Optional[str] = None,
-) -> Dict[str, sitk.Image]:
+def loadSegmentation(
+    segImagePath: Union[str, Path],
+    modality: str,
+    baseImageDirPath: Optional[Union[str, Path]] = None,
+    roiNames: Optional[str] = None,
+) -> Dict[str, sitk.Image]:

@jjjermiah jjjermiah requested a review from strixy16 October 22, 2024 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants