From ec459edc92bf501723bec39ecd2439b5d4ad17dd Mon Sep 17 00:00:00 2001 From: Mattt Date: Fri, 28 Jun 2024 06:18:56 -0700 Subject: [PATCH] Use rye for package management (#284) Alternative to #283 --------- Signed-off-by: Mattt Zmuda --- .github/workflows/ci.yaml | 7 ++- .python-version | 1 + pyproject.toml | 20 +++++---- replicate/__about__.py | 2 +- replicate/prediction.py | 3 +- requirements-dev.lock | 81 ++++++++++++++++++++++++++++++++++ requirements-dev.txt | 93 --------------------------------------- requirements.lock | 39 ++++++++++++++++ requirements.txt | 40 ----------------- script/format | 4 +- script/lint | 12 ++--- script/setup | 29 ++++++++++-- script/test | 4 +- 13 files changed, 173 insertions(+), 162 deletions(-) create mode 100644 .python-version create mode 100644 requirements-dev.lock delete mode 100644 requirements-dev.txt create mode 100644 requirements.lock delete mode 100644 requirements.txt diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index acfb932b..663fd4e7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -28,11 +28,10 @@ jobs: shell: bash steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/checkout@v4 + - uses: eifinger/setup-rye@v2 with: - python-version: ${{ matrix.python-version }} - cache: "pip" + enable-cache: true - name: Setup run: ./script/setup diff --git a/.python-version b/.python-version new file mode 100644 index 00000000..8531a3b7 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.12.2 diff --git a/pyproject.toml b/pyproject.toml index b6795d86..97c7c26c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,20 +16,22 @@ dependencies = [ "pydantic>1.10.7", "typing_extensions>=4.5.0", ] -optional-dependencies = { dev = [ - "pylint", - "pyright", - "pytest", - "pytest-asyncio", - "pytest-recording", - "respx", - "ruff>=0.3.3", -] } [project.urls] homepage = "https://replicate.com" repository = "https://github.com/replicate/replicate-python" +[tool] +rye = { dev-dependencies = [ + "pytest>=8.1.1", + "pylint>=3.1.0", + "pyright>=1.1.358", + "pytest-asyncio>=0.23.6", + "pytest-recording>=0.13.1", + "respx>=0.21.1", + "ruff>=0.3.7", +] } + [tool.pytest.ini_options] testpaths = "tests/" diff --git a/replicate/__about__.py b/replicate/__about__.py index 5f3c0243..12be9455 100644 --- a/replicate/__about__.py +++ b/replicate/__about__.py @@ -1,3 +1,3 @@ from importlib.metadata import version -__version__ = version(__package__) +__version__ = version(__package__ if __package__ is not None else "replicate") diff --git a/replicate/prediction.py b/replicate/prediction.py index b1825c30..871566d7 100644 --- a/replicate/prediction.py +++ b/replicate/prediction.py @@ -253,8 +253,7 @@ def output_iterator(self) -> Iterator[Any]: output = self.output or [] new_output = output[len(previous_output) :] - for output in new_output: - yield output + yield from new_output async def async_output_iterator(self) -> AsyncIterator[Any]: """ diff --git a/requirements-dev.lock b/requirements-dev.lock new file mode 100644 index 00000000..3eae4db9 --- /dev/null +++ b/requirements-dev.lock @@ -0,0 +1,81 @@ +# generated by rye +# use `rye lock` or `rye sync` to update this lockfile +# +# last locked with the following flags: +# pre: false +# features: [] +# all-features: false +# with-sources: false + +-e file:. +annotated-types==0.6.0 + # via pydantic +anyio==4.3.0 + # via httpx +astroid==3.1.0 + # via pylint +certifi==2024.2.2 + # via httpcore + # via httpx +dill==0.3.8 + # via pylint +h11==0.14.0 + # via httpcore +httpcore==1.0.5 + # via httpx +httpx==0.27.0 + # via replicate + # via respx +idna==3.7 + # via anyio + # via httpx + # via yarl +iniconfig==2.0.0 + # via pytest +isort==5.13.2 + # via pylint +mccabe==0.7.0 + # via pylint +multidict==6.0.5 + # via yarl +nodeenv==1.8.0 + # via pyright +packaging==24.0 + # via pytest + # via replicate +platformdirs==4.2.0 + # via pylint +pluggy==1.4.0 + # via pytest +pydantic==2.7.0 + # via replicate +pydantic-core==2.18.1 + # via pydantic +pylint==3.1.0 +pyright==1.1.358 +pytest==8.1.1 + # via pytest-asyncio + # via pytest-recording +pytest-asyncio==0.23.6 +pytest-recording==0.13.1 +pyyaml==6.0.1 + # via vcrpy +respx==0.21.1 +ruff==0.3.7 +setuptools==69.2.0 + # via nodeenv +sniffio==1.3.1 + # via anyio + # via httpx +tomlkit==0.12.4 + # via pylint +typing-extensions==4.11.0 + # via pydantic + # via pydantic-core + # via replicate +vcrpy==6.0.1 + # via pytest-recording +wrapt==1.16.0 + # via vcrpy +yarl==1.9.4 + # via vcrpy diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index f14ac1ad..00000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,93 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.12 -# by the following command: -# -# pip-compile --extra=dev --output-file=requirements-dev.txt pyproject.toml -# -annotated-types==0.5.0 - # via pydantic -anyio==3.7.1 - # via httpcore -astroid==3.0.1 - # via pylint -certifi==2023.7.22 - # via - # httpcore - # httpx -dill==0.3.7 - # via pylint -h11==0.14.0 - # via httpcore -httpcore==0.17.3 - # via httpx -httpx==0.24.1 - # via - # replicate (pyproject.toml) - # respx -idna==3.4 - # via - # anyio - # httpx - # yarl -iniconfig==2.0.0 - # via pytest -isort==5.12.0 - # via pylint -mccabe==0.7.0 - # via pylint -multidict==6.0.4 - # via yarl -nodeenv==1.8.0 - # via pyright -packaging==23.1 - # via - # pytest - # replicate (pyproject.toml) -platformdirs==3.11.0 - # via pylint -pluggy==1.2.0 - # via pytest -pydantic==2.0.3 - # via replicate (pyproject.toml) -pydantic-core==2.3.0 - # via pydantic -pylint==3.0.2 - # via replicate (pyproject.toml) -pyright==1.1.337 - # via replicate (pyproject.toml) -pytest==7.4.0 - # via - # pytest-asyncio - # pytest-recording - # replicate (pyproject.toml) -pytest-asyncio==0.21.1 - # via replicate (pyproject.toml) -pytest-recording==0.13.0 - # via replicate (pyproject.toml) -pyyaml==6.0.1 - # via vcrpy -respx==0.20.2 - # via replicate (pyproject.toml) -ruff==0.3.3 - # via replicate (pyproject.toml) -sniffio==1.3.0 - # via - # anyio - # httpcore - # httpx -tomlkit==0.12.1 - # via pylint -typing-extensions==4.7.1 - # via - # pydantic - # pydantic-core - # replicate (pyproject.toml) -vcrpy==5.1.0 - # via pytest-recording -wrapt==1.15.0 - # via vcrpy -yarl==1.9.2 - # via vcrpy - -# The following packages are considered to be unsafe in a requirements file: -# setuptools diff --git a/requirements.lock b/requirements.lock new file mode 100644 index 00000000..53ab3f58 --- /dev/null +++ b/requirements.lock @@ -0,0 +1,39 @@ +# generated by rye +# use `rye lock` or `rye sync` to update this lockfile +# +# last locked with the following flags: +# pre: false +# features: [] +# all-features: false +# with-sources: false + +-e file:. +annotated-types==0.6.0 + # via pydantic +anyio==4.3.0 + # via httpx +certifi==2024.2.2 + # via httpcore + # via httpx +h11==0.14.0 + # via httpcore +httpcore==1.0.5 + # via httpx +httpx==0.27.0 + # via replicate +idna==3.7 + # via anyio + # via httpx +packaging==24.0 + # via replicate +pydantic==2.7.0 + # via replicate +pydantic-core==2.18.1 + # via pydantic +sniffio==1.3.1 + # via anyio + # via httpx +typing-extensions==4.11.0 + # via pydantic + # via pydantic-core + # via replicate diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 21ec722f..00000000 --- a/requirements.txt +++ /dev/null @@ -1,40 +0,0 @@ -# -# This file is autogenerated by pip-compile with Python 3.11 -# by the following command: -# -# pip-compile --output-file=requirements.txt --resolver=backtracking pyproject.toml -# -annotated-types==0.5.0 - # via pydantic -anyio==3.7.1 - # via httpcore -certifi==2023.7.22 - # via - # httpcore - # httpx -h11==0.14.0 - # via httpcore -httpcore==0.17.3 - # via httpx -httpx==0.24.1 - # via replicate (pyproject.toml) -idna==3.4 - # via - # anyio - # httpx -packaging==23.1 - # via replicate (pyproject.toml) -pydantic==2.0.3 - # via replicate (pyproject.toml) -pydantic-core==2.3.0 - # via pydantic -sniffio==1.3.0 - # via - # anyio - # httpcore - # httpx -typing-extensions==4.7.1 - # via - # pydantic - # pydantic-core - # replicate (pyproject.toml) diff --git a/script/format b/script/format index 2cc38a42..2ebd5e10 100755 --- a/script/format +++ b/script/format @@ -1,5 +1,5 @@ -#!/bin/bash +#!/bin/sh set -e -python -m ruff format . +exec rye fmt . diff --git a/script/lint b/script/lint index e25ada22..5bd8bb36 100755 --- a/script/lint +++ b/script/lint @@ -5,19 +5,19 @@ set -e STATUS=0 echo "Running pyright" -python -m pyright replicate || STATUS=$? +rye run pyright replicate || STATUS=$? echo "" echo "Running pylint" -python -m pylint --exit-zero replicate || STATUS=$? +rye run pylint --exit-zero replicate || STATUS=$? echo "" -echo "Running ruff check" -python -m ruff check . || STATUS=$? +echo "Running rye lint" +rye lint . || STATUS=$? echo "" -echo "Running ruff format check" -python -m ruff format --check . || STATUS=$? +echo "Running rye fmt --check" +rye fmt --check || STATUS=$? echo "" exit $STATUS diff --git a/script/setup b/script/setup index a7b5a48b..360307a6 100755 --- a/script/setup +++ b/script/setup @@ -1,5 +1,28 @@ -#!/bin/bash +#!/bin/sh -set -e +set -eu -python -m pip install -r requirements.txt -r requirements-dev.txt . +: "${RYE_INSTALL_OPTION:='--yes'}" +: "${RYE_VERSION:='latest'}" + +if ! command -v rye > /dev/null 2>&1 +then + echo "rye is not installed." + printf "Do you want to install rye? (y/n) " + read -r REPLY + echo # move to a new line + case "$REPLY" in + [yY]) + echo "Installing rye..." + curl -sSf https://rye-up.com/get | sh + echo "rye has been successfully installed." + ;; + *) + exit 1 + ;; + esac +else + echo "rye is already installed." +fi + +exec rye sync diff --git a/script/test b/script/test index df1e5d9d..167c3001 100755 --- a/script/test +++ b/script/test @@ -1,5 +1,5 @@ -#!/bin/bash +#!/bin/sh set -e -python -m pytest -v +exec rye test -v