monopack 0.1.0__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 (37) hide show
  1. monopack-0.1.0/LICENSE +21 -0
  2. monopack-0.1.0/PKG-INFO +144 -0
  3. monopack-0.1.0/README.md +120 -0
  4. monopack-0.1.0/pyproject.toml +41 -0
  5. monopack-0.1.0/setup.cfg +4 -0
  6. monopack-0.1.0/src/monopack/__init__.py +1 -0
  7. monopack-0.1.0/src/monopack/__main__.py +7 -0
  8. monopack-0.1.0/src/monopack/build.py +605 -0
  9. monopack-0.1.0/src/monopack/cli.py +153 -0
  10. monopack-0.1.0/src/monopack/discovery.py +19 -0
  11. monopack-0.1.0/src/monopack/graph.py +146 -0
  12. monopack-0.1.0/src/monopack/imports.py +172 -0
  13. monopack-0.1.0/src/monopack/inline_config.py +104 -0
  14. monopack-0.1.0/src/monopack/module_resolver.py +37 -0
  15. monopack-0.1.0/src/monopack/requirements.py +52 -0
  16. monopack-0.1.0/src/monopack/test_mode.py +119 -0
  17. monopack-0.1.0/src/monopack/validation.py +95 -0
  18. monopack-0.1.0/src/monopack/verifier.py +56 -0
  19. monopack-0.1.0/src/monopack.egg-info/PKG-INFO +144 -0
  20. monopack-0.1.0/src/monopack.egg-info/SOURCES.txt +35 -0
  21. monopack-0.1.0/src/monopack.egg-info/dependency_links.txt +1 -0
  22. monopack-0.1.0/src/monopack.egg-info/entry_points.txt +2 -0
  23. monopack-0.1.0/src/monopack.egg-info/requires.txt +4 -0
  24. monopack-0.1.0/src/monopack.egg-info/top_level.txt +1 -0
  25. monopack-0.1.0/tests/test_build.py +343 -0
  26. monopack-0.1.0/tests/test_build_integration.py +819 -0
  27. monopack-0.1.0/tests/test_cli.py +614 -0
  28. monopack-0.1.0/tests/test_cli_integration.py +266 -0
  29. monopack-0.1.0/tests/test_discovery.py +49 -0
  30. monopack-0.1.0/tests/test_graph.py +190 -0
  31. monopack-0.1.0/tests/test_imports.py +201 -0
  32. monopack-0.1.0/tests/test_inline_config.py +65 -0
  33. monopack-0.1.0/tests/test_module_resolver.py +75 -0
  34. monopack-0.1.0/tests/test_package.py +28 -0
  35. monopack-0.1.0/tests/test_requirements.py +87 -0
  36. monopack-0.1.0/tests/test_test_mode.py +104 -0
  37. monopack-0.1.0/tests/test_verifier.py +63 -0
monopack-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 monopack maintainers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: monopack
3
+ Version: 0.1.0
4
+ Summary: Build focused Python Lambda function bundles from source imports.
5
+ Author: monopack maintainers
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/atomraymaker/monopack
8
+ Project-URL: Repository, https://github.com/atomraymaker/monopack
9
+ Project-URL: Issues, https://github.com/atomraymaker/monopack/issues
10
+ Keywords: aws-lambda,build,dependency-analysis,packaging,python
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Software Development :: Build Tools
17
+ Requires-Python: >=3.12
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Provides-Extra: dev
21
+ Requires-Dist: build>=1.2.0; extra == "dev"
22
+ Requires-Dist: twine>=5.0.0; extra == "dev"
23
+ Dynamic: license-file
24
+
25
+ # monopack
26
+
27
+ `monopack` builds per-function Python Lambda bundles from a monolith-style repo.
28
+
29
+ ## Background
30
+
31
+ Go works well for multi-Lambda projects because one codebase can expose multiple `cmd` entrypoints and build each function with only what it needs.
32
+
33
+ Python workflows are usually less ergonomic at that scale:
34
+
35
+ - AWS SAM and Serverless framework commonly package one Python artifact per project.
36
+ - Per-function folder layouts can make shared code awkward.
37
+ - Workarounds such as local packages, symlinks, or copied shared folders often add maintenance overhead.
38
+
39
+ `monopack` is intended to make Python feel closer to that Go workflow without changing your project into N separate services. It takes a larger codebase and produces per-function zip artifacts by:
40
+
41
+ - tracing imports from each function entrypoint,
42
+ - copying reachable first-party files,
43
+ - deriving a minimal pinned `requirements.txt` subset for third-party imports,
44
+ - installing only that dependency subset into the build target,
45
+ - and running optional verification/tests to increase confidence that each split artifact works in isolation.
46
+
47
+ It is intentionally conservative: this is import-based trimming with guardrails, not full tree-shaking or whole-program optimization. It aims to cover common Python import patterns used in real projects, while keeping behavior explicit and testable.
48
+
49
+ ## What monopack does
50
+
51
+ - Builds one or many functions from `functions/*.py` into `build/<function_name>/`.
52
+ - In `deploy` mode, writes deploy zip artifacts at `build/<function_name>.zip`.
53
+ - In `deploy` mode, writes package digest helper file(s) (`build/<function_name>.package.sha256` by default).
54
+ - In `test` mode, copies relevant tests and runs them in the build target (no zip output).
55
+ - Uses pinned project `requirements.txt` (`name==version` lines only).
56
+ - Supports optional auto-fix for missing-module verification failures (`--auto-fix`, opt-in).
57
+
58
+ ## Quickstart
59
+
60
+ Project expectations:
61
+
62
+ - `functions/` directory with function entrypoint files (`<name>.py`).
63
+ - Project-level `requirements.txt` containing pinned `name==version` lines.
64
+ - Optional `tests/` directory when using `--mode test`.
65
+
66
+ Build one function in deploy mode:
67
+
68
+ ```bash
69
+ PYTHONPATH=src python -m monopack users_get \
70
+ --functions-dir functions \
71
+ --build-dir build
72
+ ```
73
+
74
+ Run confidence build in test mode:
75
+
76
+ ```bash
77
+ PYTHONPATH=src python -m monopack users_get \
78
+ --functions-dir functions \
79
+ --build-dir /tmp/monopack-build \
80
+ --mode test
81
+ ```
82
+
83
+ Build all functions discovered in `functions/*.py` (no target argument):
84
+
85
+ ```bash
86
+ PYTHONPATH=src python -m monopack \
87
+ --functions-dir functions \
88
+ --build-dir build
89
+ ```
90
+
91
+ ## CLI usage
92
+
93
+ Basic form:
94
+
95
+ ```bash
96
+ PYTHONPATH=src python -m monopack [function_name] [options]
97
+ ```
98
+
99
+ Key flags for real-project usage:
100
+
101
+ - `--version`: prints the installed `monopack` version and exits.
102
+ - `--mode deploy|test`: deploy builds runtime payload + zip; test builds payload + tests (no zip).
103
+ - `--with-tests`: deploy mode only; runs relevant tests before finalizing deploy payload.
104
+ - `--verify` / `--no-verify`: verifier is on by default.
105
+ - `--auto-fix`: opt-in auto-repair loop for missing imports during verify.
106
+ - `--sha-output`: comma-separated package digest outputs for deploy mode (`hex`, `b64`; default `hex`).
107
+
108
+ Package digest output guidance:
109
+
110
+ - `hex` (`.package.sha256`): general CI/script diffing and human-readable checks.
111
+ - `b64` (`.package.sha256.b64`): Terraform-style workflows that prefer base64 digest values.
112
+ - Use both when needed: `--sha-output hex,b64`.
113
+
114
+ For full argument behavior and validation details, see `docs/cli.md`.
115
+
116
+ ## Constraints and limits
117
+
118
+ - Function discovery is shallow: only `functions/*.py` (excluding names starting with `_`).
119
+ - Function names must use letters, numbers, and underscores; target names cannot include `/`, `\\`, or `.`.
120
+ - Build directory must differ from functions directory and cannot be nested inside it.
121
+ - Requirements parser accepts only pinned `name==version` lines (comments and blanks allowed).
122
+ - First-party graph traversal is limited to roots `functions`, `app`, and `lib` unless inline config adds modules.
123
+ - Auto-fix only handles `ModuleNotFoundError` flows and retries up to 3 times when enabled.
124
+
125
+ ## Recommended feedback loop for monolith split confidence
126
+
127
+ 1. Build the target in test mode with verification enabled:
128
+ `PYTHONPATH=src python -m monopack <function> --mode test --verify`.
129
+ 2. Inspect build output (`build/<function>/`) and generated `requirements.txt` for expected scope.
130
+ 3. Build deploy artifact once confidence is good:
131
+ `PYTHONPATH=src python -m monopack <function> --mode deploy`.
132
+ 4. Optionally gate deploy build with tests:
133
+ `PYTHONPATH=src python -m monopack <function> --mode deploy --with-tests`.
134
+ 5. Run repository tests to catch broader regressions:
135
+ `python -m unittest discover -s tests -v`.
136
+ 6. Tighten imports/tests/inline config and repeat until scoped build behavior is stable.
137
+
138
+ ## Deeper docs
139
+
140
+ - CLI reference: `docs/cli.md`
141
+ - PyPI publishing: `docs/publishing.md`
142
+ - Fixture-driven confidence loop and matrix: `docs/testing-fixtures.md`
143
+
144
+ For Terraform `source_code_hash` usage with generated package digests, see `docs/cli.md`.
@@ -0,0 +1,120 @@
1
+ # monopack
2
+
3
+ `monopack` builds per-function Python Lambda bundles from a monolith-style repo.
4
+
5
+ ## Background
6
+
7
+ Go works well for multi-Lambda projects because one codebase can expose multiple `cmd` entrypoints and build each function with only what it needs.
8
+
9
+ Python workflows are usually less ergonomic at that scale:
10
+
11
+ - AWS SAM and Serverless framework commonly package one Python artifact per project.
12
+ - Per-function folder layouts can make shared code awkward.
13
+ - Workarounds such as local packages, symlinks, or copied shared folders often add maintenance overhead.
14
+
15
+ `monopack` is intended to make Python feel closer to that Go workflow without changing your project into N separate services. It takes a larger codebase and produces per-function zip artifacts by:
16
+
17
+ - tracing imports from each function entrypoint,
18
+ - copying reachable first-party files,
19
+ - deriving a minimal pinned `requirements.txt` subset for third-party imports,
20
+ - installing only that dependency subset into the build target,
21
+ - and running optional verification/tests to increase confidence that each split artifact works in isolation.
22
+
23
+ It is intentionally conservative: this is import-based trimming with guardrails, not full tree-shaking or whole-program optimization. It aims to cover common Python import patterns used in real projects, while keeping behavior explicit and testable.
24
+
25
+ ## What monopack does
26
+
27
+ - Builds one or many functions from `functions/*.py` into `build/<function_name>/`.
28
+ - In `deploy` mode, writes deploy zip artifacts at `build/<function_name>.zip`.
29
+ - In `deploy` mode, writes package digest helper file(s) (`build/<function_name>.package.sha256` by default).
30
+ - In `test` mode, copies relevant tests and runs them in the build target (no zip output).
31
+ - Uses pinned project `requirements.txt` (`name==version` lines only).
32
+ - Supports optional auto-fix for missing-module verification failures (`--auto-fix`, opt-in).
33
+
34
+ ## Quickstart
35
+
36
+ Project expectations:
37
+
38
+ - `functions/` directory with function entrypoint files (`<name>.py`).
39
+ - Project-level `requirements.txt` containing pinned `name==version` lines.
40
+ - Optional `tests/` directory when using `--mode test`.
41
+
42
+ Build one function in deploy mode:
43
+
44
+ ```bash
45
+ PYTHONPATH=src python -m monopack users_get \
46
+ --functions-dir functions \
47
+ --build-dir build
48
+ ```
49
+
50
+ Run confidence build in test mode:
51
+
52
+ ```bash
53
+ PYTHONPATH=src python -m monopack users_get \
54
+ --functions-dir functions \
55
+ --build-dir /tmp/monopack-build \
56
+ --mode test
57
+ ```
58
+
59
+ Build all functions discovered in `functions/*.py` (no target argument):
60
+
61
+ ```bash
62
+ PYTHONPATH=src python -m monopack \
63
+ --functions-dir functions \
64
+ --build-dir build
65
+ ```
66
+
67
+ ## CLI usage
68
+
69
+ Basic form:
70
+
71
+ ```bash
72
+ PYTHONPATH=src python -m monopack [function_name] [options]
73
+ ```
74
+
75
+ Key flags for real-project usage:
76
+
77
+ - `--version`: prints the installed `monopack` version and exits.
78
+ - `--mode deploy|test`: deploy builds runtime payload + zip; test builds payload + tests (no zip).
79
+ - `--with-tests`: deploy mode only; runs relevant tests before finalizing deploy payload.
80
+ - `--verify` / `--no-verify`: verifier is on by default.
81
+ - `--auto-fix`: opt-in auto-repair loop for missing imports during verify.
82
+ - `--sha-output`: comma-separated package digest outputs for deploy mode (`hex`, `b64`; default `hex`).
83
+
84
+ Package digest output guidance:
85
+
86
+ - `hex` (`.package.sha256`): general CI/script diffing and human-readable checks.
87
+ - `b64` (`.package.sha256.b64`): Terraform-style workflows that prefer base64 digest values.
88
+ - Use both when needed: `--sha-output hex,b64`.
89
+
90
+ For full argument behavior and validation details, see `docs/cli.md`.
91
+
92
+ ## Constraints and limits
93
+
94
+ - Function discovery is shallow: only `functions/*.py` (excluding names starting with `_`).
95
+ - Function names must use letters, numbers, and underscores; target names cannot include `/`, `\\`, or `.`.
96
+ - Build directory must differ from functions directory and cannot be nested inside it.
97
+ - Requirements parser accepts only pinned `name==version` lines (comments and blanks allowed).
98
+ - First-party graph traversal is limited to roots `functions`, `app`, and `lib` unless inline config adds modules.
99
+ - Auto-fix only handles `ModuleNotFoundError` flows and retries up to 3 times when enabled.
100
+
101
+ ## Recommended feedback loop for monolith split confidence
102
+
103
+ 1. Build the target in test mode with verification enabled:
104
+ `PYTHONPATH=src python -m monopack <function> --mode test --verify`.
105
+ 2. Inspect build output (`build/<function>/`) and generated `requirements.txt` for expected scope.
106
+ 3. Build deploy artifact once confidence is good:
107
+ `PYTHONPATH=src python -m monopack <function> --mode deploy`.
108
+ 4. Optionally gate deploy build with tests:
109
+ `PYTHONPATH=src python -m monopack <function> --mode deploy --with-tests`.
110
+ 5. Run repository tests to catch broader regressions:
111
+ `python -m unittest discover -s tests -v`.
112
+ 6. Tighten imports/tests/inline config and repeat until scoped build behavior is stable.
113
+
114
+ ## Deeper docs
115
+
116
+ - CLI reference: `docs/cli.md`
117
+ - PyPI publishing: `docs/publishing.md`
118
+ - Fixture-driven confidence loop and matrix: `docs/testing-fixtures.md`
119
+
120
+ For Terraform `source_code_hash` usage with generated package digests, see `docs/cli.md`.
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "monopack"
7
+ version = "0.1.0"
8
+ description = "Build focused Python Lambda function bundles from source imports."
9
+ readme = {file = "README.md", content-type = "text/markdown"}
10
+ license = "MIT"
11
+ authors = [{name = "monopack maintainers"}]
12
+ keywords = ["aws-lambda", "build", "dependency-analysis", "packaging", "python"]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3 :: Only",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Topic :: Software Development :: Build Tools",
20
+ ]
21
+ requires-python = ">=3.12"
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/atomraymaker/monopack"
25
+ Repository = "https://github.com/atomraymaker/monopack"
26
+ Issues = "https://github.com/atomraymaker/monopack/issues"
27
+
28
+ [project.optional-dependencies]
29
+ dev = [
30
+ "build>=1.2.0",
31
+ "twine>=5.0.0",
32
+ ]
33
+
34
+ [project.scripts]
35
+ monopack = "monopack.cli:main"
36
+
37
+ [tool.setuptools]
38
+ package-dir = {"" = "src"}
39
+
40
+ [tool.setuptools.packages.find]
41
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,7 @@
1
+ """Module entrypoint for ``python -m monopack``."""
2
+
3
+ from monopack.cli import main
4
+
5
+
6
+ if __name__ == "__main__":
7
+ raise SystemExit(main())