ronaldoussoren / py2app

py2app is a Python setuptools command which will allow you to make standalone Mac OS X application bundles and plugins from Python scripts.
Other
342 stars 36 forks source link

Bundling recent "black" fails #476

Closed justvanrossum closed 1 year ago

justvanrossum commented 1 year ago

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: https://github.com/psf/black/pull/3233#issuecomment-1361191055, but thought it good to report here, too.~

Cc @typemytype

justvanrossum commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Ah, interesting! https://github.com/ronaldoussoren/py2app/commit/a1c0a2c33f953467d5abeb6447d2097e48dc3e30

justvanrossum commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

ronaldoussoren commented 1 year ago

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

typemytype commented 1 year ago

thanks Ronald!

ronaldoussoren commented 1 year ago

a py2app with this fix was released yesterday.

justvanrossum commented 1 year ago

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