This repository demonstrates an issue encountered with compressed standalone parsers. The goal is to highlight the discrepancy between expected and actual results when using such parsers, and to provide steps to reproduce and fix the issue.
>>> 2 + 2
4
>>> (3 * 5) - 1
14
>>> 10 / 2
5.0ModuleNotFoundError: No module named 'lark'$ uv run --no-cache --isolated --package calculator-repr calcThe issue arises because the compressed standalone parser relies on certain components of the lark library that are embedded within the standalone module. However, when attempting to unpickle the parser, Python's pickle module expects the lark library to be installed in the environment. This discrepancy leads to the ModuleNotFoundError when the lark library is not available.
To resolve this issue, you can use a custom unpickler class that checks the resolution module. If the module matches the copied files, it replaces them with the standalone module. This ensures that the standalone parser functions correctly without requiring the lark library to be installed in the environment.
This approach ensures that the standalone parser resolves dependencies correctly, avoiding the ModuleNotFoundError.
For more details on the implementation and the fix, refer to the GitHub repository. You can test the solution using the following command:
uv run --no-cache --isolated --package calculator-repr calcThis command ensures that the environment is isolated and does not rely on cached dependencies, allowing you to verify the fix in a clean setup.