packflow 0.4.0rc3__tar.gz → 0.4.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 (38) hide show
  1. {packflow-0.4.0rc3 → packflow-0.4.2}/PKG-INFO +28 -4
  2. {packflow-0.4.0rc3 → packflow-0.4.2}/README.md +12 -0
  3. {packflow-0.4.0rc3 → packflow-0.4.2}/pyproject.toml +33 -15
  4. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/backend/base.py +6 -2
  5. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/backend/configuration.py +1 -1
  6. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/cli.py +111 -8
  7. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/data/templates/minimal/README.md +1 -1
  8. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/data/templates/minimal/inference.py +9 -1
  9. packflow-0.4.0rc3/src/packflow/data/templates/minimal/test_inference.py → packflow-0.4.2/src/packflow/data/templates/minimal/tests.py +12 -10
  10. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/loaders/base.py +9 -1
  11. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/loaders/config.py +15 -20
  12. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/loaders/local.py +10 -3
  13. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/utils/data.py +22 -18
  14. packflow-0.4.0rc3/src/packflow/data/templates/minimal/validate.py +0 -30
  15. {packflow-0.4.0rc3 → packflow-0.4.2}/LICENSE +0 -0
  16. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/__init__.py +0 -0
  17. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/_frames.py +0 -0
  18. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/_splash.py +0 -0
  19. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/backend/__init__.py +0 -0
  20. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/backend/metrics.py +0 -0
  21. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/backend/preprocessors.py +0 -0
  22. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/backend/validation.py +0 -0
  23. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/constants.py +0 -0
  24. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/data/templates/minimal/LICENSE.txt +0 -0
  25. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/data/templates/minimal/MODEL_CARD.md +0 -0
  26. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/data/templates/minimal/packflow.yaml +0 -0
  27. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/data/templates/minimal/requirements.txt +0 -0
  28. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/exceptions.py +0 -0
  29. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/loaders/__init__.py +0 -0
  30. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/loaders/module.py +0 -0
  31. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/loaders/utils.py +0 -0
  32. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/logger.py +0 -0
  33. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/project.py +0 -0
  34. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/utils/__init__.py +0 -0
  35. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/utils/normalize/__init__.py +0 -0
  36. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/utils/normalize/base.py +0 -0
  37. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/utils/normalize/handlers.py +0 -0
  38. {packflow-0.4.0rc3 → packflow-0.4.2}/src/packflow/utils/normalize/normalize.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: packflow
3
- Version: 0.4.0rc3
3
+ Version: 0.4.2
4
4
  Summary: AI/ML inference SDK for streaming data
5
5
  License: MIT License
6
6
 
@@ -17,7 +17,7 @@ Author: CDAO Models as a Service
17
17
  Author-email: osd.pentagon.cdao.mbx.perceptor-program-members@mail.mil
18
18
  Maintainer: CDAO Models as a Service
19
19
  Maintainer-email: osd.pentagon.cdao.mbx.perceptor-program-members@mail.mil
20
- Requires-Python: >=3.10
20
+ Requires-Python: >=3.10,<3.15
21
21
  Classifier: Development Status :: 4 - Beta
22
22
  Classifier: Intended Audience :: Developers
23
23
  Classifier: Intended Audience :: Science/Research
@@ -27,19 +27,31 @@ Classifier: Programming Language :: Python :: 3
27
27
  Classifier: Programming Language :: Python :: 3.10
28
28
  Classifier: Programming Language :: Python :: 3.11
29
29
  Classifier: Programming Language :: Python :: 3.12
30
+ Classifier: Programming Language :: Python :: 3.13
31
+ Classifier: Programming Language :: Python :: 3.14
30
32
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
31
33
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
32
34
  Classifier: Topic :: System :: Distributed Computing
35
+ Provides-Extra: dev
33
36
  Requires-Dist: PyYaml (>=6.0)
37
+ Requires-Dist: black[jupyter] (>=25.1.0) ; extra == "dev"
34
38
  Requires-Dist: click (>=8.0.0)
39
+ Requires-Dist: codespell (>=2.3.0) ; extra == "dev"
35
40
  Requires-Dist: deepmerge (>=2.0,<3.0)
36
41
  Requires-Dist: flatten-dict (>=0.4.2,<1.0.0)
37
42
  Requires-Dist: loguru (>=0.7.3,<0.8.0)
38
- Requires-Dist: numpy (<2.3)
43
+ Requires-Dist: numpy (<3)
39
44
  Requires-Dist: packaging (>=21.0)
45
+ Requires-Dist: pandas (>=2.3.0) ; extra == "dev"
40
46
  Requires-Dist: pathspec (>=0.12.0,<2.0.0)
47
+ Requires-Dist: pillow (>=11.3.0) ; extra == "dev"
48
+ Requires-Dist: pre-commit (>=4.2.0) ; extra == "dev"
41
49
  Requires-Dist: pydantic (>=2.11.0,<3.0.0)
42
- Project-URL: Documentation, https://github.com/dow-cdao/packflow
50
+ Requires-Dist: pytest (>=8.4.1) ; extra == "dev"
51
+ Requires-Dist: pytest-cov (>=6.2.1) ; extra == "dev"
52
+ Requires-Dist: questionary (>=2.1.0,<3.0.0)
53
+ Requires-Dist: torch (>=2.12.0) ; extra == "dev"
54
+ Project-URL: Documentation, https://dow-cdao.github.io/packflow/
43
55
  Project-URL: Homepage, https://github.com/dow-cdao/packflow
44
56
  Project-URL: Repository, https://github.com/dow-cdao/packflow
45
57
  Description-Content-Type: text/markdown
@@ -143,10 +155,22 @@ backend({"sample": "data"})
143
155
 
144
156
  ## Recent Changes
145
157
 
158
+ ### 0.4.1
159
+
160
+ - Expanded NumPy compatibility to support releases providing Python 3.14 wheels.
161
+ - Added Python 3.13 and 3.14 to the supported runtime metadata.
162
+
146
163
  ### 0.4.0
147
164
 
148
165
  Recent updates include improvements to configuration structure and new CLI capabilities:
149
166
 
167
+ - **New:** Interactive `packflow create` command with guided prompts for project setup
168
+ - Renamed `backend.validate()` to `backend.check_io()` for clarity
169
+ - Project templates simplified for better first-run experience
170
+ - Added `tests.py` to project templates with integrated validation and testing
171
+ - Removed standalone `validate.py` from templates
172
+ - Default `PackflowConfig` version now set to `0.1.0` when not specified
173
+ - Added `questionary` dependency for interactive CLI prompts
150
174
  - Custom configuration keys in `packflow.yaml` should now be placed under an `extra:` field for cleaner validation
151
175
  - Backend configuration can now be defined directly in `packflow.yaml` instead of separate JSON files
152
176
  - Name validation relaxed to allow numbers and hyphens (not as first character)
@@ -97,10 +97,22 @@ backend({"sample": "data"})
97
97
 
98
98
  ## Recent Changes
99
99
 
100
+ ### 0.4.1
101
+
102
+ - Expanded NumPy compatibility to support releases providing Python 3.14 wheels.
103
+ - Added Python 3.13 and 3.14 to the supported runtime metadata.
104
+
100
105
  ### 0.4.0
101
106
 
102
107
  Recent updates include improvements to configuration structure and new CLI capabilities:
103
108
 
109
+ - **New:** Interactive `packflow create` command with guided prompts for project setup
110
+ - Renamed `backend.validate()` to `backend.check_io()` for clarity
111
+ - Project templates simplified for better first-run experience
112
+ - Added `tests.py` to project templates with integrated validation and testing
113
+ - Removed standalone `validate.py` from templates
114
+ - Default `PackflowConfig` version now set to `0.1.0` when not specified
115
+ - Added `questionary` dependency for interactive CLI prompts
104
116
  - Custom configuration keys in `packflow.yaml` should now be placed under an `extra:` field for cleaner validation
105
117
  - Backend configuration can now be defined directly in `packflow.yaml` instead of separate JSON files
106
118
  - Name validation relaxed to allow numbers and hyphens (not as first character)
@@ -18,7 +18,7 @@ keywords = [
18
18
  ]
19
19
  license = { file = "LICENSE" }
20
20
  readme = "README.md"
21
- requires-python = ">=3.10"
21
+ requires-python = ">=3.10,<3.15"
22
22
  classifiers = [
23
23
  "Development Status :: 4 - Beta",
24
24
  "Intended Audience :: Developers",
@@ -29,6 +29,8 @@ classifiers = [
29
29
  "Programming Language :: Python :: 3.10",
30
30
  "Programming Language :: Python :: 3.11",
31
31
  "Programming Language :: Python :: 3.12",
32
+ "Programming Language :: Python :: 3.13",
33
+ "Programming Language :: Python :: 3.14",
32
34
  "Topic :: Scientific/Engineering :: Artificial Intelligence",
33
35
  "Topic :: Software Development :: Libraries :: Python Modules",
34
36
  "Topic :: System :: Distributed Computing",
@@ -37,18 +39,43 @@ dependencies = [
37
39
  "deepmerge>=2.0,<3.0",
38
40
  "flatten-dict>=0.4.2,<1.0.0",
39
41
  "loguru>=0.7.3,<0.8.0",
40
- "numpy<2.3",
42
+ "numpy<3",
41
43
  "packaging>=21.0",
42
44
  "pydantic>=2.11.0,<3.0.0",
43
45
  "click>=8.0.0",
44
46
  "pathspec>=0.12.0,<2.0.0",
45
- "PyYaml>=6.0"
47
+ "PyYaml>=6.0",
48
+ "questionary>=2.1.0,<3.0.0"
46
49
  ]
47
50
 
51
+ [project.optional-dependencies]
52
+ # NOTE: Keep synchronized with [tool.poetry.group.dev.dependencies] below
53
+ dev = [
54
+ "pre-commit>=4.2.0",
55
+ "black[jupyter]>=25.1.0",
56
+ "codespell>=2.3.0",
57
+ "pytest>=8.4.1",
58
+ "pytest-cov>=6.2.1",
59
+ "pandas>=2.3.0",
60
+ "torch>=2.12.0",
61
+ "pillow>=11.3.0"
62
+ ]
63
+
64
+ [tool.poetry.group.dev.dependencies]
65
+ # NOTE: Keep synchronized with [project.optional-dependencies] above
66
+ pre-commit = "^4.2.0"
67
+ black = {version = "^25.1.0", extras = ["jupyter"]}
68
+ codespell = "^2.3.0"
69
+ pytest = "^8.4.1"
70
+ pytest-cov = "^6.2.1"
71
+ pandas = "^2.3.0"
72
+ torch = "^2.7.1"
73
+ pillow = "^11.3.0"
74
+
48
75
  [project.urls]
49
76
  homepage = "https://github.com/dow-cdao/packflow"
50
77
  repository = "https://github.com/dow-cdao/packflow"
51
- documentation = "https://github.com/dow-cdao/packflow"
78
+ documentation = "https://dow-cdao.github.io/packflow/"
52
79
 
53
80
 
54
81
  [build-system]
@@ -57,7 +84,7 @@ build-backend = "poetry.core.masonry.api"
57
84
 
58
85
 
59
86
  [tool.poetry]
60
- version = "0.4.0rc3"
87
+ version = "0.4.2"
61
88
  exclude = [
62
89
  "tests",
63
90
  "docs",
@@ -67,18 +94,9 @@ exclude = [
67
94
 
68
95
 
69
96
  [tool.poetry.dependencies]
70
- python = '>=3.10,<4.0'
97
+ python = '>=3.10,<3.15.0'
71
98
 
72
99
 
73
- [tool.poetry.group.dev.dependencies]
74
- pre-commit = "^4.2.0"
75
- black = {version = "^25.1.0", extras = ["jupyter"]}
76
- pytest = "^8.4.1"
77
- pytest-cov = "^6.2.1"
78
- pandas = "^2.3.0"
79
- torch = "^2.7.1"
80
- tensorflow = "^2.19.0"
81
- pillow = "^11.3.0"
82
100
 
83
101
 
84
102
  [tool.poetry.scripts]
@@ -230,14 +230,18 @@ class InferenceBackend(ABC):
230
230
  # """
231
231
  # return outputs
232
232
 
233
- def validate(self, inputs: Union[dict, List[dict]]) -> Union[dict, List[dict]]:
233
+ def check_io(self, inputs: Union[dict, List[dict]]) -> Union[dict, List[dict]]:
234
234
  """
235
- Run validations against the inference backend to ensure it meets API restrictions
235
+ Run sample data through the backend and check that outputs meet Packflow's I/O format requirements.
236
236
  """
237
237
  validator = InferenceBackendValidator(self)
238
238
 
239
239
  return validator.run(inputs)
240
240
 
241
+ def validate(self, inputs: Union[dict, List[dict]]) -> Union[dict, List[dict]]:
242
+ """Deprecated: use check_io() instead."""
243
+ return self.check_io(inputs)
244
+
241
245
  def get_metrics(self) -> ExecutionMetrics:
242
246
  """
243
247
  Utility for collecting user-defined metrics and validating their contents
@@ -31,7 +31,7 @@ class BackendConfig(BaseModel):
31
31
  nested_field_delimiter: str = "."
32
32
  ignore_delimiter_collisions: bool = False
33
33
 
34
- # Output metadata - declarative only; checked by backend.validate()
34
+ # Output metadata - declarative only; checked by backend.check_io()
35
35
  output_keys: List[str] = []
36
36
 
37
37
 
@@ -1,7 +1,9 @@
1
1
  import re
2
+ import subprocess
2
3
  import sys
3
4
 
4
5
  import click
6
+ import questionary
5
7
 
6
8
  import packflow
7
9
  from packflow.loaders.config import NAME_PATTERN, validate_for_export
@@ -22,6 +24,43 @@ def _error_message(msg: str):
22
24
  click.echo(f"{base} {msg}")
23
25
 
24
26
 
27
+ def _get_git_email():
28
+ try:
29
+ result = subprocess.run(
30
+ ["git", "config", "user.email"],
31
+ capture_output=True,
32
+ text=True,
33
+ timeout=5,
34
+ )
35
+ return result.stdout.strip() if result.returncode == 0 else ""
36
+ except Exception:
37
+ return ""
38
+
39
+
40
+ def _validate_name(name):
41
+ if not name or not name.strip():
42
+ return "Project name is required."
43
+ if not re.match(NAME_PATTERN, name):
44
+ return "Names must start with a letter and contain only letters, digits, hyphens, and underscores."
45
+ return True
46
+
47
+
48
+ def _print_next_steps(project_name):
49
+ click.echo()
50
+ click.echo(" Next steps:")
51
+ click.echo(f" cd {project_name}")
52
+ click.echo(
53
+ f" Edit inference.py {click.style('- implement the execute() method', dim=True)}"
54
+ )
55
+ click.echo(
56
+ f" packflow validate {click.style('- check project structure', dim=True)}"
57
+ )
58
+ click.echo(
59
+ f" packflow export {click.style('- package for distribution', dim=True)}"
60
+ )
61
+ click.echo()
62
+
63
+
25
64
  @click.group()
26
65
  @click.version_option(version=packflow.__version__, prog_name="packflow")
27
66
  def cli():
@@ -30,25 +69,89 @@ def cli():
30
69
 
31
70
 
32
71
  @cli.command()
33
- @click.argument("project_name", type=str)
72
+ @click.argument("project_name", type=str, required=False, default=None)
34
73
  @click.option(
35
74
  "-f",
36
75
  "--force",
37
76
  is_flag=True,
38
77
  help="Force initialization in a directory that already exists. No files will be deleted, but files may be overwritten.",
39
78
  )
40
- def create(project_name, force):
41
- """Initialize a new project from a template in the current working directory"""
42
- if not re.match(NAME_PATTERN, project_name):
79
+ @click.option(
80
+ "--no-input",
81
+ is_flag=True,
82
+ help="Use defaults for all prompts (for scripting and CI).",
83
+ )
84
+ def create(project_name, force, no_input):
85
+ """Initialize a new project from a template in the current working directory.
86
+
87
+ If PROJECT_NAME is omitted, an interactive setup wizard will guide project
88
+ creation. Pass --no-input to skip all prompts and use default values.
89
+ """
90
+ interactive = sys.stdin.isatty() and not no_input
91
+
92
+ if project_name and not re.match(NAME_PATTERN, project_name):
43
93
  _error_message(
44
94
  f"Invalid project name '{project_name}'. "
45
95
  f"Names must start with a letter and contain only letters, digits, hyphens, and underscores."
46
96
  )
47
97
  sys.exit(1)
48
98
 
99
+ if interactive:
100
+ from packflow._splash import roll_in
101
+
102
+ roll_in(force=True)
103
+ if not project_name:
104
+ click.echo(
105
+ click.style("=== Initializing ", fg="white", bold=True)
106
+ + click.style("New Packflow Project", fg="cyan", bold=True)
107
+ + click.style(" ===", fg="white", bold=True)
108
+ )
109
+ project_name = questionary.text(
110
+ "Project name:", validate=_validate_name
111
+ ).ask()
112
+ if project_name is None:
113
+ sys.exit(1)
114
+ else:
115
+ click.echo(
116
+ click.style("=== Initializing ", fg="white", bold=True)
117
+ + click.style(project_name, fg="cyan", bold=True)
118
+ + click.style(" ===", fg="white", bold=True)
119
+ )
120
+ description = questionary.text("Description:", default="").ask()
121
+ if description is None:
122
+ sys.exit(1)
123
+
124
+ version = questionary.text("Version:", default="0.1.0").ask()
125
+ if version is None:
126
+ sys.exit(1)
127
+
128
+ git_email = _get_git_email()
129
+ maintainer = questionary.text("Maintainer email:", default=git_email).ask()
130
+ if maintainer is None:
131
+ sys.exit(1)
132
+
133
+ config_data = {}
134
+ if version:
135
+ config_data["version"] = version
136
+ if description:
137
+ config_data["description"] = description
138
+ if maintainer:
139
+ config_data["maintainers"] = [maintainer]
140
+ else:
141
+ if not project_name:
142
+ _error_message(
143
+ "Project name is required in non-interactive mode. "
144
+ "Usage: packflow create PROJECT_NAME [--no-input]"
145
+ )
146
+ sys.exit(1)
147
+ config_data = {"version": "0.1.0"}
148
+
49
149
  try:
50
- project = packflow.PackflowProject.create(project_name, force=force)
51
- _success_message(project)
150
+ project = packflow.PackflowProject.create(
151
+ project_name, force=force, config_data=config_data
152
+ )
153
+ _success_message(f"Created {project_name}/")
154
+ _print_next_steps(project_name)
52
155
  except Exception as e:
53
156
  _error_message(str(e))
54
157
  sys.exit(1)
@@ -63,7 +166,7 @@ def create(project_name, force):
63
166
  help="Show detailed validation checks during export.",
64
167
  )
65
168
  def export(project_path, verbose):
66
- """Save the package and export to .zip in the current working directory"""
169
+ """Package the project as a distributable .zip archive."""
67
170
  try:
68
171
  project = packflow.PackflowProject(project_path)
69
172
  output_file = project.export(verbose=verbose)
@@ -137,7 +240,7 @@ def validate(project_path, verbose, no_warnings):
137
240
  click.echo() # Blank line before individual violations
138
241
  for warning in warnings:
139
242
  _warning_message(warning)
140
- _success_message("All validation checks passed.")
243
+ _success_message("Validation passed with warnings.")
141
244
  else:
142
245
  _success_message("All validation checks passed.")
143
246
 
@@ -18,5 +18,5 @@ Install it separately:
18
18
 
19
19
  ```bash
20
20
  pip install pytest
21
- pytest test_inference.py
21
+ pytest tests.py
22
22
  ```
@@ -51,7 +51,15 @@ class Backend(InferenceBackend):
51
51
  metrics, converting outputs back to Python types, and other postprocessing steps. Try
52
52
  to keep this method focused purely on inference/analysis.
53
53
  """
54
- raise NotImplementedError
54
+
55
+ # Replace this with inference logic.
56
+ # `inputs` is a list of dicts; return a list of dicts the same length.
57
+
58
+ # For example, if a model takes single inputs at a time:
59
+ def model(x):
60
+ return x
61
+
62
+ return [model(item) for item in inputs]
55
63
 
56
64
  def transform_outputs(self, outputs):
57
65
  """Postprocessing steps or other transformation steps to be executed prior to
@@ -1,5 +1,5 @@
1
- # A starting point for testing the Inference Backend with pytest. The fixture below handles loading the backend
2
- # from packflow.yaml - add test cases to verify the backend behaves as expected for this analytic.
1
+ # Run with: pytest tests.py
2
+ # (pytest is not included in requirements.txt - install it separately)
3
3
  import pytest
4
4
  from packflow.loaders import LocalLoader
5
5
 
@@ -15,14 +15,16 @@ def test_backend_loads(backend):
15
15
  assert backend is not None
16
16
 
17
17
 
18
- # Uncomment and add input data to test backend behavior.
19
- # def test_backend_validate(backend):
20
- # sample_inputs = [
21
- # {"example_field": "example_value"},
22
- # ]
23
- # outputs = backend.validate(sample_inputs)
24
- # assert outputs is not None
25
- #
18
+ def test_check_io(backend):
19
+ """Backend I/O passes Packflow's format checks."""
20
+ sample_inputs = [
21
+ {"example_field": "example_value"},
22
+ ]
23
+ outputs = backend.check_io(sample_inputs)
24
+ assert outputs is not None
25
+
26
+
26
27
  # def test_backend_output_values(backend):
28
+ # """Verify specific output values for known inputs."""
27
29
  # outputs = backend([{"example_field": "example_value"}])
28
30
  # assert outputs[0]["expected_field"] == "expected_value"
@@ -1,4 +1,5 @@
1
1
  from abc import ABC, abstractmethod
2
+ import sys
2
3
  from pathlib import Path
3
4
  from typing import Union
4
5
 
@@ -77,8 +78,15 @@ class InferenceBackendLoader(ABC):
77
78
  config = PackflowConfig.from_project_path(project_path)
78
79
  apply_env_vars(config)
79
80
 
81
+ # Make the project root importable so sibling imports inside the
82
+ # backend module (LocalLoader) and top-level module lookups
83
+ # (ModuleLoader) resolve regardless of the caller's CWD.
84
+ project_path_str = str(project_path)
85
+ if project_path_str not in sys.path:
86
+ sys.path.insert(0, project_path_str)
87
+
80
88
  if config.loader == "local":
81
- loader = LocalLoader(config.inference_backend)
89
+ loader = LocalLoader(config.inference_backend, base_dir=project_path)
82
90
  elif config.loader == "module":
83
91
  loader = ModuleLoader(config.inference_backend)
84
92
  else:
@@ -40,7 +40,7 @@ class PackflowConfig(BaseModel):
40
40
  model_config = ConfigDict(extra="forbid")
41
41
 
42
42
  name: NameStr
43
- version: str = ""
43
+ version: str = "0.1.0"
44
44
  description: str = ""
45
45
  maintainers: list[str] = []
46
46
 
@@ -112,7 +112,8 @@ def apply_env_vars(config: "PackflowConfig") -> None:
112
112
  """
113
113
  Apply environment variables from the packflow.yaml env section.
114
114
 
115
- Warns when a key is already set in the environment with a different value.
115
+ Existing environment variables take precedence; packflow.yaml values serve
116
+ as defaults when a key is not already defined in the environment.
116
117
  """
117
118
  from packflow.logger import get_logger
118
119
 
@@ -120,12 +121,14 @@ def apply_env_vars(config: "PackflowConfig") -> None:
120
121
 
121
122
  for key, value in config.env.items():
122
123
  existing = os.environ.get(key)
123
- if existing is not None and existing != value:
124
- logger.warning(
125
- f"Overwriting existing environment variable '{key}' "
126
- f"(current: '{existing}', packflow.yaml: '{value}')"
127
- )
128
- os.environ[key] = value
124
+ if existing is not None:
125
+ if existing != value:
126
+ logger.debug(
127
+ f"Preserving existing environment variable '{key}' "
128
+ f"(current: '{existing}', packflow.yaml default: '{value}')"
129
+ )
130
+ else:
131
+ os.environ[key] = str(value)
129
132
 
130
133
 
131
134
  def validate_for_export(
@@ -250,8 +253,6 @@ def _validate_inference_backend(
250
253
  import contextlib
251
254
  import os
252
255
 
253
- original_cwd = os.getcwd()
254
-
255
256
  # Context manager to suppress stdout/stderr and logging during smoke tests
256
257
  @contextlib.contextmanager
257
258
  def suppress_output():
@@ -301,10 +302,8 @@ def _validate_inference_backend(
301
302
  try:
302
303
  from packflow.loaders.local import LocalLoader
303
304
 
304
- # Change to project directory for local imports
305
- os.chdir(project_dir)
306
305
  with suppress_output():
307
- loader = LocalLoader(config.inference_backend)
306
+ loader = LocalLoader(config.inference_backend, base_dir=project_dir)
308
307
  backend_class = loader.load_backend_module()
309
308
  if verbose:
310
309
  click.echo(
@@ -315,8 +314,6 @@ def _validate_inference_backend(
315
314
  errors.append(error_msg)
316
315
  if verbose:
317
316
  click.echo(f" {click.style('✗', fg='red')} {error_msg}")
318
- finally:
319
- os.chdir(original_cwd)
320
317
 
321
318
  elif config.loader == "module":
322
319
  if verbose:
@@ -343,8 +340,7 @@ def _validate_inference_backend(
343
340
  try:
344
341
  from packflow.loaders.base import InferenceBackendLoader
345
342
 
346
- # Change to project directory for local imports
347
- os.chdir(project_dir)
343
+ # from_project now resolves paths against project_dir; no chdir needed.
348
344
  with suppress_output():
349
345
  backend = InferenceBackendLoader.from_project(project_dir)
350
346
  if verbose:
@@ -356,8 +352,6 @@ def _validate_inference_backend(
356
352
  errors.append(error_msg)
357
353
  if verbose:
358
354
  click.echo(f" {click.style('✗', fg='red')} {error_msg}")
359
- finally:
360
- os.chdir(original_cwd)
361
355
 
362
356
  # Format errors with context about which test failed
363
357
  formatted_errors = []
@@ -420,7 +414,8 @@ def _load_raw_packaging_config(base_dir: Union[str, Path]) -> dict:
420
414
  return yaml.safe_load(f)
421
415
  except FileNotFoundError:
422
416
  raise FileNotFoundError(
423
- f"Not a valid packflow project: {packaging_config} does not exist"
417
+ f"Not a packflow project (no packflow.yaml found in {base_dir}). "
418
+ f"Run 'packflow create <name>' to start one."
424
419
  )
425
420
 
426
421
 
@@ -3,6 +3,7 @@ import importlib.util
3
3
  from pathlib import Path
4
4
  import sys
5
5
  from types import ModuleType
6
+ from typing import Union
6
7
 
7
8
  from .base import InferenceBackendLoader
8
9
  from .. import InferenceBackend
@@ -10,8 +11,12 @@ from .utils import inference_backend_parts
10
11
 
11
12
 
12
13
  class LocalLoader(InferenceBackendLoader):
14
+ def __init__(self, path: str, base_dir: Union[str, Path] = "."):
15
+ super().__init__(path)
16
+ self.base_dir = Path(base_dir).resolve()
17
+
13
18
  @staticmethod
14
- def _dot_notation_to_pypath(path: str) -> str:
19
+ def _dot_notation_to_pypath(path: str, base_dir: Union[str, Path] = ".") -> str:
15
20
  """
16
21
  Convert a dotted-path like 'foo.bar' to a file path to a python module
17
22
 
@@ -19,11 +24,13 @@ class LocalLoader(InferenceBackendLoader):
19
24
  ----------
20
25
  path : str
21
26
  The path to the module in dot notation
27
+ base_dir : str or Path
28
+ Directory the module path is resolved against. Defaults to CWD.
22
29
 
23
30
  """
24
31
  module = path.replace(".", "/")
25
32
 
26
- return str(Path(module).with_suffix(".py").resolve())
33
+ return str((Path(base_dir) / module).with_suffix(".py").resolve())
27
34
 
28
35
  @staticmethod
29
36
  def _import_module_from_source(path: str) -> ModuleType:
@@ -48,7 +55,7 @@ class LocalLoader(InferenceBackendLoader):
48
55
  def load_backend_module(self, **backend_kwargs) -> InferenceBackend:
49
56
  module_name, obj_name = inference_backend_parts(self.path)
50
57
 
51
- module_path = self._dot_notation_to_pypath(module_name)
58
+ module_path = self._dot_notation_to_pypath(module_name, self.base_dir)
52
59
 
53
60
  module = self._import_module_from_source(module_path)
54
61
 
@@ -2,14 +2,14 @@ import functools
2
2
  from typing import Any, List, Optional
3
3
 
4
4
  import numpy as np
5
- from flatten_dict import flatten, unflatten
5
+ from flatten_dict import flatten
6
6
  from flatten_dict.reducers import make_reducer
7
7
 
8
8
 
9
9
  def check_delimiter_collisions(obj: dict, delimiter: str, path: str = "") -> List[str]:
10
10
  """
11
11
  Recursively check for keys containing the delimiter character.
12
-
12
+
13
13
  Parameters
14
14
  ----------
15
15
  obj : dict
@@ -18,23 +18,25 @@ def check_delimiter_collisions(obj: dict, delimiter: str, path: str = "") -> Lis
18
18
  The delimiter character to check for
19
19
  path : str
20
20
  Current path (for recursive calls)
21
-
21
+
22
22
  Returns
23
23
  -------
24
24
  List[str]
25
25
  List of paths where delimiter collisions were found
26
26
  """
27
27
  collisions = []
28
-
28
+
29
29
  for key, value in obj.items():
30
30
  current_path = f"{path}{delimiter}{key}" if path else key
31
-
31
+
32
32
  if delimiter in key:
33
33
  collisions.append(current_path)
34
-
34
+
35
35
  if isinstance(value, dict):
36
- collisions.extend(check_delimiter_collisions(value, delimiter, current_path))
37
-
36
+ collisions.extend(
37
+ check_delimiter_collisions(value, delimiter, current_path)
38
+ )
39
+
38
40
  return collisions
39
41
 
40
42
 
@@ -42,7 +44,7 @@ def get_nested_field_direct(obj: dict, field: str, delimiter: str = ".") -> Any:
42
44
  """
43
45
  Retrieves a nested field by traversing the dictionary structure directly.
44
46
  Does not use flattening, preserving keys that contain the delimiter.
45
-
47
+
46
48
  Parameters
47
49
  ----------
48
50
  obj : dict
@@ -51,7 +53,7 @@ def get_nested_field_direct(obj: dict, field: str, delimiter: str = ".") -> Any:
51
53
  Field path using delimiter notation (e.g., "a.b.c")
52
54
  delimiter : str
53
55
  Delimiter to split the field path
54
-
56
+
55
57
  Returns
56
58
  -------
57
59
  Any
@@ -60,24 +62,26 @@ def get_nested_field_direct(obj: dict, field: str, delimiter: str = ".") -> Any:
60
62
  # First check if the field exists as a literal key
61
63
  if field in obj:
62
64
  return obj[field]
63
-
65
+
64
66
  # Otherwise, traverse the nested structure
65
67
  parts = field.split(delimiter)
66
68
  current = obj
67
-
69
+
68
70
  for part in parts:
69
71
  if not isinstance(current, dict) or part not in current:
70
72
  return None
71
73
  current = current[part]
72
-
74
+
73
75
  return current
74
76
 
75
77
 
76
- def set_nested_field_direct(obj: dict, field: str, value: Any, delimiter: str = ".") -> None:
78
+ def set_nested_field_direct(
79
+ obj: dict, field: str, value: Any, delimiter: str = "."
80
+ ) -> None:
77
81
  """
78
82
  Sets a nested field by creating the nested structure directly.
79
83
  Does not use flattening/unflattening.
80
-
84
+
81
85
  Parameters
82
86
  ----------
83
87
  obj : dict
@@ -91,7 +95,7 @@ def set_nested_field_direct(obj: dict, field: str, value: Any, delimiter: str =
91
95
  """
92
96
  parts = field.split(delimiter)
93
97
  current = obj
94
-
98
+
95
99
  # Navigate/create the nested structure
96
100
  for part in parts[:-1]:
97
101
  if part not in current:
@@ -100,7 +104,7 @@ def set_nested_field_direct(obj: dict, field: str, value: Any, delimiter: str =
100
104
  # Can't traverse further if we hit a non-dict value
101
105
  return
102
106
  current = current[part]
103
-
107
+
104
108
  # Set the final value
105
109
  current[parts[-1]] = value
106
110
 
@@ -140,7 +144,7 @@ def records_to_ndarray(
140
144
  delimiter: Optional[str] = None,
141
145
  ) -> np.ndarray:
142
146
  """
143
- Converts records to a numpy nd array
147
+ Converts records to a numpy.ndarray
144
148
 
145
149
  Example
146
150
  -------
@@ -1,30 +0,0 @@
1
- # validate.py - checks that the backend's inputs and outputs are in the format
2
- # Packflow expects (correct types, matching row counts, JSON-serializable values).
3
- #
4
- # This is NOT a test of analytic logic or accuracy. Write test cases specific
5
- # to the expected behavior of the backend to verify correctness.
6
- from packflow.loaders import LocalLoader
7
-
8
- # Load the backend in the current directory
9
- # The path 'inference:Backend' can be interpreted as
10
- # `from inference import Backend`
11
- backend = LocalLoader("inference:Backend").load()
12
-
13
- # Define sample inputs that represent realistic data for the backend.
14
- # These should exercise the expected input format(s) the backend will receive.
15
- SAMPLE_INPUTS = [
16
- # Replace with data structured to match this backend's expected input.
17
- # The placeholder below will likely fail - update before running.
18
- {"example_field": "example_value"},
19
- ]
20
-
21
- if __name__ == "__main__":
22
- print("Running validation...")
23
- print(f"Sample inputs: {SAMPLE_INPUTS}\n")
24
-
25
- # Checks output structure (format, row count, serializaibility).
26
- # Returns outputs if valid.
27
- outputs = backend.validate(SAMPLE_INPUTS)
28
-
29
- print(f"Outputs: {outputs}")
30
- print("\nValidation passed!")
File without changes