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

Bundling recent "black" fails #476

Closed
justvanrossum opened this issue Dec 21, 2022 · 11 comments
Closed

Bundling recent "black" fails #476

justvanrossum opened this issue Dec 21, 2022 · 11 comments

Comments

@justvanrossum
Copy link

justvanrossum commented Dec 21, 2022

Running python setup.py py2app in the attached archived folder fails like this:

error: [Errno 2] No such file or directory: '/Users/just/code/git/drawbot/black_py2app/venv/lib/python3.9/site-packages/black-22.12.0.dist-info/top_level.txt'

This is happening since black==22.10.0

Here is a minimal reproducer:

app_with_black.zip

Now, this may of course be a bug in black: psf/black#3233 (comment), but thought it good to report here, too.

Cc @typemytype

@justvanrossum
Copy link
Author

It seems that "top_level.txt" is not a required file, but is always added by setuptools. This is not the case with other packaging tools like Hatch (as used by Black).

@justvanrossum
Copy link
Author

Info found here: https://blog.schuetze.link/2018/07/21/a-dive-into-packaging-native-python-extensions.html

top_level.txt: Setuptools also add this file which contains only the name of your package. This is part of the (PEP-less) egg format, the predecessor of wheels, as described in The Internal Structure of Python Eggs. This file is not documented and not needed for wheels and therefore not added by other packagers such as poetry. (Interestingly enough, the wheel repository, which adds the bdist_whl command to setuptools, does not even contain the string top_level.txt.)

@justvanrossum
Copy link
Author

Ah, interesting! a1c0a2c

@justvanrossum
Copy link
Author

Maybe tangentially, running black==22.8.0 from a bundled app fails like this:

Traceback (most recent call last):
  File "/Applications/DrawBot.app/Contents/Resources/DrawBot.py", line 66, in formatCode_
    self.vanillaWindowController.formatCode()
  File "/Applications/DrawBot.app/Contents/Resources/lib/python3.9/drawBot/ui/drawBotController.py", line 171, in formatCode
    import black
  File "src/black/__init__.py", line 32, in <module>
ModuleNotFoundError: No module named 'mypy_extensions'

Somehow black's dependencies aren't completely picked up by py2app.

@ronaldoussoren
Copy link
Owner

Black uses mypyc and that makes it annoying hard to automatically bundle it up. Last time I worked on this just adding "black" to the packages option wasn't good enough, mypyc adds a helper extension outside of the package.

I'll see if I can update the recipe for this.

ronaldoussoren added a commit that referenced this issue Dec 21, 2022
Issue #476.

This should fix two problems with the recipe:

1. The older recipe uses "toplevel.txt", which is not
   present in current wheels of black, and is not part
   of a modern packaging standard.

   The new version uses "RECORD" instead.

2. Use code borrowed from modudulegraph to scan the
   source code next to the mypyc compiled extension
   modules for depedencies.

   This automaticly detects dependencies instead of
   relying on a hardcoded list in the recipe.
@ronaldoussoren
Copy link
Owner

End of year vacation time for the win... Could you check if the head of the "v0.28-branch" branch fixes the issue for this?

Don't test the the master branch, that's fairly unstable at the moment and more importantly doesn't include the fix I pushed earlier.

@justvanrossum
Copy link
Author

Fantastic, works like a charm with black 22.12.0. Thank you so much!

@ronaldoussoren
Copy link
Owner

Great, I'll push out a release later this week.

@typemytype
Copy link

thanks Ronald!

@ronaldoussoren
Copy link
Owner

a py2app with this fix was released yesterday.

@justvanrossum
Copy link
Author

FWIW, while I see the release on PyPI, it is not listed on the GH releases page: https://github.com/ronaldoussoren/py2app/releases

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

3 participants