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

Add setup file generation #617

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: no-commit-to-branch
- repo: local
hooks:
- id: build-setup-scripts
name: build setup scripts
entry: "scripts/pre-commit-build-setup-files.sh"
language: python
# language_version: python3.9
types: [python]
require_serial: true
verbose: true
additional_dependencies: ['jinja2', 'toml', 'ruff']
- repo: local
hooks:
- id: lint
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ lint = [
]

dev = [
"toml==0.10.2",
"pyautogen[lint,test,types,docs]",
"pre-commit==4.1.0",
"detect-secrets==1.5.0",
Expand Down Expand Up @@ -268,7 +269,7 @@ fix = true
line-length = 120
target-version = 'py39'
#include = ["autogen", "test", "docs"]
#exclude = []
exclude = ["setup_*.py"]

[tool.ruff.lint]
# Enable Pyflakes `E` and `F` codes by default.
Expand Down
52 changes: 52 additions & 0 deletions scripts/build-setup-files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python


# Copyright (c) 2023 - 2024, Owners of https://github.com/ag2ai
#
# SPDX-License-Identifier: Apache-2.0

from pathlib import Path

import toml
from jinja2 import Template


def get_optional_dependencies(pyproject_path: str) -> dict:
with open(pyproject_path, "r") as f:
pyproject_data = toml.load(f)

optional_dependencies = pyproject_data.get("project", {}).get("optional-dependencies", {})
return optional_dependencies


# Example usage
pyproject_path = Path(__file__).parent.joinpath("../pyproject.toml")
optional_dependencies = get_optional_dependencies(pyproject_path)
optional_groups = [group for group in optional_dependencies.keys()]

# for group, dependencies in optional_dependencies.items():
# print(f"Group: {group}")
# for dependency in dependencies:
# print(f" - {dependency}")

template_path = Path(__file__).parents[1].joinpath("setup.jinja")
assert template_path.exists()

with template_path.open("r") as f:
template_str = f.read()

if len(template_str) < 100:
raise ValueError("Template string is too short")

# Create a Jinja2 template object
template = Template(template_str)

for name in ["ag2", "autogen"]:
file_name = f"setup_{name}.py"
file_path = Path(__file__).parents[1].joinpath(file_name)
# Render the template with the optional dependencies
rendered_setup_py = template.render(optional_dependencies=optional_dependencies, name=name)

# Write the rendered setup.py to a file
with file_path.open("w") as setup_file:
setup_file.write(rendered_setup_py)
14 changes: 14 additions & 0 deletions scripts/pre-commit-build-setup-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# taken from: https://jaredkhan.com/blog/mypy-pre-commit

# A script for running mypy,
# with all its dependencies installed.

set -o errexit

# Change directory to the project root directory.
cd "$(dirname "$0")"/..

./scripts/build-setup-files.py
ruff check -s setup_*.py
45 changes: 45 additions & 0 deletions setup.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) 2023 - 2024, Owners of https://github.com/ag2ai
#
# SPDX-License-Identifier: Apache-2.0

# this file is autogenerated, please do not edit it directly
# instead, edit the corresponding setup.jinja file and run the ./scripts/build-setup-files.py script

import os

import setuptools

here = os.path.abspath(os.path.dirname(__file__))

with open("README.md", "r", encoding="UTF-8") as fh:
long_description = fh.read()

# Get the code version
version = {}
with open(os.path.join(here, "autogen/version.py")) as fp:
exec(fp.read(), version)
__version__ = version["__version__"]

setuptools.setup(
name="{{ name }}",
version=__version__,
description="Alias package for pyautogen",
long_description=long_description,
long_description_content_type="text/markdown",
install_requires=["pyautogen==" + __version__],
extras_require={
{% for group, packages in optional_dependencies.items() -%}
"{{ group }}": ["pyautogen[{{ group }}]==" + __version__],
{% endfor %}
},
url="https://github.com/ag2ai/ag2",
author="Chi Wang & Qingyun Wu",
author_email="[email protected]",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
],
license="Apache Software License 2.0",
python_requires=">=3.9,<3.14",
)
30 changes: 19 additions & 11 deletions setup_ag2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#
# SPDX-License-Identifier: Apache-2.0

# this file is autogenerated, please do not edit it directly
# instead, edit the corresponding setup.jinja file and run the ./scripts/build-setup-files.py script

import os

import setuptools
Expand All @@ -25,15 +28,22 @@
long_description_content_type="text/markdown",
install_requires=["pyautogen==" + __version__],
extras_require={
"test": ["pyautogen[test]==" + __version__],
"blendsearch": ["pyautogen[blendsearch]==" + __version__],
"mathchat": ["pyautogen[mathchat]==" + __version__],
"flaml": ["pyautogen[flaml]==" + __version__],
"jupyter-executor": ["pyautogen[jupyter-executor]==" + __version__],
"retrievechat": ["pyautogen[retrievechat]==" + __version__],
"retrievechat-pgvector": ["pyautogen[retrievechat-pgvector]==" + __version__],
"retrievechat-mongodb": ["pyautogen[retrievechat-mongodb]==" + __version__],
"retrievechat-qdrant": ["pyautogen[retrievechat-qdrant]==" + __version__],
"graph-rag-falkor-db": ["pyautogen[graph-rag-falkor-db]==" + __version__],
"neo4j": ["pyautogen[neo4j]==" + __version__],
"twilio": ["pyautogen[twilio]==" + __version__],
"interop-crewai": ["pyautogen[interop-crewai]==" + __version__],
"interop-langchain": ["pyautogen[interop-langchain]==" + __version__],
"interop-pydantic-ai": ["pyautogen[interop-pydantic-ai]==" + __version__],
"interop": ["pyautogen[interop]==" + __version__],
"autobuild": ["pyautogen[autobuild]==" + __version__],
"blendsearch": ["pyautogen[blendsearch]==" + __version__],
"mathchat": ["pyautogen[mathchat]==" + __version__],
"captainagent": ["pyautogen[captainagent]==" + __version__],
"teachable": ["pyautogen[teachable]==" + __version__],
"lmm": ["pyautogen[lmm]==" + __version__],
Expand All @@ -44,8 +54,6 @@
"redis": ["pyautogen[redis]==" + __version__],
"cosmosdb": ["pyautogen[cosmosdb]==" + __version__],
"websockets": ["pyautogen[websockets]==" + __version__],
"jupyter-executor": ["pyautogen[jupyter-executor]==" + __version__],
"types": ["pyautogen[types]==" + __version__],
"long-context": ["pyautogen[long-context]==" + __version__],
"anthropic": ["pyautogen[anthropic]==" + __version__],
"cerebras": ["pyautogen[cerebras]==" + __version__],
Expand All @@ -54,12 +62,12 @@
"cohere": ["pyautogen[cohere]==" + __version__],
"ollama": ["pyautogen[ollama]==" + __version__],
"bedrock": ["pyautogen[bedrock]==" + __version__],
"twilio": ["pyautogen[twilio]==" + __version__],
"interop-crewai": ["pyautogen[interop-crewai]==" + __version__],
"interop-langchain": ["pyautogen[interop-langchain]==" + __version__],
"interop-pydantic-ai": ["pyautogen[interop-pydantic-ai]==" + __version__],
"interop": ["pyautogen[interop]==" + __version__],
"neo4j": ["pyautogen[neo4j]==" + __version__],
"test": ["pyautogen[test]==" + __version__],
"docs": ["pyautogen[docs]==" + __version__],
"types": ["pyautogen[types]==" + __version__],
"lint": ["pyautogen[lint]==" + __version__],
"dev": ["pyautogen[dev]==" + __version__],

},
url="https://github.com/ag2ai/ag2",
author="Chi Wang & Qingyun Wu",
Expand Down
30 changes: 19 additions & 11 deletions setup_autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#
# SPDX-License-Identifier: Apache-2.0

# this file is autogenerated, please do not edit it directly
# instead, edit the corresponding setup.jinja file and run the ./scripts/build-setup-files.py script

import os

import setuptools
Expand All @@ -25,15 +28,22 @@
long_description_content_type="text/markdown",
install_requires=["pyautogen==" + __version__],
extras_require={
"test": ["pyautogen[test]==" + __version__],
"blendsearch": ["pyautogen[blendsearch]==" + __version__],
"mathchat": ["pyautogen[mathchat]==" + __version__],
"flaml": ["pyautogen[flaml]==" + __version__],
"jupyter-executor": ["pyautogen[jupyter-executor]==" + __version__],
"retrievechat": ["pyautogen[retrievechat]==" + __version__],
"retrievechat-pgvector": ["pyautogen[retrievechat-pgvector]==" + __version__],
"retrievechat-mongodb": ["pyautogen[retrievechat-mongodb]==" + __version__],
"retrievechat-qdrant": ["pyautogen[retrievechat-qdrant]==" + __version__],
"graph-rag-falkor-db": ["pyautogen[graph-rag-falkor-db]==" + __version__],
"neo4j": ["pyautogen[neo4j]==" + __version__],
"twilio": ["pyautogen[twilio]==" + __version__],
"interop-crewai": ["pyautogen[interop-crewai]==" + __version__],
"interop-langchain": ["pyautogen[interop-langchain]==" + __version__],
"interop-pydantic-ai": ["pyautogen[interop-pydantic-ai]==" + __version__],
"interop": ["pyautogen[interop]==" + __version__],
"autobuild": ["pyautogen[autobuild]==" + __version__],
"blendsearch": ["pyautogen[blendsearch]==" + __version__],
"mathchat": ["pyautogen[mathchat]==" + __version__],
"captainagent": ["pyautogen[captainagent]==" + __version__],
"teachable": ["pyautogen[teachable]==" + __version__],
"lmm": ["pyautogen[lmm]==" + __version__],
Expand All @@ -44,8 +54,6 @@
"redis": ["pyautogen[redis]==" + __version__],
"cosmosdb": ["pyautogen[cosmosdb]==" + __version__],
"websockets": ["pyautogen[websockets]==" + __version__],
"jupyter-executor": ["pyautogen[jupyter-executor]==" + __version__],
"types": ["pyautogen[types]==" + __version__],
"long-context": ["pyautogen[long-context]==" + __version__],
"anthropic": ["pyautogen[anthropic]==" + __version__],
"cerebras": ["pyautogen[cerebras]==" + __version__],
Expand All @@ -54,12 +62,12 @@
"cohere": ["pyautogen[cohere]==" + __version__],
"ollama": ["pyautogen[ollama]==" + __version__],
"bedrock": ["pyautogen[bedrock]==" + __version__],
"twilio": ["pyautogen[twilio]==" + __version__],
"interop-crewai": ["pyautogen[interop-crewai]==" + __version__],
"interop-langchain": ["pyautogen[interop-langchain]==" + __version__],
"interop-pydantic-ai": ["pyautogen[interop-pydantic-ai]==" + __version__],
"interop": ["pyautogen[interop]==" + __version__],
"neo4j": ["pyautogen[neo4j]==" + __version__],
"test": ["pyautogen[test]==" + __version__],
"docs": ["pyautogen[docs]==" + __version__],
"types": ["pyautogen[types]==" + __version__],
"lint": ["pyautogen[lint]==" + __version__],
"dev": ["pyautogen[dev]==" + __version__],

},
url="https://github.com/ag2ai/ag2",
author="Chi Wang & Qingyun Wu",
Expand Down
Loading