Conversation
|
@liamhuber I started looking into the possibility of including variables as well. Frankly I'm also not really convinced but I still would like to explore the possibility |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #164 +/- ##
===========================================
- Coverage 100.00% 98.42% -1.58%
===========================================
Files 30 30
Lines 2009 2035 +26
===========================================
- Hits 2009 2003 -6
- Misses 0 32 +32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I just had a discussion with @XzzX and we think we can keep the current implementation is maybe not quite as useless as I had imagined, because with this implementation it is now possible to throw an error as soon as an external variable is used. |
Failing cleanly is infinitely better than looking like everything is well-provenanced when it isn't. However, I still think that restricting "ok locally defined stuff" to mean "don't use any symbols outside your function definition" is going to turn out to be a more annoying, more restrictive, more-work solution than telling people "you'll have to use well-versioned code to contribute to the KG". As an intermediate step towards catching and leveraging these external symbols, this still seems like solid progress though. |
There was a problem hiding this comment.
Pull request overview
This PR updates dependency_parser to infer function dependencies by identifying undefined names in a function’s AST (including from type hints) and resolving those names from the function’s scope, recursively exploring unversioned objects.
Changes:
- Replaced call-graph-based dependency crawling with undefined-variable detection and resolution.
- Added
UndefinedVariableVisitorandfind_undefined_variableshelpers to drive dependency discovery. - Reworked
test_dependency_parserto focus on the new undefined-variable behavior and mocked resolution.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
flowrep/models/parsers/dependency_parser.py |
Introduces undefined-name visitor + new dependency collection approach based on scope resolution and version availability. |
tests/unit/models/parsers/test_dependency_parser.py |
Replaces prior call-dependency tests with new tests for splitting, undefined-name detection, and mocked dependency discovery. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR modifies the dependency parsing logic to detect names used-but-not-defined in a function’s source (e.g., globals/type-hint symbols) and resolve them to objects for version tracking, as part of the ongoing dependency-crawling work from #155.
Changes:
- Added an AST visitor (
UndefinedVariableVisitor) plusfind_undefined_variablesto extract undefined symbols from source code. - Reworked
get_call_dependenciesto resolve those symbols viaobject_scopeand optionally recurse for unversioned objects. - Replaced the prior call-graph oriented unit tests with new tests focused on undefined-variable discovery and resolution.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
flowrep/models/parsers/dependency_parser.py |
Adds undefined-variable detection and updates dependency collection logic to resolve those symbols to objects. |
tests/unit/models/parsers/test_dependency_parser.py |
Rewrites tests to cover the new undefined-variable based behavior and mocked resolution paths. |
Comments suppressed due to low confidence (1)
tests/unit/models/parsers/test_dependency_parser.py:102
test_type_hintsreferencesnpbut the module isn't imported/defined anywhere in this test module, so definingtest_functionwill raiseNameError(or laterget_call_dependencieswill fail resolving it). Also, CI envs here don't include optional deps like NumPy, so importing NumPy in the test would be brittle. Define a small module-level dummynp(with an.arrayattribute) or use a stdlib object instead so the test is self-contained and doesn't add a new dependency.
if __name__ == "__main__":
unittest.main()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def visit_Name(self, node): | ||
| if isinstance(node.ctx, ast.Load): # Variable is being used | ||
| self.used_vars.add(node.id) | ||
| elif isinstance(node.ctx, ast.Store): # Variable is being defined | ||
| self.defined_vars.add(node.id) | ||
|
|
||
| def visit_FunctionDef(self, node): | ||
| # Add the function name itself to defined variables | ||
| self.defined_vars.add(node.name) | ||
| # Add function arguments to defined variables | ||
| for arg in node.args.args: | ||
| self.defined_vars.add(arg.arg) | ||
| self.generic_visit(node) | ||
|
|
||
| def visit_AsyncFunctionDef(self, node): | ||
| # Add the async function name itself to defined variables | ||
| self.defined_vars.add(node.name) | ||
| # Add async function arguments to defined variables | ||
| for arg in node.args.args: | ||
| self.defined_vars.add(arg.arg) |
|
@copilot Rewrite |
|
@samwaseda I've opened a new pull request, #190, to work on those changes. Once the pull request is ready, I'll request review from you. |
Co-authored-by: samwaseda <37879103+samwaseda@users.noreply.github.com>
Detect local arguments and functions used in a function
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
Merge main into args
|
Ok super, the commit history looks reasonable here 😅 merge conflict resolution worked 🚀 |
|
Ah the imports from #158 disappeared XD |
|
I wonder if ruff reformatted them to the top of the file. I'll look into it later this morning. Is finding them inside the function parsing not an element of the tests? |
|
@samwaseda, ah, shoot. Main never got merged into this PR since #158 got merged into main. Since this PR only touched |
|
It’s ok leave it like this. I’ll take care of it |
|
No, I broke it. I think I can (mostly) fix it. |
In #164. I'm leveraging the diff comparison between main and the last commit in that PR that I didn't touch: https://github.com/pyiron/flowrep/compare/1e893dede850a43f2e0d3cc5595f3cb62fda1da9..e334f1f8815fc52e70d472e485dab9a024216437. Weirdly, most of the files identified as "moved" from flowrep/models to src/flowrep, but the two relevant files (`(test_)dependency_parser.py`) showed as completely removed and completely re-written. This caused me to completely delete @samwaseda's actual work in that branch during the merge. Here I lose the git history, but recover the actual file changes there. Plus I ran black and updated the module paths to reflect the current location of file in main. Actual full author: Co-authored-by: Sam Dareska <37879103+samwaseda@users.noreply.github.com> Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
In #164. I'm leveraging the diff comparison between main and the last commit in that PR that I didn't touch: https://github.com/pyiron/flowrep/compare/1e893dede850a43f2e0d3cc5595f3cb62fda1da9..e334f1f8815fc52e70d472e485dab9a024216437. Weirdly, most of the files identified as "moved" from flowrep/models to src/flowrep, but the two relevant files (`(test_)dependency_parser.py`) showed as completely removed and completely re-written. This caused me to completely delete @samwaseda's actual work in that branch during the merge. Here I lose the git history, but recover the actual file changes there. Plus I ran black and updated the module paths to reflect the current location of file in main. (actually same is primary author) Co-authored-by: Sam Dareska <37879103+samwaseda@users.noreply.github.com> Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
|
K, I couldn't figure out a fix to recover the full git history, but I think I got the content recovered and consistent with |
Following the effort in #155, I started trying to parse variables as well. Edits will follow....