Repository navigation
Resolve user function modules in CompiledRunner (#145) - #204
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #145.
Problem
CompiledRunnertranspiles a call to a user-supplied function asmodule.qualname, for example__main__.lower(...).Transpiler.evaluate()runs the code with the globals ofcelpy.evaluation, which only know the modules thatcelpy.evaluationimports. A function defined in any other module, such as__main__or an application package, fails with:The same expression works with
InterpretedRunner.Change
This revives the approach from #146 (closed because of failing checks), with these adjustments:
Transpiler.__init__()collects the top-level package of each function's module fromsys.modules. It maps_operatortooperatorthe same wayPhase1Transpiler.func_name()does.Transpiler.evaluate()executes the code with a copy of thecelpy.evaluationglobals plus those packages. Existing module globals take precedence, so a user package can't shadow a name that the transpiled code depends on.mypy --strict.Functions defined with
lambdaor nested inside another function still can't be referenced by name. That limitation is separate from this fix.Testing
test_transpile_function_from_other_moduleintests/test_transpilation.py. It registers a function in a module thatcelpy.evaluationnever imports and evaluatesdevice.lower() == 'tablet'withCompiledRunner. The test fails without the change (NameErrorfor the module name) and passes with it.pytest tests: 433 passed, 1 skipped, 100% coverage.pytest --doctest-modules src README.rst: 11 passed.behave --tags=@conformance --tags=~@wip, with both the interpreted and the compiled runner: 1127 scenarios passed, 0 failed.mypy --strict,ruff check src toolsandruff format --diffare clean.