Skip to content
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

mypy fails with "baseline-revision is not a valid Python package name" in the baseline worktree if the git repo toplevel contains __init__.py #498

Closed
tapted opened this issue May 30, 2023 · 2 comments · Fixed by #499
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@tapted
Copy link

tapted commented May 30, 2023

Describe the bug

If the top-level of a git repo has an __init__.py in it, then the step that does

git worktree add --quiet --force --force /tmp/tmpF00/baseline-revision HEAD

will create a file baseline-revision/__init__.py. When mypy sees this, it expects "baseline-revision" to be a valid python package name. But it's not because of the hyphen.

python/mypy#8400 talks a bit about this issue, and there are folks asking for a way to suppress it.

But there's a simple fix in Darker, like

diff --git a/src/darker/linting.py b/src/darker/linting.py
index bc2055f..1e285d6 100644
--- a/src/darker/linting.py
+++ b/src/darker/linting.py
@@ -524,7 +524,7 @@ def _get_messages_from_linters_for_baseline(

     """
     with TemporaryDirectory() as tmpdir:
-        tmp_path = Path(tmpdir) / "baseline-revision"
+        tmp_path = Path(tmpdir) / "baseline-revision" / root.name
         with git_clone_local(root, revision, tmp_path) as clone_root:
             rev1_commit = git_rev_parse(revision, root)
             result = _get_messages_from_linters(

i.e., always create the worktree in a subfolder of "baseline-revision". Sharing the same name as where the repo is checked out should be most reliable. (E.g. if the project config assumes the top-level of the git repo is in PYTHONPATH).

To Reproduce
Steps to reproduce the behavior:

  1. Clone this repository: 'https://chromium.googlesource.com/chromiumos/chromite'
    • (or just make a git repo with an __init__.py at the top level and any other)
  2. Run Darker with darker -vvv --lint --check --lint "mypy --follow-imports=silent" api/controller/sysroot.py
  3. See error / wrong behavior

"-vvv" will show the output, "baseline-revision is not a valid Python package name".

Otherwise, the effect is just to treat the baseline as having no errors, so all mypy errors on the files are emitted, without filtering.

Expected behavior

Just new mypy errors to be emitted.

Tested with:

  • darker@a7f586428f44d07795dba601fb21db0fb5ede22b (May 1 2023)
  • mypy 1.3.0
  • Python 3.10.9
@akaihola
Copy link
Owner

@tapted thanks for the report and the proposed fix, excellent!

@akaihola akaihola self-assigned this May 30, 2023
@akaihola akaihola added the enhancement New feature or request label May 30, 2023
@akaihola akaihola added this to the Darker 1.7.2 milestone May 30, 2023
@akaihola
Copy link
Owner

@tapted can I add you as a collaborator for this repository and assign #499 for you to review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging a pull request may close this issue.

2 participants