From aa6a5389921c88ad96cc53841cd1874cb07f9605 Mon Sep 17 00:00:00 2001 From: Branch Vincent Date: Mon, 12 Aug 2024 19:42:32 -0700 Subject: [PATCH 01/11] migrate to pyproject.toml --- .github/workflows/release.yml | 4 +- .gitignore | 1 + MANIFEST.in | 1 - pyproject.toml | 58 ++++++++++++++++++++++++++++ setup.py | 73 ----------------------------------- 5 files changed, 61 insertions(+), 76 deletions(-) delete mode 100644 MANIFEST.in create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 70ea3402e..274be72c5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,12 +21,12 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine importlib-metadata==7.2.1 + pip install build setuptools wheel twine importlib-metadata==7.2.1 - name: Build and publish env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} run: | - python setup.py sdist bdist_wheel + python -m build twine upload dist/* diff --git a/.gitignore b/.gitignore index a6a3dbfed..ae668b707 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ aider.code-workspace .aider* aider_chat.egg-info/ build +dist/ Gemfile.lock _site .jekyll-cache/ diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index f9bd1455b..000000000 --- a/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include requirements.txt diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..9b9e9baa6 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,58 @@ +[project] +name = "aider-chat" +description = "Aider is AI pair programming in your terminal" +readme = "README.md" +classifiers = [ + "Development Status :: 4 - Beta", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python", + "Topic :: Software Development", +] +requires-python = ">=3.9,<3.13" +dynamic = ["dependencies", "optional-dependencies", "version"] + +[project.urls] +Homepage = "https://github.com/paul-gauthier/aider" + +[project.scripts] +aider = "aider.main:main" + +[tool.setuptools.dynamic] +version = { attr = "aider.__init__.__version__" } +dependencies = { file = "requirements.txt" } + +[tool.setuptools.dynamic.optional-dependencies] +dev = { file = "requirements/requirements-dev.txt" } +help = { file = "requirements/requirements-help.txt" } +browser = { file = "requirements/requirements-browser.txt" } +playwright = { file = "requirements/requirements-playwright.txt" } + +[tool.setuptools.packages.find] +include = ["aider*", "aider.website"] + +[tool.setuptools.package-data] +"aider" = ["queries/*.scm"] +"aider.website" = ["**/*.md"] + +[tool.setuptools.exclude-package-data] +"aider.website" = [ + "examples/**", + "_posts/**", + "HISTORY.md", + "docs/benchmarks*md", + "docs/ctags.md", + "docs/unified-diffs.md", + "docs/leaderboards/index.md", + "assets/**", +] + +[build-system] +requires = ["setuptools>=68"] +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py deleted file mode 100644 index 10a0b8c76..000000000 --- a/setup.py +++ /dev/null @@ -1,73 +0,0 @@ -import re -from pathlib import Path - -from setuptools import find_packages, setup - -from aider import __version__ -from aider.help_pats import exclude_website_pats - - -def get_requirements(suffix=""): - if suffix: - fname = "requirements-" + suffix + ".txt" - fname = Path("requirements") / fname - else: - fname = Path("requirements.txt") - - requirements = fname.read_text().splitlines() - - return requirements - - -requirements = get_requirements() - -# README -with open("README.md", "r", encoding="utf-8") as f: - long_description = f.read() - long_description = re.sub(r"\n!\[.*\]\(.*\)", "", long_description) - # long_description = re.sub(r"\n- \[.*\]\(.*\)", "", long_description) - -# Discover packages, plus the website -packages = find_packages(exclude=["benchmark", "tests"]) -packages += ["aider.website"] - -print("Packages:", packages) - -extras = "dev help browser playwright".split() - -setup( - name="aider-chat", - version=__version__, - packages=packages, - include_package_data=True, - package_data={ - "aider": ["queries/*.scm"], - "aider.website": ["**/*.md"], - }, - exclude_package_data={"aider.website": exclude_website_pats}, - install_requires=requirements, - extras_require={extra: get_requirements(extra) for extra in extras}, - python_requires=">=3.9,<3.13", - entry_points={ - "console_scripts": [ - "aider = aider.main:main", - ], - }, - description="Aider is AI pair programming in your terminal", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/paul-gauthier/aider", - classifiers=[ - "Development Status :: 4 - Beta", - "Environment :: Console", - "Intended Audience :: Developers", - "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python", - "Topic :: Software Development", - ], -) From c1fc69ff43926c05ab5d4bfaf37808cf6397664a Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 13 Aug 2024 08:13:06 -0700 Subject: [PATCH 02/11] copy --- aider/website/HISTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/aider/website/HISTORY.md b/aider/website/HISTORY.md index 8eba0623f..eedb0f8ac 100644 --- a/aider/website/HISTORY.md +++ b/aider/website/HISTORY.md @@ -20,6 +20,7 @@ cog.out(text) - Infinite output for DeepSeek Coder, Mistral models in addition to Anthropic's models. - New `--deepseek` switch to use DeepSeek Coder. +- DeepSeek Coder uses 8k token output. - New `--chat-mode ` switch to launch in ask/help/code modes. - New `/code ` command request a code edit while in `ask` mode. - Web scraper is more robust if page never idles. From d0ab70eba0e24c624ae88bc4cd65813f090f6c41 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 13 Aug 2024 09:19:54 -0700 Subject: [PATCH 03/11] feat: Add note for Windows users about restarting terminal after setting environment variables --- aider/models.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aider/models.py b/aider/models.py index 551d0b9a4..30ae58c5e 100644 --- a/aider/models.py +++ b/aider/models.py @@ -3,6 +3,7 @@ import importlib import json import math import os +import platform import sys from dataclasses import dataclass, fields from pathlib import Path @@ -674,6 +675,10 @@ def sanity_check_model(io, model): io.tool_error(f"Model {model}: Missing these environment variables:") for key in model.missing_keys: io.tool_error(f"- {key}") + + if platform.system() == "Windows": + io.tool_output("\nNote for Windows users: If you've just set these environment variables using 'setx',") + io.tool_output("you may need to restart your terminal or command prompt for the changes to take effect.") elif not model.keys_in_environment: show = True io.tool_output(f"Model {model}: Unknown which environment variables are required.") From 4d9f091802fe7b84bce9f18fce8d93f5d182ed96 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 13 Aug 2024 09:19:58 -0700 Subject: [PATCH 04/11] style: format code for better readability --- aider/models.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/aider/models.py b/aider/models.py index 30ae58c5e..849a9c1aa 100644 --- a/aider/models.py +++ b/aider/models.py @@ -675,10 +675,16 @@ def sanity_check_model(io, model): io.tool_error(f"Model {model}: Missing these environment variables:") for key in model.missing_keys: io.tool_error(f"- {key}") - + if platform.system() == "Windows": - io.tool_output("\nNote for Windows users: If you've just set these environment variables using 'setx',") - io.tool_output("you may need to restart your terminal or command prompt for the changes to take effect.") + io.tool_output( + "\nNote for Windows users: If you've just set these environment variables using" + " 'setx'," + ) + io.tool_output( + "you may need to restart your terminal or command prompt for the changes to take" + " effect." + ) elif not model.keys_in_environment: show = True io.tool_output(f"Model {model}: Unknown which environment variables are required.") From 390e425729f0bd345b8acba89463255a6e95f39a Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 13 Aug 2024 09:25:01 -0700 Subject: [PATCH 05/11] Warn windows users about setx restart terminal --- aider/models.py | 11 ++++------- aider/website/_includes/model-warnings.md | 4 ++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/aider/models.py b/aider/models.py index 849a9c1aa..cad99d1df 100644 --- a/aider/models.py +++ b/aider/models.py @@ -676,15 +676,12 @@ def sanity_check_model(io, model): for key in model.missing_keys: io.tool_error(f"- {key}") - if platform.system() == "Windows": + if platform.system() == "Windows" or True: io.tool_output( - "\nNote for Windows users: If you've just set these environment variables using" - " 'setx'," - ) - io.tool_output( - "you may need to restart your terminal or command prompt for the changes to take" - " effect." + "If you just set these environment variables using `setx` you may need to restart" + " your terminal or command prompt for the changes to take effect." ) + elif not model.keys_in_environment: show = True io.tool_output(f"Model {model}: Unknown which environment variables are required.") diff --git a/aider/website/_includes/model-warnings.md b/aider/website/_includes/model-warnings.md index bcf483b48..d6783de05 100644 --- a/aider/website/_includes/model-warnings.md +++ b/aider/website/_includes/model-warnings.md @@ -44,6 +44,10 @@ Model azure/gpt-4-turbo: Missing these environment variables: - AZURE_API_KEY ``` +{: .tip } +On Windows, +if you just set these environment variables using `setx` you may need to restart your terminal or +command prompt for the changes to take effect. ## Unknown which environment variables are required From 5d14d9359490d95882a0b29e80426027102bab17 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 13 Aug 2024 09:36:31 -0700 Subject: [PATCH 06/11] feat: use cog to import exclude_website_pats and emit it into the toml --- pyproject.toml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9b9e9baa6..15176f6c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,8 @@ +# [[[cog +# from aider.help_pats import exclude_website_pats +# ]]] +# [[[end]]] + [project] name = "aider-chat" description = "Aider is AI pair programming in your terminal" @@ -43,14 +48,10 @@ include = ["aider*", "aider.website"] [tool.setuptools.exclude-package-data] "aider.website" = [ - "examples/**", - "_posts/**", - "HISTORY.md", - "docs/benchmarks*md", - "docs/ctags.md", - "docs/unified-diffs.md", - "docs/leaderboards/index.md", - "assets/**", +# [[[cog +# print("\n".join(f' "{pat}",' for pat in exclude_website_pats)) +# ]]] +# [[[end]]] ] [build-system] From 211ab282532545148aa8d51a23ef7db58e88f5b6 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 13 Aug 2024 09:39:44 -0700 Subject: [PATCH 07/11] feat: add check_cog_pyproject function to run cog -r on pyproject.toml and abort if it has changed the file --- scripts/versionbump.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/versionbump.py b/scripts/versionbump.py index e7584f3e4..e81b10d95 100755 --- a/scripts/versionbump.py +++ b/scripts/versionbump.py @@ -5,10 +5,28 @@ import datetime import re import subprocess import sys - +import tempfile +import filecmp from packaging import version +def check_cog_pyproject(): + with tempfile.NamedTemporaryFile(mode='w+', delete=False) as temp_file: + with open('pyproject.toml', 'r') as original_file: + temp_file.write(original_file.read()) + + result = subprocess.run(["cog", "-r", "pyproject.toml"], capture_output=True, text=True) + + if result.returncode != 0: + print("Error: cog -r pyproject.toml failed with the following output:") + print(result.stderr) + sys.exit(1) + + if not filecmp.cmp('pyproject.toml', temp_file.name): + print("Error: cog -r pyproject.toml has changed the file. Please run cog -r pyproject.toml and commit the changes.") + sys.exit(1) + + def main(): parser = argparse.ArgumentParser(description="Bump version") parser.add_argument("new_version", help="New version in x.y.z format") @@ -56,6 +74,7 @@ def main(): check_branch() check_working_directory_clean() check_main_branch_up_to_date() + check_cog_pyproject() new_version_str = args.new_version if not re.match(r"^\d+\.\d+\.\d+$", new_version_str): From 458864be452532e823bfc49dc8437b411ae88454 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 13 Aug 2024 09:39:48 -0700 Subject: [PATCH 08/11] style: Apply linter edits to scripts/versionbump.py --- scripts/versionbump.py | 55 ++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/scripts/versionbump.py b/scripts/versionbump.py index e81b10d95..5902b2c91 100755 --- a/scripts/versionbump.py +++ b/scripts/versionbump.py @@ -2,28 +2,32 @@ import argparse import datetime +import filecmp import re import subprocess import sys import tempfile -import filecmp + from packaging import version def check_cog_pyproject(): - with tempfile.NamedTemporaryFile(mode='w+', delete=False) as temp_file: - with open('pyproject.toml', 'r') as original_file: + with tempfile.NamedTemporaryFile(mode="w+", delete=False) as temp_file: + with open("pyproject.toml", "r") as original_file: temp_file.write(original_file.read()) - + result = subprocess.run(["cog", "-r", "pyproject.toml"], capture_output=True, text=True) - + if result.returncode != 0: print("Error: cog -r pyproject.toml failed with the following output:") print(result.stderr) sys.exit(1) - - if not filecmp.cmp('pyproject.toml', temp_file.name): - print("Error: cog -r pyproject.toml has changed the file. Please run cog -r pyproject.toml and commit the changes.") + + if not filecmp.cmp("pyproject.toml", temp_file.name): + print( + "Error: cog -r pyproject.toml has changed the file. Please run cog -r pyproject.toml" + " and commit the changes." + ) sys.exit(1) @@ -33,16 +37,21 @@ def main(): parser.add_argument( "--dry-run", action="store_true", help="Print each step without actually executing them" ) + # Function to check if we are on the main branch def check_branch(): - branch = subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True, text=True).stdout.strip() + branch = subprocess.run( + ["git", "rev-parse", "--abbrev-ref", "HEAD"], capture_output=True, text=True + ).stdout.strip() if branch != "main": print("Error: Not on the main branch.") sys.exit(1) # Function to check if the working directory is clean def check_working_directory_clean(): - status = subprocess.run(["git", "status", "--porcelain"], capture_output=True, text=True).stdout + status = subprocess.run( + ["git", "status", "--porcelain"], capture_output=True, text=True + ).stdout if status: print("Error: Working directory is not clean.") sys.exit(1) @@ -50,19 +59,33 @@ def main(): # Function to fetch the latest changes and check if the main branch is up to date def check_main_branch_up_to_date(): subprocess.run(["git", "fetch", "origin"], check=True) - local_main = subprocess.run(["git", "rev-parse", "main"], capture_output=True, text=True).stdout.strip() + local_main = subprocess.run( + ["git", "rev-parse", "main"], capture_output=True, text=True + ).stdout.strip() print(f"Local main commit hash: {local_main}") - origin_main = subprocess.run(["git", "rev-parse", "origin/main"], capture_output=True, text=True).stdout.strip() + origin_main = subprocess.run( + ["git", "rev-parse", "origin/main"], capture_output=True, text=True + ).stdout.strip() print(f"Origin main commit hash: {origin_main}") if local_main != origin_main: - local_date = subprocess.run(["git", "show", "-s", "--format=%ci", "main"], capture_output=True, text=True).stdout.strip() - origin_date = subprocess.run(["git", "show", "-s", "--format=%ci", "origin/main"], capture_output=True, text=True).stdout.strip() + local_date = subprocess.run( + ["git", "show", "-s", "--format=%ci", "main"], capture_output=True, text=True + ).stdout.strip() + origin_date = subprocess.run( + ["git", "show", "-s", "--format=%ci", "origin/main"], capture_output=True, text=True + ).stdout.strip() local_date = datetime.datetime.strptime(local_date, "%Y-%m-%d %H:%M:%S %z") origin_date = datetime.datetime.strptime(origin_date, "%Y-%m-%d %H:%M:%S %z") if local_date < origin_date: - print("Error: The local main branch is behind origin/main. Please pull the latest changes.") + print( + "Error: The local main branch is behind origin/main. Please pull the latest" + " changes." + ) elif local_date > origin_date: - print("Error: The origin/main branch is behind the local main branch. Please push your changes.") + print( + "Error: The origin/main branch is behind the local main branch. Please push" + " your changes." + ) else: print("Error: The main branch and origin/main have diverged.") sys.exit(1) From d5f59d72e44bd2566b91928e70cefcaf5aa02852 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 13 Aug 2024 09:47:20 -0700 Subject: [PATCH 09/11] build: Update pyproject.toml to exclude additional website files --- pyproject.toml | 10 +++++++++- scripts/versionbump.py | 19 ++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 15176f6c7..4defa2772 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,8 +49,16 @@ include = ["aider*", "aider.website"] [tool.setuptools.exclude-package-data] "aider.website" = [ # [[[cog -# print("\n".join(f' "{pat}",' for pat in exclude_website_pats)) +# cog.out("\n".join(f' "{pat}",' for pat in exclude_website_pats)) # ]]] +"examples/**", +"_posts/**", +"HISTORY.md", +"docs/benchmarks*md", +"docs/ctags.md", +"docs/unified-diffs.md", +"docs/leaderboards/index.md", +"assets/**", # [[[end]]] ] diff --git a/scripts/versionbump.py b/scripts/versionbump.py index 5902b2c91..f66cc322c 100755 --- a/scripts/versionbump.py +++ b/scripts/versionbump.py @@ -12,22 +12,11 @@ from packaging import version def check_cog_pyproject(): - with tempfile.NamedTemporaryFile(mode="w+", delete=False) as temp_file: - with open("pyproject.toml", "r") as original_file: - temp_file.write(original_file.read()) - - result = subprocess.run(["cog", "-r", "pyproject.toml"], capture_output=True, text=True) + result = subprocess.run(["cog", "--check", "pyproject.toml"], capture_output=True, text=True) if result.returncode != 0: - print("Error: cog -r pyproject.toml failed with the following output:") - print(result.stderr) - sys.exit(1) - - if not filecmp.cmp("pyproject.toml", temp_file.name): - print( - "Error: cog -r pyproject.toml has changed the file. Please run cog -r pyproject.toml" - " and commit the changes." - ) + print("Error: cog --check pyproject.toml failed, updating.") + subprocess.run(["cog", "-r", "pyproject.toml"]) sys.exit(1) @@ -94,10 +83,10 @@ def main(): dry_run = args.dry_run # Perform checks before proceeding + check_cog_pyproject() check_branch() check_working_directory_clean() check_main_branch_up_to_date() - check_cog_pyproject() new_version_str = args.new_version if not re.match(r"^\d+\.\d+\.\d+$", new_version_str): From 14fb59f73bcc7e74f0ca462a3e793c8ab88fdf6c Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 13 Aug 2024 09:47:26 -0700 Subject: [PATCH 10/11] fix: Remove unused imports of `filecmp` and `tempfile` in `scripts/versionbump.py` --- scripts/versionbump.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/versionbump.py b/scripts/versionbump.py index f66cc322c..6838eea2a 100755 --- a/scripts/versionbump.py +++ b/scripts/versionbump.py @@ -2,11 +2,9 @@ import argparse import datetime -import filecmp import re import subprocess import sys -import tempfile from packaging import version From df1b036ba1503eebcf452f861fba6b8a185db16f Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 13 Aug 2024 09:50:06 -0700 Subject: [PATCH 11/11] copy --- HISTORY.md | 1 + aider/website/HISTORY.md | 1 + 2 files changed, 2 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index ca72881ec..7fd23ff7c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -11,6 +11,7 @@ - Web scraper is more robust if page never idles. - Improved token and cost reporting for infinite output. - Improvements and bug fixes for `/read` only files. +- Switched from `setup.py` to `pyproject.toml`, by @branchvincent. - Bug fix to persist files added during `/ask`. - Bug fix for chat history size in `/tokens`. diff --git a/aider/website/HISTORY.md b/aider/website/HISTORY.md index eedb0f8ac..f3cbe1e79 100644 --- a/aider/website/HISTORY.md +++ b/aider/website/HISTORY.md @@ -26,6 +26,7 @@ cog.out(text) - Web scraper is more robust if page never idles. - Improved token and cost reporting for infinite output. - Improvements and bug fixes for `/read` only files. +- Switched from `setup.py` to `pyproject.toml`, by @branchvincent. - Bug fix to persist files added during `/ask`. - Bug fix for chat history size in `/tokens`.