mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 04:14:59 +00:00
style: Address flake8 errors
This commit is contained in:
parent
38e7f04e60
commit
023e939798
4 changed files with 31 additions and 25 deletions
|
@ -1,6 +1,5 @@
|
|||
import os
|
||||
import re
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import traceback
|
||||
|
|
|
@ -134,15 +134,16 @@ class GitRepo:
|
|||
Args:
|
||||
fnames (list, optional): List of filenames to commit. Defaults to None (commit all
|
||||
dirty files).
|
||||
context (str, optional): Context for generating the commit message. Defaults to None.
|
||||
context (str, optional): Context for generating commit message. Defaults to None.
|
||||
message (str, optional): Explicit commit message. Defaults to None (generate message).
|
||||
aider_edits (bool, optional): Whether the changes were made by Aider. Defaults to False.
|
||||
This affects attribution logic.
|
||||
coder (Coder, optional): The Coder instance, used to access config and model info.
|
||||
coder (Coder, optional): The Coder instance, used for config and model info.
|
||||
Defaults to None.
|
||||
|
||||
Returns:
|
||||
tuple(str, str) or None: The commit hash and commit message if successful, else None.
|
||||
tuple(str, str) or None: The commit hash and commit message if successful,
|
||||
else None.
|
||||
|
||||
Attribution Logic:
|
||||
------------------
|
||||
|
@ -154,16 +155,16 @@ class GitRepo:
|
|||
- Committer: The person who last applied the commit to the repository.
|
||||
- aider_edits=True: Changes were generated by Aider (LLM).
|
||||
- aider_edits=False: Commit is user-driven (e.g., /commit manually staged changes).
|
||||
- Explicit Setting: A flag (--attribute-...) is set to True or False via command line
|
||||
or config file.
|
||||
- Explicit Setting: A flag (--attribute-...) is set to True or False
|
||||
via command line or config file.
|
||||
- Implicit Default: A flag is not explicitly set, defaulting to None in args, which is
|
||||
interpreted as True unless overridden by other logic.
|
||||
|
||||
Flags:
|
||||
- --attribute-author: Modify Author name to "User Name (aider)".
|
||||
- --attribute-committer: Modify Committer name to "User Name (aider)".
|
||||
- --attribute-co-authored-by: Add "Co-authored-by: aider (<model>) <noreply@aider.chat>"
|
||||
trailer to the commit message.
|
||||
- --attribute-co-authored-by: Add
|
||||
"Co-authored-by: aider (<model>) <noreply@aider.chat>" trailer to commit message.
|
||||
|
||||
Behavior Summary:
|
||||
|
||||
|
@ -171,8 +172,8 @@ class GitRepo:
|
|||
- If --attribute-co-authored-by=True:
|
||||
- Co-authored-by trailer IS ADDED.
|
||||
- Author/Committer names are NOT modified by default (co-authored-by takes precedence).
|
||||
- EXCEPTION: If --attribute-author/--attribute-committer is EXPLICITLY True,
|
||||
the respective name IS modified (explicit overrides precedence).
|
||||
- EXCEPTION: If --attribute-author/--attribute-committer is EXPLICITLY True, the
|
||||
respective name IS modified (explicit overrides precedence).
|
||||
- If --attribute-co-authored-by=False:
|
||||
- Co-authored-by trailer is NOT added.
|
||||
- Author/Committer names ARE modified by default (implicit True).
|
||||
|
@ -186,11 +187,15 @@ class GitRepo:
|
|||
- EXCEPTION: If --attribute-committer is EXPLICITLY False, the name is NOT modified.
|
||||
|
||||
Resulting Scenarios:
|
||||
- Standard AI edit (defaults): Co-authored-by=False -> Author=You(aider), Committer=You(aider)
|
||||
- AI edit with Co-authored-by (default): Co-authored-by=True -> Author=You, Committer=You, Trailer added
|
||||
- AI edit with Co-authored-by + Explicit Author: Co-authored-by=True, --attribute-author -> Author=You(aider), Committer=You, Trailer added
|
||||
- Standard AI edit (defaults): Co-authored-by=False -> Author=You(aider),
|
||||
Committer=You(aider)
|
||||
- AI edit with Co-authored-by (default): Co-authored-by=True -> Author=You,
|
||||
Committer=You, Trailer added
|
||||
- AI edit with Co-authored-by + Explicit Author: Co-authored-by=True,
|
||||
--attribute-author -> Author=You(aider), Committer=You, Trailer added
|
||||
- User commit (defaults): aider_edits=False -> Author=You, Committer=You(aider)
|
||||
- User commit with explicit no-committer: aider_edits=False, --no-attribute-committer -> Author=You, Committer=You
|
||||
- User commit with explicit no-committer: aider_edits=False,
|
||||
--no-attribute-committer -> Author=You, Committer=You
|
||||
"""
|
||||
if not fnames and not self.repo.is_dirty():
|
||||
return
|
||||
|
@ -244,13 +249,15 @@ class GitRepo:
|
|||
|
||||
# Determine if author/committer names should be modified
|
||||
# Author modification applies only to aider edits.
|
||||
# It's used if effective_author is True AND (co-authored-by is False OR author was explicitly set).
|
||||
# It's used if effective_author is True AND
|
||||
# (co-authored-by is False OR author was explicitly set).
|
||||
use_attribute_author = (
|
||||
aider_edits and effective_author and (not attribute_co_authored_by or author_explicit)
|
||||
)
|
||||
|
||||
# Committer modification applies regardless of aider_edits (based on tests).
|
||||
# It's used if effective_committer is True AND (it's not an aider edit with co-authored-by OR committer was explicitly set).
|
||||
# It's used if effective_committer is True AND
|
||||
# (it's not an aider edit with co-authored-by OR committer was explicitly set).
|
||||
use_attribute_committer = effective_committer and (
|
||||
not (aider_edits and attribute_co_authored_by) or committer_explicit
|
||||
)
|
||||
|
|
|
@ -294,7 +294,8 @@ class TestRepo(unittest.TestCase):
|
|||
|
||||
@unittest.skipIf(platform.system() == "Windows", "Git env var behavior differs on Windows")
|
||||
def test_commit_co_authored_by_with_explicit_name_modification(self):
|
||||
# Test scenario where Co-authored-by is true AND author/committer modification are explicitly True
|
||||
# Test scenario where Co-authored-by is true AND
|
||||
# author/committer modification are explicitly True
|
||||
with GitTemporaryDirectory():
|
||||
# Setup repo...
|
||||
# new repo
|
||||
|
@ -308,7 +309,8 @@ class TestRepo(unittest.TestCase):
|
|||
raw_repo.git.add(str(fname))
|
||||
raw_repo.git.commit("-m", "initial commit")
|
||||
|
||||
# Mock coder args: Co-authored-by enabled, author/committer modification explicitly enabled
|
||||
# Mock coder args: Co-authored-by enabled,
|
||||
# author/committer modification explicitly enabled
|
||||
mock_coder = MagicMock()
|
||||
mock_coder.args.attribute_co_authored_by = True
|
||||
mock_coder.args.attribute_author = True # Explicitly enable
|
||||
|
@ -334,7 +336,8 @@ class TestRepo(unittest.TestCase):
|
|||
"Co-authored-by: aider (gpt-test-combo) <noreply@aider.chat>", commit.message
|
||||
)
|
||||
self.assertEqual(commit.message.splitlines()[0], "Aider combo edit")
|
||||
# When co-authored-by is true BUT author/committer are explicit True, modification SHOULD happen
|
||||
# When co-authored-by is true BUT author/committer are explicit True,
|
||||
# modification SHOULD happen
|
||||
self.assertEqual(
|
||||
commit.author.name,
|
||||
"Test User (aider)",
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from aider.scrape import Scraper, install_playwright
|
||||
from aider.scrape import Scraper
|
||||
|
||||
|
||||
class DummyIO:
|
||||
|
@ -23,7 +19,8 @@ class DummyIO:
|
|||
|
||||
def test_scraper_disable_playwright_flag(monkeypatch):
|
||||
io = DummyIO()
|
||||
# Simulate that playwright is not available (disable_playwright just means playwright_available=False)
|
||||
# Simulate that playwright is not available
|
||||
# (disable_playwright just means playwright_available=False)
|
||||
scraper = Scraper(print_error=io.tool_error, playwright_available=False)
|
||||
# Patch scrape_with_httpx to check it is called
|
||||
called = {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue