Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/python/typeshed into bump-t…
Browse files Browse the repository at this point in the history
…ensorflow-to-2.16.1
  • Loading branch information
Avasam committed Apr 21, 2024
2 parents f716ff6 + 1017c52 commit 0109400
Show file tree
Hide file tree
Showing 37 changed files with 911 additions and 988 deletions.
8 changes: 4 additions & 4 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"dependencyDashboard": true,
"suppressNotifications": ["prEditedNotification"],
"extends": ["config:base"],
"extends": ["config:recommended"],
"labels": ["bot: dependencies"],
"semanticCommits": "disabled",
"separateMajorMinor": false,
"prHourlyLimit": 10,
"pre-commit": {
"enabled": true
},
Expand All @@ -12,23 +15,20 @@
"groupName": "GitHub Actions",
"matchManagers": ["github-actions"],
"description": "Quarterly update of GitHub Action dependencies",
"separateMajorMinor": "false",
"schedule": ["every 3 months on the first day of the month"]
},
{
"groupName": "most test/lint dependencies",
"matchManagers": ["pip_requirements", "pre-commit"],
"excludePackageNames": ["pytype", "pyright"],
"description": "Quarterly update of most test dependencies",
"separateMajorMinor": "false",
"schedule": ["every 3 months on the first day of the month"]
},
{
"groupName": "pytype and pyright",
"matchManagers": ["pip_requirements"],
"matchPackageNames": ["pytype", "pyright"],
"description": "Daily update of pyright and pytype",
"separateMajorMinor": "false",
"schedule": ["before 4am"]
}
]
Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ jobs:
- run: uv pip install -r requirements-tests.txt --system
- run: python ./tests/check_typeshed_structure.py

new-syntax:
name: Ensure new syntax usage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: ./tests/check_new_syntax.py

pytype:
name: Run pytype against the stubs
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repos:
- id: flake8
additional_dependencies:
- "flake8-noqa==1.4.0" # must match requirements-tests.txt
- "flake8-pyi==24.4.0" # must match requirements-tests.txt
- "flake8-pyi==24.4.1" # must match requirements-tests.txt
types: [file]
types_or: [python, pyi]
- repo: meta
Expand Down
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
black==24.3.0 # must match .pre-commit-config.yaml
flake8==7.0.0 # must match .pre-commit-config.yaml
flake8-noqa==1.4.0 # must match .pre-commit-config.yaml
flake8-pyi==24.4.0 # must match .pre-commit-config.yaml
flake8-pyi==24.4.1 # must match .pre-commit-config.yaml
mypy==1.9.0
pre-commit-hooks==4.5.0 # must match .pre-commit-config.yaml
pyright==1.1.358
Expand Down
32 changes: 12 additions & 20 deletions scripts/generate_proto_stubs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,25 @@ set -ex -o pipefail
PROTOBUF_VERSION=26.1
MYPY_PROTOBUF_VERSION=3.6.0

if uname -a | grep Darwin; then
# brew install coreutils wget
PLAT=osx
else
# sudo apt install -y unzip
PLAT=linux
fi
# brew install coreutils wget
# sudo apt install -y unzip
REPO_ROOT="$(realpath "$(dirname "${BASH_SOURCE[0]}")"/..)"
TMP_DIR="$(mktemp -d)"
PYTHON_PROTOBUF_FILENAME="protobuf-$PROTOBUF_VERSION.zip"
PROTOC_FILENAME="protoc-$PROTOBUF_VERSION-$PLAT-x86_64.zip"
PROTOC_URL="https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/$PROTOC_FILENAME"
PYTHON_PROTOBUF_URL="https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/$PYTHON_PROTOBUF_FILENAME"
PYTHON_PROTOBUF_DIR="protobuf-$PROTOBUF_VERSION"

cd "$TMP_DIR"
echo "Working in $TMP_DIR"

# Install protoc
wget "$PROTOC_URL"
mkdir protoc_install
unzip "$PROTOC_FILENAME" -d protoc_install
protoc_install/bin/protoc --version

# Fetch protoc-python (which contains all the .proto files)
wget "$PYTHON_PROTOBUF_URL"
unzip "$PYTHON_PROTOBUF_FILENAME"
PYTHON_PROTOBUF_DIR="protobuf-$PROTOBUF_VERSION"

# Prepare virtualenv
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install pre-commit mypy-protobuf=="$MYPY_PROTOBUF_VERSION"
python3 -m pip install grpcio-tools pre-commit mypy-protobuf=="$MYPY_PROTOBUF_VERSION"

# Remove existing pyi
find "$REPO_ROOT/stubs/protobuf/" -name '*_pb2.pyi' -delete
Expand All @@ -62,8 +49,9 @@ PROTO_FILES=$(grep '"//:.*_proto"' $PYTHON_PROTOBUF_DIR/python/dist/BUILD.bazel
)

# And regenerate!
# shellcheck disable=SC2086
protoc_install/bin/protoc \
PROTOC_VERSION=$(python3 -m grpc_tools.protoc --version)
echo $PROTOC_VERSION
python3 -m grpc_tools.protoc \
--proto_path="$PYTHON_PROTOBUF_DIR/src" \
--mypy_out="relax_strict_optional_primitives:$REPO_ROOT/stubs/protobuf" \
$PROTO_FILES
Expand All @@ -76,7 +64,11 @@ rm -rf "$TMP_DIR"
cd "$REPO_ROOT"

sed --in-place="" \
"s/extra_description = .*$/extra_description = \"Generated using [mypy-protobuf==$MYPY_PROTOBUF_VERSION](https:\/\/github.com\/nipunn1313\/mypy-protobuf\/tree\/v$MYPY_PROTOBUF_VERSION) on [protobuf v$PROTOBUF_VERSION](https:\/\/github.com\/protocolbuffers\/protobuf\/releases\/tag\/v$PROTOBUF_VERSION) (python protobuf==$PYTHON_PROTOBUF_VERSION)\"/" \
"s/extra_description = .*$/extra_description = \"\
Partially generated using [mypy-protobuf==$MYPY_PROTOBUF_VERSION](https:\/\/github.com\/nipunn1313\/mypy-protobuf\/tree\/v$MYPY_PROTOBUF_VERSION) \
and $PROTOC_VERSION \
on [protobuf v$PROTOBUF_VERSION](https:\/\/github.com\/protocolbuffers\/protobuf\/releases\/tag\/v$PROTOBUF_VERSION) \
(python protobuf==$PYTHON_PROTOBUF_VERSION).\"/" \
stubs/protobuf/METADATA.toml

# use `|| true` so the script still continues even if a pre-commit hook
Expand Down
4 changes: 0 additions & 4 deletions scripts/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ def main() -> None:

print("\nRunning check_typeshed_structure.py...")
check_structure_result = subprocess.run([sys.executable, "tests/check_typeshed_structure.py"])
print("\nRunning check_new_syntax.py...")
check_new_syntax_result = subprocess.run([sys.executable, "tests/check_new_syntax.py"])

strict_params = _get_strict_params(path)
print(f"\nRunning Pyright ({'stricter' if strict_params else 'base' } configs) for Python {python_version}...")
Expand Down Expand Up @@ -180,7 +178,6 @@ def main() -> None:
[
pre_commit_result.returncode,
check_structure_result.returncode,
check_new_syntax_result.returncode,
pyright_returncode,
mypy_result.returncode,
getattr(stubtest_result, "returncode", 0),
Expand All @@ -207,7 +204,6 @@ def main() -> None:
that the autofixes did sensible things."""
)
print("Check structure:", _SUCCESS if check_structure_result.returncode == 0 else _FAILED)
print("Check new syntax:", _SUCCESS if check_new_syntax_result.returncode == 0 else _FAILED)
if pyright_skipped:
print("Pyright:", _SKIPPED)
else:
Expand Down
2 changes: 1 addition & 1 deletion scripts/stubsabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ async def determine_action(stub_path: Path, session: aiohttp.ClientSession) -> U
"Release": f"{pypi_info.pypi_root}/{relevant_version}",
"Homepage": project_urls.get("Homepage"),
"Repository": stub_info.upstream_repository,
"Typeshed stubs": f"https://github.com/{TYPESHED_OWNER}/typeshed/tree/main/{stub_info.distribution}",
"Typeshed stubs": f"https://github.com/{TYPESHED_OWNER}/typeshed/tree/main/stubs/{stub_info.distribution}",
"Changelog": project_urls.get("Changelog") or project_urls.get("Changes") or project_urls.get("Change Log"),
}
links = {k: v for k, v in maybe_links.items() if v is not None}
Expand Down
31 changes: 11 additions & 20 deletions scripts/sync_tensorflow_protobuf_stubs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,30 @@

set -euxo pipefail

# Need protoc >= 3.15 for explicit optional
PROTOBUF_VERSION=25.3 # 4.25.3
# Whenever you update TENSORFLOW_VERSION here, version should be updated
# in stubs/tensorflow/METADATA.toml and vice-versa.
TENSORFLOW_VERSION=2.16.1
MYPY_PROTOBUF_VERSION=3.6.0

if uname -a | grep Darwin; then
# brew install coreutils wget
PLAT=osx
else
PLAT=linux
fi
# brew install coreutils wget
# sudo apt install -y unzip
REPO_ROOT="$(realpath "$(dirname "${BASH_SOURCE[0]}")"/..)"
TMP_DIR="$(mktemp -d)"
TENSORFLOW_FILENAME="v$TENSORFLOW_VERSION.zip"
PROTOC_FILENAME="protoc-$PROTOBUF_VERSION-$PLAT-x86_64.zip"
PROTOC_URL="https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOBUF_VERSION/$PROTOC_FILENAME"
TENSORFLOW_URL="https://github.com/tensorflow/tensorflow/archive/refs/tags/$TENSORFLOW_FILENAME"
TENSORFLOW_DIR="tensorflow-$TENSORFLOW_VERSION"

cd "$TMP_DIR"
echo "Working in $TMP_DIR"

# Install protoc
wget "$PROTOC_URL"
mkdir protoc_install
unzip "$PROTOC_FILENAME" -d protoc_install
protoc_install/bin/protoc --version

# Fetch tensorflow (which contains all the .proto files)
wget "$TENSORFLOW_URL"
unzip "$TENSORFLOW_FILENAME"
TENSORFLOW_DIR="tensorflow-$TENSORFLOW_VERSION"

# Prepare virtualenv
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install pre-commit mypy-protobuf=="$MYPY_PROTOBUF_VERSION"
python3 -m pip install grpcio-tools pre-commit mypy-protobuf=="$MYPY_PROTOBUF_VERSION"

# Empty target folders or the mv command below will fail
rm -rf "$REPO_ROOT/stubs/tensorflow/tensorflow/tsl/"
Expand All @@ -52,7 +38,9 @@ find "$REPO_ROOT/stubs/tensorflow/" -name "*_pb2.pyi" -delete

# Folders here cover the more commonly used protobufs externally and
# their dependencies. Tensorflow has more protobufs and can be added if requested.
protoc_install/bin/protoc \
PROTOC_VERSION=$(python3 -m grpc_tools.protoc --version)
echo $PROTOC_VERSION
python3 -m grpc_tools.protoc \
--proto_path="$TENSORFLOW_DIR/third_party/xla/third_party/tsl" \
--proto_path="$TENSORFLOW_DIR/third_party/xla" \
--proto_path="$TENSORFLOW_DIR" \
Expand Down Expand Up @@ -102,7 +90,10 @@ rm -r \
stubs/tensorflow/tensorflow/core/util/example_proto_fast_parsing_test_pb2.pyi \

sed --in-place="" \
"s/extra_description = .*$/extra_description = \"Partially generated using [mypy-protobuf==$MYPY_PROTOBUF_VERSION](https:\/\/github.com\/nipunn1313\/mypy-protobuf\/tree\/v$MYPY_PROTOBUF_VERSION) on tensorflow==$TENSORFLOW_VERSION\"/" \
"s/extra_description = .*$/extra_description = \"\
Partially generated using [mypy-protobuf==$MYPY_PROTOBUF_VERSION](https:\/\/github.com\/nipunn1313\/mypy-protobuf\/tree\/v$MYPY_PROTOBUF_VERSION) \
and $PROTOC_VERSION \
on tensorflow==$TENSORFLOW_VERSION .\"/" \
stubs/tensorflow/METADATA.toml

# use `|| true` so the script still continues even if a pre-commit hook
Expand Down
2 changes: 1 addition & 1 deletion stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class Coroutine(Awaitable[_ReturnT_co], Generic[_YieldT_co, _SendT_contra, _Retu
@property
def cr_code(self) -> CodeType: ...
@property
def cr_frame(self) -> FrameType: ...
def cr_frame(self) -> FrameType | None: ...
@property
def cr_running(self) -> bool: ...
@abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion stubs/editdistance/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "0.6.*"
version = "0.8.*"
upstream_repository = "https://github.com/roy-ht/editdistance"
2 changes: 2 additions & 0 deletions stubs/editdistance/editdistance/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ from collections.abc import Hashable, Iterable

def eval(a: Iterable[Hashable], b: Iterable[Hashable]) -> int: ...
def distance(a: Iterable[Hashable], b: Iterable[Hashable]) -> int: ...
def eval_criterion(a: Iterable[Hashable], b: Iterable[Hashable], thr: int) -> bool: ...
def distance_le_than(a: Iterable[Hashable], b: Iterable[Hashable], thr: int) -> bool: ...
2 changes: 1 addition & 1 deletion stubs/protobuf/METADATA.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# in scripts/generate_proto_stubs.sh and vice-versa.
version = "5.26.*"
upstream_repository = "https://github.com/protocolbuffers/protobuf"
extra_description = "Generated using [mypy-protobuf==3.6.0](https://github.com/nipunn1313/mypy-protobuf/tree/v3.6.0) on [protobuf v26.1](https://github.com/protocolbuffers/protobuf/releases/tag/v26.1) (python protobuf==5.26.1)"
extra_description = "Generated using [mypy-protobuf==3.6.0](https://github.com/nipunn1313/mypy-protobuf/tree/v3.6.0) and libprotoc 25.1 on [protobuf v26.1](https://github.com/protocolbuffers/protobuf/releases/tag/v26.1) (python protobuf==5.26.1)"
partial_stub = true

[tool.stubtest]
Expand Down
15 changes: 2 additions & 13 deletions stubs/pycurl/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
version = "7.45.2"
version = "7.45.3"
upstream_repository = "https://github.com/pycurl/pycurl"

[tool.stubtest]
# Install on Windows requires building PycURL from source
#
# Install on MacOS is too complicated for the CI and does not work with stubtest:
# % brew install openssl
# % export LDFLAGS="-L/usr/local/opt/openssl@3/lib"
# % export CPPFLAGS="-I/usr/local/opt/openssl@3/include"
# % pip install --compile --install-option="--with-openssl" pycurl
# TODO: Test on Windows and/or MacOS once wheels are available.
platforms = ["linux"]
apt_dependencies = ["libcurl4-openssl-dev", "libssl-dev"]
# No need to install on the CI. Leaving here as information for MacOS contributors.
# brew_dependencies = ["openssl"]
platforms = ["darwin", "linux", "win32"]
Loading

0 comments on commit 0109400

Please sign in to comment.