Skip to content

Instantly share code, notes, and snippets.

@graingert
Created September 5, 2023 10:59
Show Gist options
  • Save graingert/a2dbd999c9eadd0d6c7ec3a71a2a9d9f to your computer and use it in GitHub Desktop.
Save graingert/a2dbd999c9eadd0d6c7ec3a71a2a9d9f to your computer and use it in GitHub Desktop.
import pathlib
import sys
import tomllib
from collections.abc import Iterable
def main() -> None:
project = pathlib.Path("pyproject.toml")
module = tomllib.loads(project.read_text())["tool"]["mypy"]["overrides"][0][
"module"
]
src = pathlib.Path("src")
def new_module() -> Iterable[str]:
for m in module:
if not m.endswith(".*"):
yield m
for path in (src / m.removesuffix(".*").replace(".", "/")).rglob("*.py"):
yield str(path).removeprefix("src/").removesuffix(
"/__init__.py"
).removesuffix(".py").replace("/", ".")
new_module = list(new_module())
breakpoint()
sys.exit(main())
import json
import pathlib
import pprint
import sys
import tomllib
from collections.abc import Iterable
def main() -> None:
project = pathlib.Path("pyproject.toml")
module = tomllib.loads(project.read_text())["tool"]["mypy"]["overrides"][1][
"module"
]
errors = json.loads(pathlib.Path("mypy-ratchet.json").read_text())
module2 = []
module3 = []
for m in module:
path = pathlib.Path("src/") / m.replace(".", "/")
if (
str(path.with_suffix(".py")) in errors
or str(path / "__init__.py") in errors
):
module2.append(m)
else:
module3.append(m)
pprint.pp(module2)
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment