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 ruff sort imports #47

Merged
merged 1 commit into from
May 22, 2024
Merged

Make ruff sort imports #47

merged 1 commit into from
May 22, 2024

Conversation

madeddie
Copy link
Owner

@madeddie madeddie commented May 22, 2024

Summary by CodeRabbit

  • Chores

    • Updated pre-commit configuration to enhance code formatting checks.
  • Refactor

    • Reordered import statements for better readability and organization across multiple files.

Copy link

@senior-dev-bot senior-dev-bot bot left a comment

Choose a reason for hiding this comment

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

Feedback from Senior Dev Bot

Comment on lines 1 to 6
import pytest
import requests_mock
import tyora


def test_parse_args_missing_args() -> None:

Choose a reason for hiding this comment

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

CODE REVIEW

  • No need to re-import tyora after requests_mock.
  • Ensure imports are sorted alphabetically.
import pytest
import requests_mock
import tyora

This keeps imports clean and manageable.

Comment on lines 1 to 5
import io
from html.parser import HTMLParser
from typing import Optional
from xml.etree.ElementTree import Element

Choose a reason for hiding this comment

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

CODE REVIEW

Great addition of Optional from the typing module. Minor formatting improvement: maintain alphabetical order.

from html.parser import HTMLParser
from typing import Optional
from xml.etree.ElementTree import Element
import io

Comment on lines 16 to 22
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
args: [ --select, I, --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy

Choose a reason for hiding this comment

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

CODE REVIEW

Your changes improve the specific linting rules applied. However:

  1. Validate that ruff-format aligns with your code style.
  2. Ensure the removed repo: for mypy is intentional.

Example:

hooks:
  - id: ruff
    args: [ --select I, --fix ]
  - id: ruff-format  
  - repo: https://github.com/pre-commit/mirrors-mypy
    id: mypy

Comment on lines 1 to 18
import argparse
import json
import logging
from dataclasses import dataclass, field
from enum import Enum
from getpass import getpass
import logging
import json
from urllib.parse import urljoin
from pathlib import Path
from time import sleep
from typing import AnyStr, Optional
from urllib.parse import urljoin
from xml.etree.ElementTree import Element, tostring

from html2text import html2text
import htmlement
import requests

from html2text import html2text

logger = logging.getLogger(name="tyora")

Choose a reason for hiding this comment

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

CODE REVIEW

Your import reorganization improves readability, but some imports still need adjustments.

  1. Standard Imports First: Arrange built-in modules before third-party ones.
  2. Alphabetical Order: Sort imports alphabetically within each group.
import argparse
import json
import logging
from dataclasses import dataclass, field
from enum import Enum
from getpass import getpass
from pathlib import Path
from time import sleep
from typing import AnyStr, Optional
from urllib.parse import urljoin
from xml.etree.ElementTree import Element, tostring

import html2text
import htmlement
import requests

@madeddie madeddie merged commit 1f9acc9 into main May 22, 2024
4 checks passed
@madeddie madeddie deleted the sort_imports branch May 22, 2024 16:46
Copy link
Contributor

coderabbitai bot commented May 22, 2024

Walkthrough

The recent changes primarily focus on reordering import statements across multiple files to improve code organization and readability. Additionally, the .pre-commit-config.yaml file has been updated to enhance the ruff hook configuration by adding the --select I argument for improved code quality checks.

Changes

File Change Summary
.pre-commit-config.yaml Modified ruff hook arguments to include --select, I in addition to --fix.
src/tyora/__init__.py Reordered imports, moving json and logging up, and added html2text import.
stubs/htmlement.pyi Moved HTMLParser import to the top of the file.
tests/test_tyora.py Reordered imports, moving import tyora to the end of the block.

🐇
In lines of code, we made a shift,
Imports moved and given a lift.
With ruff we now inspect with care,
To keep our code both neat and fair.
The rabbit hops with joy and glee,
For organized imports set us free!


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 2b314ce and 5104c16.
Files selected for processing (4)
  • .pre-commit-config.yaml (1 hunks)
  • src/tyora/init.py (1 hunks)
  • stubs/htmlement.pyi (1 hunks)
  • tests/test_tyora.py (1 hunks)
Files skipped from review due to trivial changes (3)
  • .pre-commit-config.yaml
  • stubs/htmlement.pyi
  • tests/test_tyora.py
Additional comments not posted (1)
src/tyora/__init__.py (1)

2-3: Reordered imports and added html2text import.

The reordering of imports and the addition of html2text align with Python's best practices of grouping and ordering imports. This change improves readability and maintainability.

Also applies to: 15-15

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.

1 participant