Use main.py as call graph entry point for CLI commands#53
Open
theweaklink wants to merge 5 commits into
Open
Conversation
Centralize entry file selection in get_call_graph_entry_files() so onecode-build, onecode-extract, onecode-check, and onecode-require analyze main.py plus registered flows from .onecode.json instead of globbing all Python files under flows/ or the project root. Co-authored-by: Cursor <[email protected]>
Resolve PyCG graph keys such as utils.xx to flows\utils.xx on Windows so extract/build pick up OneCode elements defined in imported helper modules under flows/. Co-authored-by: Cursor <[email protected]>
Backslashes are not allowed inside f-string expressions before Python 3.12. Build the Windows graph key with string concatenation instead. Co-authored-by: Cursor <[email protected]>
Do not replace dots in function namespaces when building Windows keys:
step1.run must resolve to flows\step1.run, not flows\step1\run.
Always start extraction from flows.{name}.run and let
_resolve_graph_key map to the platform-specific PyCG namespace.
Co-authored-by: Cursor <[email protected]>
On Windows, PyCG does not always analyze relative imports such as `from .utils import xx` unless the helper module is an explicit entry file. Collect helpers imported by registered flows and add them to get_call_graph_entry_files() so step2 can reach flows/utils.py. Co-authored-by: Cursor <[email protected]>
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.
Summary
get_call_graph_entry_files()to centralize PyCG entry file selection for all CLI commands that perform static analysis.onecode-build,onecode-extract,onecode-check, andonecode-requirenow analyzemain.pyplus only the flow scripts registered in.onecode.json(the same flows executed at runtime bymain.py).flows/**/*.pyor the entire project tree, which previously caused unrelated files (.venv, unused scripts, data helpers) to be parsed.Motivation
On Windows, when a
.venvlives inside the project directory, PyCG's naivemod_dir in mod.__file__check treatedsite-packagesas local project code and crashed during analysis. Even without that bug, scanning every.pyfile underflows/or the project root is broader than what OneCode actually runs.Using
main.pyas the entry point mirrors the runtime execution model: flows are loaded from.onecode.json, not discovered by directory glob.Test plan
tests/unit/utils/test_call_graph_entry.py— verifies entry files excludeflows/unused.pytests/unit/cli/test_extract.py— ground-truth extraction unchangedtests/unit/cli/test_build.py— ground-truth build unchangedtests/unit/cli/test_check.py::test_imported_modules— same module set as beforetests/unit/cli/test_require.py— same requirements output as before