onecode 1.2.0__tar.gz → 1.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. {onecode-1.2.0 → onecode-1.2.2}/PKG-INFO +1 -1
  2. {onecode-1.2.0 → onecode-1.2.2}/onecode/__init__.py +1 -1
  3. {onecode-1.2.0 → onecode-1.2.2}/onecode/base/logger.py +4 -1
  4. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/utils.py +40 -16
  5. {onecode-1.2.0 → onecode-1.2.2}/onecode/utils/module.py +99 -2
  6. {onecode-1.2.0 → onecode-1.2.2}/pyproject.toml +1 -1
  7. {onecode-1.2.0 → onecode-1.2.2}/LICENSE +0 -0
  8. {onecode-1.2.0 → onecode-1.2.2}/README.md +0 -0
  9. {onecode-1.2.0 → onecode-1.2.2}/onecode/base/__init__.py +0 -0
  10. {onecode-1.2.0 → onecode-1.2.2}/onecode/base/decorator.py +0 -0
  11. {onecode-1.2.0 → onecode-1.2.2}/onecode/base/enums.py +0 -0
  12. {onecode-1.2.0 → onecode-1.2.2}/onecode/base/project.py +0 -0
  13. {onecode-1.2.0 → onecode-1.2.2}/onecode/base/singleton.py +0 -0
  14. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/__init__.py +0 -0
  15. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/add.py +0 -0
  16. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/build.py +0 -0
  17. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/check.py +0 -0
  18. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/create.py +0 -0
  19. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/extract.py +0 -0
  20. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/require.py +0 -0
  21. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/skeleton/.gitignore +0 -0
  22. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/skeleton/LICENSE +0 -0
  23. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/skeleton/README.md +0 -0
  24. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/skeleton/data/README.md +0 -0
  25. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/skeleton/flows/README.md +0 -0
  26. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/skeleton/main.py +0 -0
  27. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/skeleton/requirements.txt +0 -0
  28. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/start.py +0 -0
  29. {onecode-1.2.0 → onecode-1.2.2}/onecode/cli/zip.py +0 -0
  30. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/__init__.py +0 -0
  31. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/input/__init__.py +0 -0
  32. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/input/__init__.pyi +0 -0
  33. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/input/checkbox.py +0 -0
  34. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/input/csv_reader.py +0 -0
  35. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/input/dropdown.py +0 -0
  36. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/input/file_input.py +0 -0
  37. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/input/number_input.py +0 -0
  38. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/input/radio_button.py +0 -0
  39. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/input/slider.py +0 -0
  40. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/input/text_input.py +0 -0
  41. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/input_element.py +0 -0
  42. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/output/__init__.py +0 -0
  43. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/output/__init__.pyi +0 -0
  44. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/output/file_output.py +0 -0
  45. {onecode-1.2.0 → onecode-1.2.2}/onecode/elements/output_element.py +0 -0
  46. {onecode-1.2.0 → onecode-1.2.2}/onecode/utils/__init__.py +0 -0
  47. {onecode-1.2.0 → onecode-1.2.2}/onecode/utils/import_input.py +0 -0
  48. {onecode-1.2.0 → onecode-1.2.2}/onecode/utils/import_output.py +0 -0
  49. {onecode-1.2.0 → onecode-1.2.2}/onecode/utils/typing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: onecode
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: Python skeleton and library for OneCode projects
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -1,7 +1,7 @@
1
1
  # SPDX-FileCopyrightText: 2023-2024 DeepLime <contact@deeplime.io>
2
2
  # SPDX-License-Identifier: MIT
3
3
 
4
- __version__ = "1.2.0"
4
+ __version__ = "1.2.2"
5
5
 
6
6
 
7
7
  from .base import *
@@ -144,7 +144,10 @@ class Logger(metaclass=Singleton):
144
144
 
145
145
  handler = logging.StreamHandler(sys.stdout)
146
146
  handler.setFormatter(ColoredFormatter(Project().get_config(ConfigOption.LOGGER_COLOR)))
147
- logging.getLogger(Env.ONECODE_LOGGER_NAME).addHandler(handler)
147
+
148
+ base_logger = logging.getLogger(Env.ONECODE_LOGGER_NAME)
149
+ base_logger.addHandler(handler)
150
+ base_logger.propagate = False
148
151
  self.set_level(logging.INFO)
149
152
 
150
153
  @check_type
@@ -5,7 +5,6 @@ import ast
5
5
  import json
6
6
  import os
7
7
  from collections import OrderedDict
8
- from glob import iglob
9
8
  from typing import Dict, List, Optional
10
9
 
11
10
  import pydash
@@ -17,6 +16,7 @@ from slugify import slugify
17
16
  from ..base.decorator import check_type
18
17
  from ..base.enums import Env
19
18
  from ..base.project import Project
19
+ from ..utils.module import get_call_graph_entry_files
20
20
 
21
21
 
22
22
  @check_type
@@ -130,6 +130,40 @@ def run():
130
130
  json.dump(flows, f, indent=4)
131
131
 
132
132
 
133
+ def _flow_module_name(name: str) -> str:
134
+ if name.startswith('flows.'):
135
+ return name[len('flows.'):]
136
+ if name.startswith('flows\\'):
137
+ return name[len('flows\\'):]
138
+ return name
139
+
140
+
141
+ def _resolve_graph_key(name: str, graph: Dict) -> str:
142
+ """
143
+ Resolve a PyCG graph key across platform naming differences.
144
+
145
+ On Windows, PyCG keeps path separators in module namespaces (``flows\\step1.run``)
146
+ while Linux uses dots (``flows.step1.run``). Relative imports inside ``flows/``
147
+ are often keyed as ``utils.xx`` while the analyzed module lives under
148
+ ``flows\\utils.xx``.
149
+ """
150
+ if name in graph:
151
+ return name
152
+
153
+ module_name = _flow_module_name(name)
154
+ candidates = [
155
+ f'flows.{module_name}',
156
+ name,
157
+ f'flows\\{module_name}',
158
+ ]
159
+
160
+ for candidate in candidates:
161
+ if candidate in graph:
162
+ return candidate
163
+
164
+ return name
165
+
166
+
133
167
  # check_type decorator not compatible with recursive calls
134
168
  def extract_calls(
135
169
  entry_point: str,
@@ -162,9 +196,7 @@ def extract_calls(
162
196
  for ent in Project().registered_elements
163
197
  }
164
198
 
165
- # PyCG is not exactly equivalent on Windows vs Linux wrt to graph keys
166
- if os.name == 'nt' and not entry_point.startswith('flows\\'):
167
- entry_point = f'flows\\{entry_point}'
199
+ entry_point = _resolve_graph_key(entry_point, graph)
168
200
 
169
201
  if entry_point in graph:
170
202
  for fn in graph[entry_point]:
@@ -183,7 +215,8 @@ def extract_calls(
183
215
  if verbose:
184
216
  print(f" >> ({entry_point}) function {fn['normed']} ⏩")
185
217
 
186
- extract_calls(fn['normed'], graph, calls)
218
+ next_point = _resolve_graph_key(fn['normed'], graph)
219
+ extract_calls(next_point, graph, calls)
187
220
 
188
221
 
189
222
  @check_type
@@ -214,13 +247,7 @@ def process_call_graph(
214
247
  raise FileNotFoundError('Ensure you are at the root of your OneCode project')
215
248
 
216
249
  statements = OrderedDict()
217
- entry_files = [
218
- filename for filename in iglob(
219
- os.path.join(project_path, 'flows', '**', '*.py'), recursive=True
220
- ) if filename != '__init__.py' and not filename.startswith(
221
- os.path.join(project_path, 'flows', 'onecode_ext')
222
- )
223
- ]
250
+ entry_files = get_call_graph_entry_files(project_path)
224
251
 
225
252
  cg = CallGraphGenerator(
226
253
  entry_files,
@@ -238,10 +265,7 @@ def process_call_graph(
238
265
  print(f"Processing {label}...")
239
266
 
240
267
  calls = []
241
- if os.name == 'nt':
242
- extract_calls(f"{file}.run", flow_graph, calls, verbose)
243
- else:
244
- extract_calls(f"flows.{file}.run", flow_graph, calls, verbose)
268
+ extract_calls(f"flows.{file}.run", flow_graph, calls, verbose)
245
269
 
246
270
  statements[label] = {
247
271
  "entry_point": file,
@@ -1,11 +1,12 @@
1
1
  # SPDX-FileCopyrightText: 2023-2024 DeepLime <contact@deeplime.io>
2
2
  # SPDX-License-Identifier: MIT
3
3
 
4
+ import ast
4
5
  import importlib
6
+ import json
5
7
  import os
6
8
  import sys
7
9
  from collections import OrderedDict
8
- from glob import iglob
9
10
  from pathlib import Path
10
11
  from types import ModuleType
11
12
  from typing import Dict, List, Optional, Union
@@ -16,6 +17,7 @@ from pycg.pycg import CallGraphGenerator
16
17
  from pycg.utils.constants import CALL_GRAPH_OP
17
18
 
18
19
  from ..base.decorator import check_type
20
+ from ..base.enums import Env
19
21
 
20
22
 
21
23
  @check_type
@@ -56,6 +58,101 @@ def register_ext_module(
56
58
  return module
57
59
 
58
60
 
61
+ def _is_onecode_ext_path(path: str) -> bool:
62
+ parts = path.replace('\\', '/').split('/')
63
+ return 'onecode_ext' in parts
64
+
65
+
66
+ def _resolve_relative_import(flow_py: str, node: ast.ImportFrom) -> List[str]:
67
+ base_dir = os.path.dirname(flow_py)
68
+ module_parts = node.module.split('.') if node.module else []
69
+ rel_path = os.path.normpath(
70
+ os.path.join(base_dir, *(['..'] * (node.level - 1)), *module_parts)
71
+ )
72
+
73
+ candidates = []
74
+ if os.path.isfile(rel_path + '.py'):
75
+ candidates.append(rel_path + '.py')
76
+ init_py = os.path.join(rel_path, '__init__.py')
77
+ if os.path.isfile(init_py):
78
+ candidates.append(init_py)
79
+
80
+ return [path for path in candidates if not _is_onecode_ext_path(path)]
81
+
82
+
83
+ def _collect_flow_helper_files(flow_files: List[str]) -> List[str]:
84
+ helpers = []
85
+ seen = set(os.path.abspath(path) for path in flow_files)
86
+
87
+ pending = list(flow_files)
88
+ while pending:
89
+ flow_py = pending.pop()
90
+ try:
91
+ with open(flow_py, 'r', encoding='utf-8') as f:
92
+ tree = ast.parse(f.read(), filename=flow_py)
93
+ except (OSError, SyntaxError, UnicodeDecodeError):
94
+ continue
95
+
96
+ for node in ast.walk(tree):
97
+ if not isinstance(node, ast.ImportFrom) or node.level == 0:
98
+ continue
99
+
100
+ for helper_py in _resolve_relative_import(flow_py, node):
101
+ helper_py = os.path.abspath(helper_py)
102
+ if helper_py in seen:
103
+ continue
104
+ seen.add(helper_py)
105
+ helpers.append(helper_py)
106
+ pending.append(helper_py)
107
+
108
+ return helpers
109
+
110
+
111
+ @check_type
112
+ def get_call_graph_entry_files(project_path: str) -> List[str]:
113
+ """
114
+ Return the Python entry files used for static call-graph analysis.
115
+
116
+ Analysis starts from ``main.py`` and includes only the flow scripts registered in
117
+ ``.onecode.json`` — the same flows executed at runtime by ``main.py`` — plus any
118
+ helper modules they import locally under ``flows/``. This avoids scanning unrelated
119
+ project files (e.g. ``.venv``, unused scripts, or data helpers).
120
+
121
+ Args:
122
+ project_path: Path to the root of the OneCode project.
123
+
124
+ Returns:
125
+ Absolute paths to the entry Python files.
126
+
127
+ Raises:
128
+ FileNotFoundError: if ``main.py`` or ``.onecode.json`` is missing.
129
+
130
+ """
131
+ project_path = os.path.abspath(project_path)
132
+ main_py = os.path.join(project_path, 'main.py')
133
+ if not os.path.isfile(main_py):
134
+ raise FileNotFoundError('main.py not found at project root')
135
+
136
+ config_file = os.path.join(project_path, Env.ONECODE_CONFIG_FILE)
137
+ if not os.path.isfile(config_file):
138
+ raise FileNotFoundError('Ensure you are at the root of your OneCode project')
139
+
140
+ entry_files = [main_py]
141
+ flow_files = []
142
+ with open(config_file, 'r') as f:
143
+ flows = json.load(f)
144
+
145
+ for flow in flows:
146
+ flow_py = os.path.join(project_path, 'flows', f"{flow['file']}.py")
147
+ if os.path.isfile(flow_py):
148
+ entry_files.append(flow_py)
149
+ flow_files.append(flow_py)
150
+
151
+ entry_files.extend(_collect_flow_helper_files(flow_files))
152
+
153
+ return entry_files
154
+
155
+
59
156
  @check_type
60
157
  def get_imported_modules(scripts_folder: str) -> List[str]:
61
158
  """
@@ -68,7 +165,7 @@ def get_imported_modules(scripts_folder: str) -> List[str]:
68
165
  List of modules names imported by the Python scripts.
69
166
 
70
167
  """
71
- entry_files = list(iglob(os.path.join(scripts_folder, '**', '*.py'), recursive=True))
168
+ entry_files = get_call_graph_entry_files(scripts_folder)
72
169
  cg = CallGraphGenerator(
73
170
  entry_files,
74
171
  scripts_folder,
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "onecode"
3
- version = "1.2.0"
3
+ version = "1.2.2"
4
4
  description = "Python skeleton and library for OneCode projects"
5
5
  readme = "README.md"
6
6
  authors = ["DeepLime <contact@deeplime.io>"]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes