mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 09:14:42 +01:00
Switch mypy approach to pre-commit (#1234)
I'm treating my PR to mypy bazel integration as dead in the water. Abandoning that approach, this seems to work reasonably well as a replacement. It's actually a slightly newer version of mypy too -- the bazel integration was stuck on an old version. Note I don't think we're losing much: we shouldn't be writing too much python.
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
load("@py_deps//:requirements.bzl", "requirement")
|
||||
load("@mypy_integration//:mypy.bzl", "mypy_test")
|
||||
|
||||
py_library(
|
||||
name = "github_helpers",
|
||||
@@ -25,12 +24,6 @@ py_binary(
|
||||
deps = ["github_helpers"],
|
||||
)
|
||||
|
||||
mypy_test(
|
||||
name = "pr_comments_mypy_test",
|
||||
include_imports = True,
|
||||
deps = [":pr_comments"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "pr_comments_test",
|
||||
srcs = ["pr_comments_test.py"],
|
||||
@@ -48,12 +41,6 @@ py_binary(
|
||||
],
|
||||
)
|
||||
|
||||
mypy_test(
|
||||
name = "update_label_access_mypy_test",
|
||||
include_imports = True,
|
||||
deps = [":update_label_access"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "update_label_access_test",
|
||||
srcs = ["update_label_access_test.py"],
|
||||
|
||||
@@ -14,8 +14,8 @@ import os
|
||||
from typing import Dict, Generator, Optional, Tuple
|
||||
|
||||
# https://pypi.org/project/gql/
|
||||
import gql
|
||||
import gql.transport.requests
|
||||
import gql # type: ignore
|
||||
import gql.transport.requests # type: ignore
|
||||
|
||||
_ENV_TOKEN = "GITHUB_ACCESS_TOKEN"
|
||||
|
||||
@@ -52,7 +52,7 @@ class Client(object):
|
||||
url="https://api.github.com/graphql",
|
||||
headers={"Authorization": "bearer %s" % parsed_args.access_token},
|
||||
)
|
||||
self._client = gql.Client(transport=transport) # type: ignore
|
||||
self._client = gql.Client(transport=transport)
|
||||
|
||||
def execute(self, query: str) -> Dict:
|
||||
"""Runs a query."""
|
||||
|
||||
@@ -25,6 +25,7 @@ except ImportError:
|
||||
"github_helpers",
|
||||
os.path.join(os.path.dirname(__file__), "github_helpers.py"),
|
||||
)
|
||||
assert github_helpers_spec is not None
|
||||
github_helpers = importlib.util.module_from_spec(github_helpers_spec)
|
||||
github_helpers_spec.loader.exec_module(github_helpers) # type: ignore
|
||||
|
||||
|
||||
@@ -114,18 +114,18 @@ def _update_team(
|
||||
|
||||
This switches to pygithub because GraphQL lacks equivalent mutation support.
|
||||
"""
|
||||
gh_team = gh.get_organization(_ORG).get_team_by_slug(_TEAM) # type: ignore
|
||||
gh_team = gh.get_organization(_ORG).get_team_by_slug(_TEAM)
|
||||
add_members = org_members - team_members
|
||||
if add_members:
|
||||
print("Adding members: %s" % ", ".join(add_members))
|
||||
for member in add_members:
|
||||
gh_team.add_membership(gh.get_user(member)) # type: ignore
|
||||
gh_team.add_membership(gh.get_user(member))
|
||||
|
||||
remove_members = team_members - org_members
|
||||
if remove_members:
|
||||
print("Removing members: %s" % ", ".join(remove_members))
|
||||
for member in remove_members:
|
||||
gh_team.remove_membership(gh.get_user(member)) # type: ignore
|
||||
gh_team.remove_membership(gh.get_user(member))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
@@ -136,7 +136,7 @@ def main() -> None:
|
||||
org_members = _load_org_members(client)
|
||||
team_members = _load_team_members(client)
|
||||
if org_members != team_members:
|
||||
gh = github.Github(parsed_args.access_token) # type: ignore
|
||||
gh = github.Github(parsed_args.access_token)
|
||||
_update_team(gh, org_members, team_members)
|
||||
print("Done!")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user