packflow 0.4.0rc2__tar.gz → 0.4.1__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.
- {packflow-0.4.0rc2 → packflow-0.4.1}/PKG-INFO +51 -5
- {packflow-0.4.0rc2 → packflow-0.4.1}/README.md +33 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/pyproject.toml +40 -21
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/backend/base.py +6 -2
- packflow-0.4.1/src/packflow/backend/configuration.py +67 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/backend/validation.py +19 -1
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/cli.py +114 -9
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/constants.py +0 -1
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/data/templates/minimal/README.md +1 -1
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/data/templates/minimal/inference.py +9 -1
- packflow-0.4.0rc2/src/packflow/data/templates/minimal/test_inference.py → packflow-0.4.1/src/packflow/data/templates/minimal/tests.py +12 -10
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/loaders/base.py +14 -3
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/loaders/config.py +43 -36
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/loaders/local.py +10 -3
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/project.py +25 -10
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/utils/data.py +22 -18
- packflow-0.4.0rc2/src/packflow/backend/configuration.py +0 -153
- packflow-0.4.0rc2/src/packflow/data/templates/minimal/validate.py +0 -30
- {packflow-0.4.0rc2 → packflow-0.4.1}/LICENSE +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/__init__.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/_frames.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/_splash.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/backend/__init__.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/backend/metrics.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/backend/preprocessors.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/data/templates/minimal/LICENSE.txt +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/data/templates/minimal/MODEL_CARD.md +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/data/templates/minimal/packflow.yaml +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/data/templates/minimal/requirements.txt +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/exceptions.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/loaders/__init__.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/loaders/module.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/loaders/utils.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/logger.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/utils/__init__.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/utils/normalize/__init__.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/utils/normalize/base.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/src/packflow/utils/normalize/handlers.py +0 -0
- {packflow-0.4.0rc2 → packflow-0.4.1}/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.
|
|
3
|
+
Version: 0.4.1
|
|
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,18 +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
|
|
33
|
-
|
|
35
|
+
Provides-Extra: dev
|
|
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 (<
|
|
43
|
+
Requires-Dist: numpy (<3)
|
|
44
|
+
Requires-Dist: packaging (>=21.0)
|
|
45
|
+
Requires-Dist: pandas (>=2.3.0) ; extra == "dev"
|
|
39
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"
|
|
40
49
|
Requires-Dist: pydantic (>=2.11.0,<3.0.0)
|
|
41
|
-
|
|
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/
|
|
42
55
|
Project-URL: Homepage, https://github.com/dow-cdao/packflow
|
|
43
56
|
Project-URL: Repository, https://github.com/dow-cdao/packflow
|
|
44
57
|
Description-Content-Type: text/markdown
|
|
@@ -140,6 +153,39 @@ backend({"sample": "data"})
|
|
|
140
153
|
# >> {"sample": "data"}
|
|
141
154
|
```
|
|
142
155
|
|
|
156
|
+
## Recent Changes
|
|
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
|
+
|
|
163
|
+
### 0.4.0
|
|
164
|
+
|
|
165
|
+
Recent updates include improvements to configuration structure and new CLI capabilities:
|
|
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
|
|
174
|
+
- Custom configuration keys in `packflow.yaml` should now be placed under an `extra:` field for cleaner validation
|
|
175
|
+
- Backend configuration can now be defined directly in `packflow.yaml` instead of separate JSON files
|
|
176
|
+
- Name validation relaxed to allow numbers and hyphens (not as first character)
|
|
177
|
+
- New `packflow validate` and `packflow --version` commands
|
|
178
|
+
- Environment variables can be specified in `packflow.yaml` and are set automatically during packflow operations
|
|
179
|
+
- `packflow export` now respects `.gitignore` patterns
|
|
180
|
+
- `verbose` defaults to `false` to reduce log output
|
|
181
|
+
- Backend configuration supports `output_keys` field to declare expected output fields
|
|
182
|
+
|
|
183
|
+
For projects using custom top-level keys in `packflow.yaml`, nest them under `extra:` to maintain compatibility with current validation.
|
|
184
|
+
|
|
185
|
+
### 0.3.0
|
|
186
|
+
|
|
187
|
+
- Initial release
|
|
188
|
+
|
|
143
189
|
## Contributing
|
|
144
190
|
|
|
145
191
|
Contributions to Packflow are welcomed and highly encouraged! Please refer to the [CONTRIBUTING.md](https://github.com/dow-cdao/packflow/blob/master/CONTRIBUTING.md) guide for more information and guidelines for contributing to Packflow.
|
|
@@ -95,6 +95,39 @@ backend({"sample": "data"})
|
|
|
95
95
|
# >> {"sample": "data"}
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
+
## Recent Changes
|
|
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
|
+
|
|
105
|
+
### 0.4.0
|
|
106
|
+
|
|
107
|
+
Recent updates include improvements to configuration structure and new CLI capabilities:
|
|
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
|
|
116
|
+
- Custom configuration keys in `packflow.yaml` should now be placed under an `extra:` field for cleaner validation
|
|
117
|
+
- Backend configuration can now be defined directly in `packflow.yaml` instead of separate JSON files
|
|
118
|
+
- Name validation relaxed to allow numbers and hyphens (not as first character)
|
|
119
|
+
- New `packflow validate` and `packflow --version` commands
|
|
120
|
+
- Environment variables can be specified in `packflow.yaml` and are set automatically during packflow operations
|
|
121
|
+
- `packflow export` now respects `.gitignore` patterns
|
|
122
|
+
- `verbose` defaults to `false` to reduce log output
|
|
123
|
+
- Backend configuration supports `output_keys` field to declare expected output fields
|
|
124
|
+
|
|
125
|
+
For projects using custom top-level keys in `packflow.yaml`, nest them under `extra:` to maintain compatibility with current validation.
|
|
126
|
+
|
|
127
|
+
### 0.3.0
|
|
128
|
+
|
|
129
|
+
- Initial release
|
|
130
|
+
|
|
98
131
|
## Contributing
|
|
99
132
|
|
|
100
133
|
Contributions to Packflow are welcomed and highly encouraged! Please refer to the [CONTRIBUTING.md](https://github.com/dow-cdao/packflow/blob/master/CONTRIBUTING.md) guide for more information and guidelines for contributing to Packflow.
|
|
@@ -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,25 +29,53 @@ 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",
|
|
35
37
|
]
|
|
36
38
|
dependencies = [
|
|
37
|
-
"deepmerge
|
|
38
|
-
"flatten-dict
|
|
39
|
-
"loguru
|
|
40
|
-
"numpy
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
39
|
+
"deepmerge>=2.0,<3.0",
|
|
40
|
+
"flatten-dict>=0.4.2,<1.0.0",
|
|
41
|
+
"loguru>=0.7.3,<0.8.0",
|
|
42
|
+
"numpy<3",
|
|
43
|
+
"packaging>=21.0",
|
|
44
|
+
"pydantic>=2.11.0,<3.0.0",
|
|
45
|
+
"click>=8.0.0",
|
|
46
|
+
"pathspec>=0.12.0,<2.0.0",
|
|
47
|
+
"PyYaml>=6.0",
|
|
48
|
+
"questionary>=2.1.0,<3.0.0"
|
|
45
49
|
]
|
|
46
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
|
+
|
|
47
75
|
[project.urls]
|
|
48
76
|
homepage = "https://github.com/dow-cdao/packflow"
|
|
49
77
|
repository = "https://github.com/dow-cdao/packflow"
|
|
50
|
-
documentation = "https://
|
|
78
|
+
documentation = "https://dow-cdao.github.io/packflow/"
|
|
51
79
|
|
|
52
80
|
|
|
53
81
|
[build-system]
|
|
@@ -56,7 +84,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
56
84
|
|
|
57
85
|
|
|
58
86
|
[tool.poetry]
|
|
59
|
-
version = "0.4.
|
|
87
|
+
version = "0.4.1"
|
|
60
88
|
exclude = [
|
|
61
89
|
"tests",
|
|
62
90
|
"docs",
|
|
@@ -66,18 +94,9 @@ exclude = [
|
|
|
66
94
|
|
|
67
95
|
|
|
68
96
|
[tool.poetry.dependencies]
|
|
69
|
-
python = '>=3.10,<
|
|
97
|
+
python = '>=3.10,<3.15.0'
|
|
70
98
|
|
|
71
99
|
|
|
72
|
-
[tool.poetry.group.dev.dependencies]
|
|
73
|
-
pre-commit = "^4.2.0"
|
|
74
|
-
black = {version = "^25.1.0", extras = ["jupyter"]}
|
|
75
|
-
pytest = "^8.4.1"
|
|
76
|
-
pytest-cov = "^6.2.1"
|
|
77
|
-
pandas = "^2.3.0"
|
|
78
|
-
torch = "^2.7.1"
|
|
79
|
-
tensorflow = "^2.19.0"
|
|
80
|
-
pillow = "^11.3.0"
|
|
81
100
|
|
|
82
101
|
|
|
83
102
|
[tool.poetry.scripts]
|
|
@@ -230,14 +230,18 @@ class InferenceBackend(ABC):
|
|
|
230
230
|
# """
|
|
231
231
|
# return outputs
|
|
232
232
|
|
|
233
|
-
def
|
|
233
|
+
def check_io(self, inputs: Union[dict, List[dict]]) -> Union[dict, List[dict]]:
|
|
234
234
|
"""
|
|
235
|
-
Run
|
|
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
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import enum
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
|
|
6
|
+
from packflow.logger import get_logger
|
|
7
|
+
|
|
8
|
+
logger = get_logger()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class InputFormats(enum.Enum):
|
|
12
|
+
"""See :ref:`Preprocessors<preprocessors>` for details."""
|
|
13
|
+
|
|
14
|
+
PASSTHROUGH = "passthrough"
|
|
15
|
+
RECORDS = "records"
|
|
16
|
+
NUMPY = "numpy"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class BackendConfig(BaseModel):
|
|
20
|
+
"""See :ref:`Backend Configuration<backend-configuration>` for details."""
|
|
21
|
+
|
|
22
|
+
# Base configurations - controls some runtime logging behaviors
|
|
23
|
+
verbose: bool = False
|
|
24
|
+
|
|
25
|
+
# Data Requirements - controls preprocessor behavior.
|
|
26
|
+
input_format: InputFormats = InputFormats.RECORDS
|
|
27
|
+
rename_fields: dict = {}
|
|
28
|
+
feature_names: List[str] = []
|
|
29
|
+
flatten_nested_inputs: bool = False
|
|
30
|
+
flatten_lists: bool = False
|
|
31
|
+
nested_field_delimiter: str = "."
|
|
32
|
+
ignore_delimiter_collisions: bool = False
|
|
33
|
+
|
|
34
|
+
# Output metadata - declarative only; checked by backend.check_io()
|
|
35
|
+
output_keys: List[str] = []
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def load_backend_configuration(
|
|
39
|
+
backend_config_model: BackendConfig | type[BackendConfig] = BackendConfig,
|
|
40
|
+
**backend_kwargs,
|
|
41
|
+
) -> BackendConfig:
|
|
42
|
+
"""
|
|
43
|
+
Loads and validates backend configuration.
|
|
44
|
+
|
|
45
|
+
Parameters
|
|
46
|
+
----------
|
|
47
|
+
backend_config_model : BackendConfig
|
|
48
|
+
An instance of, or a subclass of, a BackendConfig Model to use for validation.
|
|
49
|
+
Defaults to a base BackendConfig
|
|
50
|
+
|
|
51
|
+
**backend_kwargs
|
|
52
|
+
Keyword arguments used as configuration values. When loading from a packflow
|
|
53
|
+
project, these are populated from the ``backend_config`` section of
|
|
54
|
+
``packflow.yaml``, with any caller-supplied overrides merged on top.
|
|
55
|
+
|
|
56
|
+
Returns
|
|
57
|
+
-------
|
|
58
|
+
BackendConfig
|
|
59
|
+
A validated configuration model
|
|
60
|
+
"""
|
|
61
|
+
logger.debug(f"Loaded raw configuration: {backend_kwargs}")
|
|
62
|
+
|
|
63
|
+
validated_config = backend_config_model.model_validate(backend_kwargs)
|
|
64
|
+
|
|
65
|
+
logger.info(f"Configuration: {validated_config.__repr__()}")
|
|
66
|
+
|
|
67
|
+
return validated_config
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import Any, Callable, List, Union
|
|
3
3
|
|
|
4
4
|
import packflow.exceptions as exceptions
|
|
5
5
|
|
|
@@ -41,6 +41,10 @@ class InferenceBackendValidator:
|
|
|
41
41
|
|
|
42
42
|
_output_is_json_serializable(outputs)
|
|
43
43
|
|
|
44
|
+
_check_output_keys(
|
|
45
|
+
outputs, self.backend.config.output_keys, self.backend.logger
|
|
46
|
+
)
|
|
47
|
+
|
|
44
48
|
if input_is_dict:
|
|
45
49
|
outputs = outputs[0]
|
|
46
50
|
|
|
@@ -86,6 +90,20 @@ def _output_is_list_of_dicts(outputs: Any):
|
|
|
86
90
|
)
|
|
87
91
|
|
|
88
92
|
|
|
93
|
+
def _check_output_keys(outputs: List[dict], output_keys: List[str], logger) -> None:
|
|
94
|
+
"""Warns when declared output_keys are missing from actual output."""
|
|
95
|
+
if not output_keys:
|
|
96
|
+
return
|
|
97
|
+
|
|
98
|
+
declared = set(output_keys)
|
|
99
|
+
actual = set().union(*(record.keys() for record in outputs))
|
|
100
|
+
|
|
101
|
+
for key in sorted(declared - actual):
|
|
102
|
+
logger.warning(
|
|
103
|
+
f"output_keys: declared key '{key}' was not found in any output record"
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
89
107
|
def _output_is_json_serializable(outputs: Any):
|
|
90
108
|
"""Makes sure every row is json serializable and does not contain bad types"""
|
|
91
109
|
for i, v in enumerate(outputs):
|
|
@@ -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,27 +69,92 @@ 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
|
-
|
|
41
|
-
""
|
|
42
|
-
|
|
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)
|
|
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"}
|
|
48
148
|
|
|
49
149
|
try:
|
|
50
|
-
project = packflow.PackflowProject.create(
|
|
51
|
-
|
|
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))
|
|
157
|
+
sys.exit(1)
|
|
54
158
|
|
|
55
159
|
|
|
56
160
|
@cli.command()
|
|
@@ -62,7 +166,7 @@ def create(project_name, force):
|
|
|
62
166
|
help="Show detailed validation checks during export.",
|
|
63
167
|
)
|
|
64
168
|
def export(project_path, verbose):
|
|
65
|
-
"""
|
|
169
|
+
"""Package the project as a distributable .zip archive."""
|
|
66
170
|
try:
|
|
67
171
|
project = packflow.PackflowProject(project_path)
|
|
68
172
|
output_file = project.export(verbose=verbose)
|
|
@@ -71,6 +175,7 @@ def export(project_path, verbose):
|
|
|
71
175
|
_success_message(f"Saved Package to {output_file}")
|
|
72
176
|
except Exception as e:
|
|
73
177
|
_error_message(str(e))
|
|
178
|
+
sys.exit(1)
|
|
74
179
|
|
|
75
180
|
|
|
76
181
|
@cli.command()
|
|
@@ -135,7 +240,7 @@ def validate(project_path, verbose, no_warnings):
|
|
|
135
240
|
click.echo() # Blank line before individual violations
|
|
136
241
|
for warning in warnings:
|
|
137
242
|
_warning_message(warning)
|
|
138
|
-
_success_message("
|
|
243
|
+
_success_message("Validation passed with warnings.")
|
|
139
244
|
else:
|
|
140
245
|
_success_message("All validation checks passed.")
|
|
141
246
|
|
|
@@ -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
|
-
|
|
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
|
-
#
|
|
2
|
-
#
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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,10 +1,11 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
|
+
import sys
|
|
2
3
|
from pathlib import Path
|
|
3
4
|
from typing import Union
|
|
4
5
|
|
|
5
6
|
from packflow import InferenceBackend, exceptions
|
|
6
7
|
|
|
7
|
-
from .config import PackflowConfig
|
|
8
|
+
from .config import PackflowConfig, apply_env_vars
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
class InferenceBackendLoader(ABC):
|
|
@@ -75,12 +76,22 @@ class InferenceBackendLoader(ABC):
|
|
|
75
76
|
|
|
76
77
|
project_path = Path(project_path).resolve()
|
|
77
78
|
config = PackflowConfig.from_project_path(project_path)
|
|
79
|
+
apply_env_vars(config)
|
|
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)
|
|
78
87
|
|
|
79
88
|
if config.loader == "local":
|
|
80
|
-
loader = LocalLoader(config.inference_backend)
|
|
89
|
+
loader = LocalLoader(config.inference_backend, base_dir=project_path)
|
|
81
90
|
elif config.loader == "module":
|
|
82
91
|
loader = ModuleLoader(config.inference_backend)
|
|
83
92
|
else:
|
|
84
93
|
raise ValueError(f"Unknown loader type: {config.loader}")
|
|
85
94
|
|
|
86
|
-
|
|
95
|
+
# packflow.yaml backend_config is the base; explicit kwargs take priority
|
|
96
|
+
merged_kwargs = {**config.backend_config, **backend_kwargs}
|
|
97
|
+
return loader.load(**merged_kwargs)
|