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

cx_Freeze includes dist-info directories for excluded packages #1283

Open
marsfan opened this issue Nov 16, 2021 · 3 comments
Open

cx_Freeze includes dist-info directories for excluded packages #1283

marsfan opened this issue Nov 16, 2021 · 3 comments

Comments

@marsfan
Copy link

marsfan commented Nov 16, 2021

Describe the bug
The distribution info (the *.dist-info folders) for packages that are specified with the excludes are still added to library.zip

To Reproduce
Note: I am using pytest as an example, but it works with any package

  1. Create a simple dummy module (containing just __main__.py and __init__.py) to build into a program.

  2. Create a virtual environment with cx_Freeze and pytest installed.

  3. Create the following setup.py file for cx_freeze:

    from cx_Freeze import setup, Executable
    
    setup(
        name="Test Module",
        version="1.0.0",
        description="A simple module for testing",
        options={"build_exe": {"excludes": "pytest"}},
        executables=[Executable("example_module/__main__.py")]
    )
  4. Create the program by running python setup.py build

Expected behavior
lib/library.zip should not contain the "pytest-6.2.5.dist-info" folder

Desktop (please complete the following information):

  • Platform information (e.g. Ubuntu Linux 16.04): Windows 10 20H2
  • OS architecture (e.g. amd64): amd64
  • cx_Freeze version [e.g. 6.6]: 6.8.2
  • Python version [e.g. 3.9]: 3.9

Additional context
I spent some tracing down the exact source of this issue. It appears to be in freezer.py, specifically the Freezer._write_modules() method. Starting around line 569, the program gets the distribution file metadata that was cached, and copies it all into the zip file, however, it does not check to see if any of the cached metadata is for a package that was excluded.

@marcelotduarte
Copy link
Owner

This behavior is by design. At least for a while.
If a package specifies that it requires another, I can exclude that package that I know won't be used, but the metadata has that information. Then the dist-info of the required package will have to be kept.

Do you have a real issue with this behavior?

@marsfan
Copy link
Author

marsfan commented Nov 18, 2021

Sorry for taking a little while to respond. What I don't understand is why it still includes the metadata folder even if the package itself is not included.

In my case, I am working on a program that has an option to print out all of the libraries that are bundled with it along with their licenses. Since cx_freeze is still including the metadata folders for some packages (in my case, zipp.dist-info and importlib-metadata.dist-info), the program improperly reports that they are included.

For the time being, I have worked around this by adding my own functionality to my setup.py script that removes the .dist-info folders from library.zip for explicitly excluded packages, but it would be nice for this functionality to be integrated into cx_Freeze

@marcelotduarte
Copy link
Owner

I accept a PR for excludes_metadata option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants