Skip to content

Enable Ruff flake8-async (ASYNC) #13727

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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ exclude = ["**/test_cases/**/*.py"]
external = ["F821", "Y"]
select = [
"ARG", # flake8-unused-arguments
"ASYNC", # flake8-async
"B", # flake8-bugbear
"D", # pydocstyle
"EXE", # flake8-executable
Expand Down
1 change: 1 addition & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pyright==1.1.397
pytype==2024.10.11; platform_system != "Windows" and python_version >= "3.10" and python_version < "3.13"

# Libraries used by our various scripts.
anyio
aiohttp==3.10.11
grpcio-tools>=1.66.2 # For grpc_tools.protoc
mypy-protobuf==3.6.0
Expand Down
31 changes: 16 additions & 15 deletions scripts/stubsabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from typing_extensions import Self, TypeAlias

import aiohttp
import anyio
import packaging.version
import tomlkit
from packaging.specifiers import Specifier
Expand Down Expand Up @@ -689,10 +690,10 @@ async def suggest_typeshed_update(update: Update, session: aiohttp.ClientSession
title = f"[stubsabot] Bump {update.distribution} to {update.new_version}"
async with _repo_lock:
branch_name = f"{BRANCH_PREFIX}/{normalize(update.distribution)}"
subprocess.check_call(["git", "checkout", "-B", branch_name, "origin/main"])
await anyio.run_process(["git", "checkout", "-B", branch_name, "origin/main"], check=True)
meta = update_metadata(update.distribution, version=update.new_version)
body = get_update_pr_body(update, meta)
subprocess.check_call(["git", "commit", "--all", "-m", f"{title}\n\n{body}"])
await anyio.run_process(["git", "commit", "--all", "-m", f"{title}\n\n{body}"], check=True)
if action_level <= ActionLevel.local:
return
if not latest_commit_is_different_to_last_commit_on_origin(branch_name):
Expand All @@ -711,12 +712,12 @@ async def suggest_typeshed_obsolete(obsolete: Obsolete, session: aiohttp.ClientS
title = f"[stubsabot] Mark {obsolete.distribution} as obsolete since {obsolete.obsolete_since_version}"
async with _repo_lock:
branch_name = f"{BRANCH_PREFIX}/{normalize(obsolete.distribution)}"
subprocess.check_call(["git", "checkout", "-B", branch_name, "origin/main"])
await anyio.run_process(["git", "checkout", "-B", branch_name, "origin/main"], check=True)
obs_string = tomlkit.string(obsolete.obsolete_since_version)
obs_string.comment(f"Released on {obsolete.obsolete_since_date.date().isoformat()}")
update_metadata(obsolete.distribution, obsolete_since=obs_string)
body = "\n".join(f"{k}: {v}" for k, v in obsolete.links.items())
subprocess.check_call(["git", "commit", "--all", "-m", f"{title}\n\n{body}"])
await anyio.run_process(["git", "commit", "--all", "-m", f"{title}\n\n{body}"], check=True)
if action_level <= ActionLevel.local:
return
if not latest_commit_is_different_to_last_commit_on_origin(branch_name):
Expand Down Expand Up @@ -754,15 +755,17 @@ async def main() -> None:
dists_to_update = [path.name for path in STUBS_PATH.iterdir()]

if args.action_level > ActionLevel.nothing:
subprocess.run(["git", "update-index", "--refresh"], capture_output=True)
diff_result = subprocess.run(["git", "diff-index", "HEAD", "--name-only"], text=True, capture_output=True)
await anyio.run_process(["git", "update-index", "--refresh"])
diff_result = await anyio.run_process(["git", "diff-index", "HEAD", "--name-only"])
stdout = diff_result.stdout.decode()
stderr = diff_result.stderr.decode()
if diff_result.returncode:
print("Unexpected exception!")
print(diff_result.stdout)
print(diff_result.stderr)
print(stdout)
print(stderr)
sys.exit(diff_result.returncode)
if diff_result.stdout:
changed_files = ", ".join(repr(line) for line in diff_result.stdout.split("\n") if line)
if stdout:
changed_files = ", ".join(repr(line) for line in stdout.split("\n") if line)
print(f"Cannot run stubsabot, as uncommitted changes are present in {changed_files}!")
sys.exit(1)

Expand All @@ -772,12 +775,10 @@ async def main() -> None:

denylist = {"gdb"} # gdb is not a pypi distribution

original_branch = subprocess.run(
["git", "branch", "--show-current"], text=True, capture_output=True, check=True
).stdout.strip()
original_branch = (await anyio.run_process(["git", "branch", "--show-current"], check=True)).stdout.decode().strip()

if args.action_level >= ActionLevel.local:
subprocess.check_call(["git", "fetch", "--prune", "--all"])
await anyio.run_process(["git", "fetch", "--prune", "--all"], check=True)

try:
conn = aiohttp.TCPConnector(limit_per_host=10)
Expand Down Expand Up @@ -817,7 +818,7 @@ async def main() -> None:
# if you need to cleanup, try:
# git branch -D $(git branch --list 'stubsabot/*')
if args.action_level >= ActionLevel.local and original_branch:
subprocess.check_call(["git", "checkout", original_branch])
await anyio.run_process(["git", "checkout", original_branch], check=True)


if __name__ == "__main__":
Expand Down