A programming framework for agentic AI
Migrate build tools to hatch (#93)
Jack Gerrits432b1c121359
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.jsonindex 4244703ae..42f34cc1c 100644--- a/.devcontainer/devcontainer.json+++ b/.devcontainer/devcontainer.json@@ -21,7 +21,8 @@"ghcr.io/devcontainers/features/python:1": {"installTools": true,"version": "latest"- }+ },+ "ghcr.io/devcontainers-contrib/features/hatch:2": {}},// Use 'forwardPorts' to make a list of ports inside the container available locally.// "forwardPorts": [],diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.ymlindex 5f781d060..5383fe846 100644--- a/.github/workflows/checks.yml+++ b/.github/workflows/checks.yml@@ -9,68 +9,53 @@ on:- mainjobs:- lint:+ format:runs-on: ubuntu-latest-steps:- uses: actions/checkout@v4- - uses: actions/setup-python@v5- with:- python-version: '3.10'- - run: pip install ".[dev]"- - run: ruff check+ - name: Install Hatch+ uses: pypa/hatch@install+ - run: hatch run ruff format --check- format:+ lint:runs-on: ubuntu-latest-steps:- uses: actions/checkout@v4- - uses: actions/setup-python@v5- with:- python-version: '3.10'- - run: pip install ".[dev]"- - run: ruff format --check+ - name: Install Hatch+ uses: pypa/hatch@install+ - run: hatch run ruff checkmypy:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- - uses: actions/setup-python@v5- with:- python-version: '3.10'- - run: pip install ".[dev]"- - run: mypy+ - name: Install Hatch+ uses: pypa/hatch@install+ - run: hatch run mypypyright:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- - uses: actions/setup-python@v5- with:- python-version: '3.10'- - run: pip install ".[dev]"- - uses: jakebailey/pyright-action@v2+ - name: Install Hatch+ uses: pypa/hatch@install+ - run: hatch run pyrighttest:runs-on: ubuntu-lateststrategy:matrix:- # "pypy3.10" disabled until better example than polars used in testspython-version: ["3.10", "3.11", "3.12"]steps:- uses: actions/checkout@v4- - uses: actions/setup-python@v5- with:- python-version: ${{ matrix.python-version }}- - run: pip install ".[dev]"- - run: pytest -n auto+ - name: Install Hatch+ uses: pypa/hatch@install+ - run: hatch run +python=${{ matrix.python-version }} test-matrix:pytest -n autodocs:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- - uses: actions/setup-python@v5- with:- python-version: '3.10'- - run: pip install ".[docs]"- - run: sphinx-build --fail-on-warning docs/src docs/build+ - name: Install Hatch+ uses: pypa/hatch@install+ - run: hatch run docs:checkdiff --git a/.github/workflows/docs.yml b/.github/workflows/docs.ymlindex 5b64cef16..333b144c0 100644--- a/.github/workflows/docs.yml+++ b/.github/workflows/docs.yml@@ -30,11 +30,9 @@ jobs:steps:- name: Checkoutuses: actions/checkout@v4- - uses: actions/setup-python@v5- with:- python-version: '3.10'- - run: pip install ".[docs]"- - run: sphinx-build docs/src docs/build+ - name: Install Hatch+ uses: pypa/hatch@install+ - run: hatch run docs:build- name: Upload artifactuses: actions/upload-pages-artifact@v3with:diff --git a/README.md b/README.mdindex bb858fe5c..b818e28fe 100644--- a/README.md+++ b/README.md@@ -14,50 +14,32 @@## Development-### Setup--```sh-python -m venv .venv-source .venv/bin/activate--pip install -e ".[dev]"-```--### Running tests--```sh-pytest-```--### Type checking+**TL;DR**, run all checks with:```sh-mypy+hatch run check```-```sh-pyright-```+### Setup-### Linting+- [Install `hatch`](https://hatch.pypa.io/1.12/install/).-```sh-ruff check-```--### Formatting+### Virtual environment+To get a shell with the package available (virtual environment) run:```sh-ruff format+hatch shell```-### Build docs--```sh-pip install -e ".[docs]"+### Common tasks-sphinx-build docs/src docs/build+- Format: `hatch run check`+- Lint: `hatch run lint`+- Test: `hatch run pytest -n auto`+- Mypy: `hatch run mypy`+- Pyright: `hatch run pyright`+- Build docs: `hatch run docs:build`+- Auto rebuild+serve docs: `hatch run docs:serve`-# To view the docs:-python -m http.server -d docs/build-```+> [!NOTE]+> These don't need to be run in a virtual environment, `hatch` will automatically manage it for you.diff --git a/examples/README.md b/examples/README.mdindex f218fa356..83e8640ce 100644--- a/examples/README.md+++ b/examples/README.md@@ -2,23 +2,28 @@This directory contains examples of how to use AGNext.-First, you need to install AGNext and development dependencies by running the-following command:+First, you need a shell with AGNext and the examples dependencies installed. To do this, run:```bash-pip install -e '.[dev]'+hatch shell```To run an example, just run the corresponding Python script. For example, to run the `coder_reviewer.py` example, run:```bash+hatch shellpython coder_reviewer.py```+Or simply:+```bash+hatch run python coder_reviewer.py+```+To enable logging, turn on verbose mode by setting `--verbose` flag:```bash-python coder_reviewer.py --verbose+hatch run python coder_reviewer.py --verbose```By default the log file is saved in the same directory with the same filenamediff --git a/pyproject.toml b/pyproject.tomlindex 8abfc9d30..752408f3b 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -1,6 +1,6 @@[build-system]-requires = ["setuptools>=61.0"]-build-backend = "setuptools.build_meta"+requires = ["hatchling"]+build-backend = "hatchling.build"[project]name = "agnext"@@ -21,29 +21,54 @@ dependencies = ["pydantic>=1.10,<3",]-[project.optional-dependencies]-dev = [- "ruff==0.4.6",- "pyright",- "mypy",- "pytest",- "pytest-asyncio",- "pytest-xdist",+[tool.hatch.envs.default]+dependencies = [+ "pyright==1.1.368",+ "mypy==1.10.0",+ "ruff==0.4.8","types-Pillow","polars",- # Dependencies for the examples."chess","tavily-python","aiofiles","types-aiofiles","colorama","textual",+ "textual-dev","textual-imageview",+ "pytest-asyncio",+ "pip",+ "pytest",+ "pytest-xdist",+]++[tool.hatch.envs.default.scripts]+fmt = "ruff format"+lint = "ruff check"+test = "pytest -n auto"+check = [+ "ruff format",+ "ruff check --fix",+ "pyright",+ "mypy",+ "pytest -n auto",+]++[tool.hatch.envs.test-matrix]+template = "default"++[[tool.hatch.envs.test-matrix.matrix]]+python = ["3.10", "3.11", "3.12"]++[tool.hatch.envs.docs]+dependencies = [+ "sphinx", "furo", "sphinxcontrib-apidoc", "myst-parser", "sphinx-autobuild"]-docs = ["sphinx", "furo", "sphinxcontrib-apidoc", "myst-parser"]-[tool.setuptools.package-data]-agnext = ["py.typed"]+[tool.hatch.envs.docs.scripts]+build = "sphinx-build docs/src docs/build"+serve = "sphinx-autobuild --watch src docs/src docs/build"+check = "sphinx-build --fail-on-warning docs/src docs/build"[tool.ruff]line-length = 120diff --git a/src/agnext/application/_single_threaded_agent_runtime.py b/src/agnext/application/_single_threaded_agent_runtime.pyindex 9be306026..6a59d21c2 100644--- a/src/agnext/application/_single_threaded_agent_runtime.py+++ b/src/agnext/application/_single_threaded_agent_runtime.py@@ -121,7 +121,6 @@ class SingleThreadedAgentRuntime(AgentRuntime):# )# )-future = asyncio.get_event_loop().create_future()if recipient.name not in self._known_agent_names:future.set_exception(Exception("Recipient not found"))@@ -182,7 +181,6 @@ class SingleThreadedAgentRuntime(AgentRuntime):namespace = cast(str, explicit_namespace or sender_namespace)self._process_seen_namespace(namespace)-self._message_queue.append(PublishMessageEnvelope(message=message,diff --git a/src/agnext/components/_function_utils.py b/src/agnext/components/_function_utils.pyindex 4628ae57a..d541411d4 100644--- a/src/agnext/components/_function_utils.py+++ b/src/agnext/components/_function_utils.py@@ -248,7 +248,11 @@ def get_function_schema(f: Callable[..., Any], *, name: Optional[str] = None, de.. code-block:: python- def f(a: Annotated[str, "Parameter a"], b: int = 2, c: Annotated[float, "Parameter c"] = 0.1) -> None:+ def f(+ a: Annotated[str, "Parameter a"],+ b: int = 2,+ c: Annotated[float, "Parameter c"] = 0.1,+ ) -> None:passdiff --git a/src/agnext/py.typed b/src/agnext/py.typednew file mode 100644index 000000000..e69de29bbdiff --git a/test.sh b/test.shdeleted file mode 100755index 9236c93ff..000000000--- a/test.sh+++ /dev/null@@ -1,23 +0,0 @@-set -e--# Current script directory-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"--if [[ "$VIRTUAL_ENV" == "" ]]-then- echo "Virtual environment is not activated"- exit 1-fi--cd $DIR--echo "--- Running ruff format ---"-ruff format-echo "--- Running ruff check ---"-ruff check-echo "--- Running pyright ---"-pyright-echo "--- Running mypy ---"-mypy-echo "--- Running pytest ---"-pytest -n auto\ No newline at end of file