[PATCH] fix "replace_paths" in combination with "namespace_packages"

Gaëtan de Menten avatarGaëtan de Menten created an issue

Here is an excerpt of my setup.py which caused an exception (with release 4.3.2 on Windows 7):

{
"replace_paths": [("*", "")],
"namespace_packages": ["mpl_toolkits"],
}

Attached is a patch (against release 4.3.2) to fix the problem.

Comments (2)

  1. Thomas Kluyver

    Thanks. Questions about the fix:

    • Is the bug actually that file shouldn't be None for modules in namespace packages? i.e. should this be fixed by setting mod.file, instead of ignoring the case where it's None?
    • The patch checks topLevelModule.file inside a for loop, but there's nothing within that loop that can change it. So if it's None the first time, it will be None on each subsequent iteration, and also when the function recurses in the next code block. So it can be done outside the loop, and just return co unmodified if necessary.
  2. Gaëtan de Menten
    • It might be better, I don't know. I can just tell you that my fix results in an (apparent) correct behavior.
    • You are right. I tried to produce a minimal fix/patch. But given the large return statement and the fact that it needs to be different on py3, I wouldn't bother checking it before the loop, I would only replace "continue" by "break" in my patch. Just my 2c. Do whatever is best for you.
  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.