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

Centralize Python linter/formatter requirements #8854

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

SpecLad
Copy link
Contributor

@SpecLad SpecLad commented Dec 20, 2024

Motivation and context

These are currently duplicated all over the codebase, often with mismatched constraints. Put them all in one requirements file instead.

Fix a few minor issues while I'm at it:

  • Constrain black to the current major version to avoid New Year surprises (black can change styles between major versions). Constrain isort too, just in case.

  • Remove usages of egrep, which is deprecated (and unnecessary here).

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • [ ] I have created a changelog fragment
  • [ ] I have updated the documentation accordingly
  • [ ] I have added tests to cover my changes
  • [ ] I have linked related issues (see GitHub docs)
  • [ ] I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • New Features

    • Introduced new development dependencies, including black, isort, and pylint, to enhance code quality and consistency.
  • Bug Fixes

    • Removed outdated references to development requirements to streamline the installation process.
  • Documentation

    • Updated comments and structure in various requirements files for clarity.
  • Chores

    • Deleted obsolete requirements files and simplified existing ones to improve maintainability.

Copy link
Contributor

coderabbitai bot commented Dec 20, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces a significant restructuring of development requirements and workflow configurations. The changes primarily involve consolidating development dependencies into a new dev/requirements.txt file, removing existing requirement files in cvat-cli and cvat directories, and updating GitHub Actions workflows to reference the new requirements file. This reorganization simplifies dependency management and standardizes the approach to development tool installations across the project.

Changes

File Change Summary
.github/workflows/black.yml Updated Black package installation path from ./cvat-cli/requirements/development.txt to ./dev/requirements.txt
.github/workflows/isort.yml Modified isort installation to use ./dev/requirements.txt instead of ./cvat-cli/requirements/development.txt
.github/workflows/pylint.yml Updated Pylint installation paths to use ./dev/requirements.txt
cvat-cli/requirements/development.txt File deleted
cvat/requirements/all.txt Removed references to development.txt, production.txt, and testing.txt
cvat/requirements/development.in Removed multiple development dependencies
cvat/requirements/development.txt Significantly reduced number of dependencies
dev/requirements.txt New file created with development dependencies like Black, isort, Pylint
site/requirements.txt Removed isort version constraint

Poem

🐰 A Rabbit's Ode to Dependency Delight

Requirements scattered, now neatly aligned,
In dev/requirements.txt, dependencies refined
Black, isort, and Pylint, all in one place
A cleaner workflow with algorithmic grace
Hop, hop, hooray for code's new might! 🚀


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@SpecLad SpecLad force-pushed the central-dev-reqs branch 2 times, most recently from 2a435b5 to 93b0ee8 Compare December 20, 2024 14:04
These are currently duplicated all over the codebase, often with mismatched
constraints. Put them all in one requirements file instead.

Fix a few minor issues while I'm at it:

* Constrain black to the current major version to avoid New Year surprises
  (black can change styles between major versions). Constrain isort too,
  just in case.

* Remove usages of `egrep`, which is deprecated (and unnecessary here).
@SpecLad SpecLad marked this pull request as ready for review December 20, 2024 14:19
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: 0

🧹 Nitpick comments (2)
dev/requirements.txt (1)

1-5: Consider standardizing version constraint approach

The version constraints are inconsistent:

  • Formatters use major version constraints (24.*, 5.*)
  • Linters use exact versions (2.14.5, 2.5.3, 0.7)

Consider using similar constraint patterns for better maintainability:

 black==24.*
 isort==5.*
-pylint-django==2.5.3
-pylint-plugin-utils==0.7
-pylint==2.14.5
+pylint-django~=2.5.0
+pylint-plugin-utils~=0.7.0
+pylint~=2.14.0

This allows for patch updates while maintaining compatibility.

.github/workflows/black.yml (1)

11-11: Add error handling for requirement extraction

The grep command might fail if the requirement format changes. Consider adding error handling:

-          pipx install $(grep "^black" ./dev/requirements.txt)
+          BLACK_REQ=$(grep "^black==" ./dev/requirements.txt)
+          if [ -z "$BLACK_REQ" ]; then
+            echo "Error: Could not find black requirement"
+            exit 1
+          fi
+          pipx install $BLACK_REQ
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54534e8 and 60b1c93.

⛔ Files ignored due to path filters (1)
  • cvat-sdk/gen/requirements.txt is excluded by !**/gen/**
📒 Files selected for processing (10)
  • .github/workflows/black.yml (1 hunks)
  • .github/workflows/isort.yml (1 hunks)
  • .github/workflows/pylint.yml (1 hunks)
  • cvat-cli/requirements/development.txt (0 hunks)
  • cvat/requirements/all.txt (0 hunks)
  • cvat/requirements/development.in (0 hunks)
  • cvat/requirements/development.txt (1 hunks)
  • cvat/requirements/testing.txt (0 hunks)
  • dev/requirements.txt (1 hunks)
  • site/requirements.txt (0 hunks)
💤 Files with no reviewable changes (5)
  • site/requirements.txt
  • cvat-cli/requirements/development.txt
  • cvat/requirements/testing.txt
  • cvat/requirements/all.txt
  • cvat/requirements/development.in
✅ Files skipped from review due to trivial changes (1)
  • cvat/requirements/development.txt
🔇 Additional comments (3)
.github/workflows/pylint.yml (1)

22-26: 🛠️ Refactor suggestion

Improve dependency installation robustness

The current implementation has several potential issues:

  1. No error handling for requirement extraction
  2. Potential version conflicts between pylint plugins and Django

Consider this more robust approach:

-            pipx install $(grep "^pylint==" ./dev/requirements.txt)
-
-            pipx inject pylint \
-              $(grep "^pylint-.\+==" ./dev/requirements.txt) \
-              $(grep "^django==" ./cvat/requirements/base.txt)
+            # Extract requirements
+            PYLINT_REQ=$(grep "^pylint==" ./dev/requirements.txt)
+            PYLINT_PLUGINS=$(grep "^pylint-.\+==" ./dev/requirements.txt)
+            DJANGO_REQ=$(grep "^django==" ./cvat/requirements/base.txt)
+
+            # Validate requirements were found
+            if [ -z "$PYLINT_REQ" ] || [ -z "$PYLINT_PLUGINS" ] || [ -z "$DJANGO_REQ" ]; then
+                echo "Error: Could not find all required packages"
+                exit 1
+            fi
+
+            # Install pylint and inject dependencies
+            pipx install $PYLINT_REQ
+            pipx inject pylint $PYLINT_PLUGINS $DJANGO_REQ

Let's verify Django version compatibility:

✅ Verification successful

Refactoring suggestion is valid but version compatibility is not a concern

The original review comment's refactoring suggestion to improve error handling is valuable, but the concern about version conflicts between Django and pylint-django is unfounded:

  1. pylint-django 2.5.3 doesn't enforce strict Django version requirements (only optional with 'with_django' extra)
  2. Django 4.2.17 is a stable release and pylint-django is known to work with Django 4.x
  3. The current setup in the repository has been working with these exact versions

The suggested error handling improvements remain beneficial for robustness:

  • Validating package existence in requirements files
  • Using intermediate variables for better debugging
  • Proper error reporting and exit codes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check Django version constraints in both files
echo "Django version in base.txt:"
grep "^django==" ./cvat/requirements/base.txt

echo "Django version supported by pylint-django:"
grep "^pylint-django==" ./dev/requirements.txt

Length of output: 292


Script:

#!/bin/bash
# Check pylint-django package metadata for Django version compatibility
echo "Checking pylint-django package metadata:"
curl -s https://pypi.org/pypi/pylint-django/2.5.3/json | jq -r '.info.requires_dist[] | select(contains("Django"))'

# Check if there are any Django version constraints in pylint core
echo -e "\nChecking pylint version:"
grep "^pylint==" ./dev/requirements.txt

echo -e "\nChecking other pylint plugins that might have Django dependencies:"
grep "^pylint-" ./dev/requirements.txt

Length of output: 598

.github/workflows/isort.yml (2)

28-28: LGTM! Changes align with PR objectives.

The modification successfully:

  • Centralizes the isort requirement in the new dev/requirements.txt
  • Removes the deprecated egrep usage

28-28: Consider using absolute path for requirements file.

To make the script more robust against working directory changes, consider using $GITHUB_WORKSPACE:

-            pipx install $(grep "^isort" ./dev/requirements.txt)
+            pipx install $(grep "^isort" "${GITHUB_WORKSPACE}/dev/requirements.txt")

Let's verify the requirements file setup:

@SpecLad SpecLad requested a review from zhiltsov-max December 20, 2024 14:47
Copy link
Contributor

@zhiltsov-max zhiltsov-max left a comment

Choose a reason for hiding this comment

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

You should probably update development env setup instructions as well.

@archibald1418
Copy link
Contributor

archibald1418 commented Dec 23, 2024

This might seem a bit silly, but adding a spell-checker to CI would also be nice (just as already recommended here), this will enforce correct and unified English spelling in all qualifiers across the codebase. I had this funny thing where I'm searching keywords in the codebase and can't find anything only to later find out that they had been misspelled. Misspellings vary by each author so this might become an issue, too

@SpecLad
Copy link
Contributor Author

SpecLad commented Dec 23, 2024

You should probably update development env setup instructions as well.

Alright, updated.

@SpecLad
Copy link
Contributor Author

SpecLad commented Dec 23, 2024

@archibald1418 Yeah, it would be nice, but that's a big task in its own right.

Incidentally, if you do find misspellings/typos, feel free to submit a PR to fix them.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.87%. Comparing base (54534e8) to head (edaec47).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8854      +/-   ##
===========================================
- Coverage    73.88%   73.87%   -0.01%     
===========================================
  Files          408      408              
  Lines        44086    44104      +18     
  Branches      3986     3986              
===========================================
+ Hits         32575    32584       +9     
- Misses       11511    11520       +9     
Components Coverage Δ
cvat-ui 78.33% <ø> (-0.05%) ⬇️
cvat-server 70.08% <ø> (+0.02%) ⬆️

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.

4 participants