Skip to content

Commit

Permalink
Create second project for mypy-protobuf
Browse files Browse the repository at this point in the history
This was a rudimentary way of having multiple mypy commands
per project (as needed here). It might be more elegant to have
multiple mypy_cmd within a project, but it seemed nontrivial to
achieve, and I was able to whip this mechanism up more quickly -
using multiple projects with one mypy_cmd per project.
Not the most proud of it, but it works.
  • Loading branch information
nipunn1313 committed Aug 14, 2021
1 parent 960c832 commit 17c34e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ Some other things that could be done are:
- add support for mypy plugins
- add bisection for typeshed
- make it possibe to dump structured output
- multiple mypy invocations for the same project
- improve CLI or output formatting
- ???

35 changes: 22 additions & 13 deletions mypy_primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ def line_count(path: Path) -> int:
# ==============================


async def clone(repo_url: str, cwd: Path, shallow: bool = False) -> None:
async def clone(repo_url: str, repo_dir: str, cwd: Path, shallow: bool = False) -> None:
if os.path.exists(repo_url):
repo_url = os.path.abspath(repo_url)
cmd = ["git", "clone", "--recurse-submodules", repo_url]
cmd = ["git", "clone", "--recurse-submodules", repo_url, repo_dir]
if shallow:
cmd += ["--depth", "1"]
await run(cmd, cwd=cwd)
Expand Down Expand Up @@ -157,12 +157,12 @@ async def get_revision_for_revision_or_date(revision: str, repo_dir: Path) -> st
return revision


async def ensure_repo_at_revision(repo_url: str, cwd: Path, revision_like: RevisionLike) -> Path:
repo_dir = cwd / Path(repo_url).stem
async def ensure_repo_at_revision(repo_url: str, cwd: Path, revision_like: RevisionLike, project_name: Optional[str] = None) -> Path:
repo_dir = cwd / (project_name or Path(repo_url).stem)
if repo_dir.is_dir():
await refresh(repo_dir)
else:
await clone(repo_url, cwd, shallow=revision_like is None)
await clone(repo_url, str(repo_dir), cwd, shallow=revision_like is None)
assert repo_dir.is_dir()

if revision_like is None:
Expand Down Expand Up @@ -315,10 +315,12 @@ class Project:
pip_cmd: Optional[str] = None
# if expected_success, there is a recent version of mypy which passes cleanly
expected_success: bool = False
# If unset, infer name from location
name_override: Optional[str] = None

@property
def name(self) -> str:
return Path(self.location).stem
return self.name_override or Path(self.location).stem

@property
def venv_dir(self) -> Path:
Expand All @@ -339,7 +341,7 @@ async def setup(self) -> None:
else:
# usually projects are something clonable
repo_dir = await ensure_repo_at_revision(
self.location, ARGS.projects_dir, self.revision
self.location, ARGS.projects_dir, self.revision, self.name
)
assert repo_dir == ARGS.projects_dir / self.name
if self.pip_cmd:
Expand Down Expand Up @@ -1265,6 +1267,19 @@ def inner() -> Optional[int]:
),
expected_success=True,
),
Project(
location="https://github.com/dropbox/mypy-protobuf",
mypy_cmd="{mypy} mypy_protobuf/",
pip_cmd="{pip} install types-protobuf",
expected_success=True,
),
Project(
name_override="mypy-protobuf-generated-code",
location="https://github.com/dropbox/mypy-protobuf",
mypy_cmd="{mypy} test/",
pip_cmd="{pip} install types-protobuf grpc-stubs",
expected_success=True,
),
# failures expected...
Project(
location="https://github.com/pyppeteer/pyppeteer.git",
Expand Down Expand Up @@ -1345,12 +1360,6 @@ def inner() -> Optional[int]:
mypy_cmd="{mypy} rotkehlchen/ tools/data_faker",
pip_cmd="{pip} install types-requests",
),
Project(
location="https://github.com/dropbox/mypy-protobuf",
mypy_cmd="{mypy} mypy_protobuf/",
pip_cmd="{pip} install types-protobuf",
expected_success=True,
),
]
assert len(PROJECTS) == len({p.name for p in PROJECTS})

Expand Down

0 comments on commit 17c34e1

Please sign in to comment.