1. Anthony Tuininga
  2. cx_Freeze
  3. Issues
Issue #53 new

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

Gaë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 (3)

  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 reporter
    • 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. EricSmith

    To the first point:

    It seems to me that the file attribute being None is reasonably consistent with how namespace packages work. From the Python Cookbook:

    ...the main way that you can tell if a package is serving as a namespace package is to check its file attribute. If it’s missing altogether, the package is a namespace.

    To the second point:

    While there might be marginally more efficient ways to fix the problem, I'd be thrilled just to have a fix, and the provided patch (perhaps with the change from continue to break) seems like a pretty simple one.

  4. Log in to comment