Skip to content

Commit a5f59a0

Browse files
committed
chore(internal): migrate from Poetry to Rye (anthropics#194)
1 parent cd93ef0 commit a5f59a0

11 files changed

+171
-1496
lines changed

.github/workflows/create-releases.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ jobs:
2020
repo: ${{ github.event.repository.full_name }}
2121
stainless-api-key: ${{ secrets.STAINLESS_API_KEY }}
2222

23-
- name: Set up Python
23+
- name: Install Rye
2424
if: ${{ steps.release.outputs.releases_created }}
25-
uses: actions/setup-python@v4
26-
with:
27-
python-version: '3.7'
25+
run: |
26+
curl -sSf https://rye-up.com/get | bash
27+
echo "$HOME/.rye/shims" >> $GITHUB_PATH
28+
env:
29+
RYE_VERSION: 0.15.2
30+
RYE_INSTALL_OPTION: "--yes"
2831

2932
- name: Publish to PyPI
3033
if: ${{ steps.release.outputs.releases_created }}
3134
run: |
32-
pipx install poetry
3335
bash ./bin/publish-pypi
3436
env:
3537
PYPI_TOKEN: ${{ secrets.ANTHROPIC_PYPI_TOKEN }}

.github/workflows/publish-pypi.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v3
1414

15-
- name: Set up Python
16-
uses: actions/setup-python@v4
17-
with:
18-
python-version: '3.7'
15+
- name: Install Rye
16+
run: |
17+
curl -sSf https://rye-up.com/get | bash
18+
echo "$HOME/.rye/shims" >> $GITHUB_PATH
19+
env:
20+
RYE_VERSION: 0.15.2
21+
RYE_INSTALL_OPTION: "--yes"
1922

2023
- name: Publish to PyPI
2124
run: |
22-
pipx install poetry
2325
bash ./bin/publish-pypi
2426
env:
2527
PYPI_TOKEN: ${{ secrets.ANTHROPIC_PYPI_TOKEN }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ __pycache__
66

77
dist
88

9+
.venv
10+
911
.env
1012
codegen.log

bin/publish-pypi

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22

33
set -eux
4-
poetry config pypi-token.pypi $PYPI_TOKEN
5-
poetry publish --build
4+
mkdir dist
5+
rye build --clean
6+
rye publish --yes --token=$PYPI_TOKEN

bin/test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22

3-
bin/check-test-server && poetry run pytest "$@"
3+
bin/check-test-server && rye run pytest "$@"

noxfile.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import nox
2-
import nox_poetry
32

43

5-
@nox_poetry.session(reuse_venv=True, name="test-pydantic-v1")
4+
@nox.session(reuse_venv=True, name="test-pydantic-v1")
65
def test_pydantic_v1(session: nox.Session) -> None:
7-
session.run_always("poetry", "install", external=True)
8-
9-
# https://github.com/cjolowicz/nox-poetry/issues/1116
10-
session._session.run("python", "-m", "pip", "install", "pydantic<2", external=True) # type: ignore
6+
session.install("-r", "requirements-dev.lock")
7+
session.install("pydantic<2")
118

129
session.run("pytest", "--showlocals", "--ignore=tests/functional", *session.posargs)

poetry.lock

-1,448
This file was deleted.

pyproject.toml

+53-27
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,69 @@
1-
[tool.poetry]
1+
[project]
22
name = "anthropic"
33
version = "0.4.1"
44
description = "Client library for the anthropic API"
55
readme = "README.md"
6-
authors = ["Anthropic <[email protected]>"]
76
license = "MIT"
8-
repository = "https://github.com/anthropics/anthropic-sdk-python"
9-
packages = [
10-
{ include = "anthropic", from = "src" }
7+
authors = [
8+
{ name = "Anthropic", email = "[email protected]" },
119
]
10+
dependencies = [
11+
"httpx>=0.23.0, <1",
12+
"pydantic>=1.9.0, <3",
13+
"typing-extensions>=4.5, <5",
14+
"anyio>=3.5.0, <4",
15+
"distro>=1.7.0, <2",
16+
"tokenizers >= 0.13.0"
17+
]
18+
requires-python = ">= 3.7"
19+
1220

13-
[tool.poetry.dependencies]
14-
python = "^3.7"
15-
httpx = ">= 0.23.0, < 1"
16-
pydantic = ">= 1.9.0, < 3"
17-
typing-extensions = ">= 4.5, < 5"
18-
anyio = ">= 3.5.0, < 4"
19-
distro = ">= 1.7.0, < 2"
20-
tokenizers = ">= 0.13.0"
2121

22+
[project.urls]
23+
Homepage = "https://github.com/anthropics/anthropic-sdk-python"
24+
Repository = "https://github.com/anthropics/anthropic-sdk-python"
2225

23-
[tool.poetry.group.dev.dependencies]
24-
pyright = "1.1.326"
25-
mypy = "1.4.1"
26-
black = "23.3.0"
27-
respx = "0.19.2"
28-
pytest = "7.1.1"
29-
pytest-asyncio = "0.21.1"
30-
ruff = "0.0.282"
31-
isort = "5.10.1"
32-
time-machine = "^2.9.0"
33-
nox = "^2023.4.22"
34-
nox-poetry = "^1.0.3"
3526

3627

28+
[tool.rye]
29+
managed = true
30+
dev-dependencies = [
31+
"pyright==1.1.326",
32+
"mypy==1.4.1",
33+
"black==23.3.0",
34+
"respx==0.19.2",
35+
"pytest==7.1.1",
36+
"pytest-asyncio==0.21.1",
37+
"ruff==0.0.282",
38+
"isort==5.10.1",
39+
"time-machine==2.9.0",
40+
"nox==2023.4.22",
41+
42+
]
43+
44+
[tool.rye.scripts]
45+
format = { chain = [
46+
"format:black",
47+
"format:docs",
48+
"format:ruff",
49+
"format:isort",
50+
]}
51+
"format:black" = "black ."
52+
"format:docs" = "python bin/blacken-docs.py README.md api.md"
53+
"format:ruff" = "ruff --fix ."
54+
"format:isort" = "isort ."
3755

3856
[build-system]
39-
requires = ["poetry-core>=1.0.0"]
40-
build-backend = "poetry.core.masonry.api"
57+
requires = ["hatchling"]
58+
build-backend = "hatchling.build"
59+
60+
[tool.hatch.build]
61+
include = [
62+
"src/*"
63+
]
64+
65+
[tool.hatch.build.targets.wheel]
66+
packages = ["src/anthropic"]
4167

4268
[tool.black]
4369
line-length = 120

requirements-dev.lock

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# generated by rye
2+
# use `rye lock` or `rye sync` to update this lockfile
3+
#
4+
# last locked with the following flags:
5+
# pre: false
6+
# features: []
7+
# all-features: true
8+
9+
-e file:.
10+
annotated-types==0.6.0
11+
anyio==3.7.1
12+
argcomplete==3.1.2
13+
attrs==23.1.0
14+
black==23.3.0
15+
certifi==2023.7.22
16+
charset-normalizer==3.3.0
17+
click==8.1.7
18+
colorlog==6.7.0
19+
distlib==0.3.7
20+
distro==1.8.0
21+
exceptiongroup==1.1.3
22+
filelock==3.12.4
23+
fsspec==2023.9.2
24+
h11==0.12.0
25+
httpcore==0.15.0
26+
httpx==0.23.0
27+
huggingface-hub==0.16.4
28+
idna==3.4
29+
iniconfig==2.0.0
30+
isort==5.10.1
31+
mypy==1.4.1
32+
mypy-extensions==1.0.0
33+
nodeenv==1.8.0
34+
nox==2023.4.22
35+
packaging==23.2
36+
pathspec==0.11.2
37+
platformdirs==3.11.0
38+
pluggy==1.3.0
39+
py==1.11.0
40+
pydantic==2.4.2
41+
pydantic-core==2.10.1
42+
pyright==1.1.326
43+
pytest==7.1.1
44+
pytest-asyncio==0.21.1
45+
python-dateutil==2.8.2
46+
pyyaml==6.0.1
47+
requests==2.31.0
48+
respx==0.19.2
49+
rfc3986==1.5.0
50+
ruff==0.0.282
51+
six==1.16.0
52+
sniffio==1.3.0
53+
time-machine==2.9.0
54+
tokenizers==0.14.0
55+
tomli==2.0.1
56+
tqdm==4.66.1
57+
typing-extensions==4.8.0
58+
urllib3==2.0.6
59+
virtualenv==20.24.5
60+
# The following packages are considered to be unsafe in a requirements file:
61+
setuptools==68.2.2

requirements.lock

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# generated by rye
2+
# use `rye lock` or `rye sync` to update this lockfile
3+
#
4+
# last locked with the following flags:
5+
# pre: false
6+
# features: []
7+
# all-features: true
8+
9+
-e file:.
10+
annotated-types==0.6.0
11+
anyio==3.7.1
12+
certifi==2023.7.22
13+
charset-normalizer==3.3.0
14+
distro==1.8.0
15+
exceptiongroup==1.1.3
16+
filelock==3.12.4
17+
fsspec==2023.9.2
18+
h11==0.12.0
19+
httpcore==0.15.0
20+
httpx==0.23.0
21+
huggingface-hub==0.16.4
22+
idna==3.4
23+
packaging==23.2
24+
pydantic==2.4.2
25+
pydantic-core==2.10.1
26+
pyyaml==6.0.1
27+
requests==2.31.0
28+
rfc3986==1.5.0
29+
sniffio==1.3.0
30+
tokenizers==0.14.0
31+
tqdm==4.66.1
32+
typing-extensions==4.8.0
33+
urllib3==2.0.6

src/anthropic/_models.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import pydantic
99
import pydantic.generics
10-
from pydantic import Extra
1110
from pydantic.fields import FieldInfo
1211

1312
from ._types import (
@@ -56,7 +55,7 @@ def model_fields_set(self) -> set[str]:
5655
return self.__fields_set__ # type: ignore
5756

5857
class Config(pydantic.BaseConfig): # pyright: ignore[reportDeprecated]
59-
extra: Any = Extra.allow # type: ignore
58+
extra: Any = pydantic.Extra.allow # type: ignore
6059

6160
def __str__(self) -> str:
6261
# mypy complains about an invalid self arg

0 commit comments

Comments
 (0)