python-jsonschema / jsonschema-specifications

Support files exposing JSON from the JSON Schema specifications to Python
https://jsonschema-specifications.readthedocs.io/
MIT License
10 stars 7 forks source link

_core._schemas fails with Pyinstaller #10

Closed patricklatimer closed 1 year ago

patricklatimer commented 1 year ago

Description

When using Pyinstaller to package an application using jsonschema>=4.18.0, the 'schemas' folder in jsonschema_specifications isn't pulled into the resulting folder under dist. Then when jsonschema_specifications tries to access it in line 27 of _core: for version in files(__package__).joinpath("schemas").iterdir():, it fails. This doesn't happen for jsonschema==4.17.0, so it must be something with the newer repo structure.

Steps to reproduce:

In a fresh environment:

Traceback (most recent call last):
  File "app.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "jsonschema\__init__.py", line 17, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "jsonschema\validators.py", line 19, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "jsonschema_specifications\__init__.py", line 11, in <module>
  File "referencing\_core.py", line 297, in __rmatmul__
  File "jsonschema_specifications\_core.py", line 27, in _schemas
  File "pathlib.py", line 1150, in iterdir
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'path\\to\\dist\\app\\jsonschema_specifications\\schemas'
[22508] Failed to execute script 'app' due to unhandled exception!

And there is no dist/app/jsonschema_specifications folder, though there is a dist/app/jsonschema. When I tested it with jsonschema==4.17.0, there was a dist/app/jsonschema/schemas folder and the app runs correctly.

Julian commented 1 year ago

Hi there -- this probably belongs downstream in the pyinstaller repos -- what's here in this repo is working correctly for normal installations, so whatever is happening has to do with the tricks pyinstaller plays.