funcsnap 0.0.1.dev1__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. funcsnap-0.0.1.dev1/.github/workflows/ci.yml +29 -0
  2. funcsnap-0.0.1.dev1/.github/workflows/publish.yml +39 -0
  3. funcsnap-0.0.1.dev1/.gitignore +195 -0
  4. funcsnap-0.0.1.dev1/LICENSE +21 -0
  5. funcsnap-0.0.1.dev1/Makefile +34 -0
  6. funcsnap-0.0.1.dev1/PKG-INFO +59 -0
  7. funcsnap-0.0.1.dev1/README.md +32 -0
  8. funcsnap-0.0.1.dev1/agent.md +13 -0
  9. funcsnap-0.0.1.dev1/funcsnap/__init__.py +12 -0
  10. funcsnap-0.0.1.dev1/funcsnap/save_source_function.py +507 -0
  11. funcsnap-0.0.1.dev1/implementation.md +76 -0
  12. funcsnap-0.0.1.dev1/notebooks/test_source_function.ipynb +48 -0
  13. funcsnap-0.0.1.dev1/plan/plan.md +337 -0
  14. funcsnap-0.0.1.dev1/pyproject.toml +49 -0
  15. funcsnap-0.0.1.dev1/requirements.txt +5 -0
  16. funcsnap-0.0.1.dev1/tests/__init__.py +0 -0
  17. funcsnap-0.0.1.dev1/tests/fixtures/sample_chain/dev_example.py +14 -0
  18. funcsnap-0.0.1.dev1/tests/fixtures/sample_chain/some_module.py +25 -0
  19. funcsnap-0.0.1.dev1/tests/fixtures/sample_chain/some_module2.py +10 -0
  20. funcsnap-0.0.1.dev1/tests/mylib/__init__.py +0 -0
  21. funcsnap-0.0.1.dev1/tests/mylib/core/__init__.py +0 -0
  22. funcsnap-0.0.1.dev1/tests/mylib/core/primitives.py +15 -0
  23. funcsnap-0.0.1.dev1/tests/mylib/core/utils.py +12 -0
  24. funcsnap-0.0.1.dev1/tests/mylib/models/__init__.py +0 -0
  25. funcsnap-0.0.1.dev1/tests/mylib/models/base_model.py +14 -0
  26. funcsnap-0.0.1.dev1/tests/mylib/models/classifier.py +11 -0
  27. funcsnap-0.0.1.dev1/tests/mylib/pipeline/__init__.py +0 -0
  28. funcsnap-0.0.1.dev1/tests/mylib/pipeline/runner.py +20 -0
  29. funcsnap-0.0.1.dev1/tests/mylib2/__init__.py +0 -0
  30. funcsnap-0.0.1.dev1/tests/mylib2/ops/__init__.py +0 -0
  31. funcsnap-0.0.1.dev1/tests/mylib2/ops/primitives.py +17 -0
  32. funcsnap-0.0.1.dev1/tests/mylib2/ops/transforms.py +10 -0
  33. funcsnap-0.0.1.dev1/tests/mylib2/pipeline/__init__.py +0 -0
  34. funcsnap-0.0.1.dev1/tests/mylib2/pipeline/runner2.py +17 -0
  35. funcsnap-0.0.1.dev1/tests/test_complex_source_functions.py +293 -0
  36. funcsnap-0.0.1.dev1/tests/test_e2e_reconstruct.py +115 -0
  37. funcsnap-0.0.1.dev1/tests/test_multi_lib.py +280 -0
  38. funcsnap-0.0.1.dev1/tests/test_save_source_function.py +153 -0
@@ -0,0 +1,29 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ python-version: ["3.10"]
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Set up Python ${{ matrix.python-version }}
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: ${{ matrix.python-version }}
21
+
22
+ - name: Install dependencies
23
+ run: pip install -e ".[dev]"
24
+
25
+ - name: Ruff
26
+ run: ruff check .
27
+
28
+ - name: Pytest
29
+ run: pytest -q
@@ -0,0 +1,39 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ environment: PyPI
12
+ permissions:
13
+ id-token: write
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ with:
17
+ fetch-depth: 0
18
+
19
+ - name: Verify tag commit is on main
20
+ run: |
21
+ git fetch origin main
22
+ if ! git merge-base --is-ancestor "${GITHUB_SHA}" origin/main; then
23
+ echo "Tagged commit is not an ancestor of main; refusing to publish."
24
+ exit 1
25
+ fi
26
+
27
+ - name: Set up Python
28
+ uses: actions/setup-python@v5
29
+ with:
30
+ python-version: "3.12"
31
+
32
+ - name: Install build tooling
33
+ run: pip install build
34
+
35
+ - name: Build
36
+ run: python -m build
37
+
38
+ - name: Publish to PyPI
39
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,195 @@
1
+
2
+ # Created by https://www.toptal.com/developers/gitignore/api/python
3
+ # Edit at https://www.toptal.com/developers/gitignore?templates=python
4
+
5
+ ### Python ###
6
+ # Byte-compiled / optimized / DLL files
7
+ __pycache__/
8
+ *.py[cod]
9
+ *$py.class
10
+
11
+ # C extensions
12
+ *.so
13
+
14
+ # Distribution / packaging
15
+ .Python
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ downloads/
20
+ eggs/
21
+ .eggs/
22
+ lib/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ share/python-wheels/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+ MANIFEST
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ # Installer logs
41
+ pip-log.txt
42
+ pip-delete-this-directory.txt
43
+
44
+ # Unit test / coverage reports
45
+ htmlcov/
46
+ .tox/
47
+ .nox/
48
+ .coverage
49
+ .coverage.*
50
+ .cache
51
+ nosetests.xml
52
+ coverage.xml
53
+ *.cover
54
+ *.py,cover
55
+ .hypothesis/
56
+ .pytest_cache/
57
+ cover/
58
+
59
+ # Translations
60
+ *.mo
61
+ *.pot
62
+
63
+ # Django stuff:
64
+ *.log
65
+ local_settings.py
66
+ db.sqlite3
67
+ db.sqlite3-journal
68
+
69
+ # Flask stuff:
70
+ instance/
71
+ .webassets-cache
72
+
73
+ # Scrapy stuff:
74
+ .scrapy
75
+
76
+ # Sphinx documentation
77
+ docs/_build/
78
+
79
+ # PyBuilder
80
+ .pybuilder/
81
+ target/
82
+
83
+ # Jupyter Notebook
84
+ .ipynb_checkpoints
85
+
86
+ # IPython
87
+ profile_default/
88
+ ipython_config.py
89
+
90
+ # pyenv
91
+ # For a library or package, you might want to ignore these files since the code is
92
+ # intended to run in multiple environments; otherwise, check them in:
93
+ # .python-version
94
+
95
+ # pipenv
96
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
98
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
99
+ # install all needed dependencies.
100
+ #Pipfile.lock
101
+
102
+ # poetry
103
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
104
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
105
+ # commonly ignored for libraries.
106
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
107
+ #poetry.lock
108
+
109
+ # pdm
110
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
111
+ #pdm.lock
112
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
113
+ # in version control.
114
+ # https://pdm.fming.dev/#use-with-ide
115
+ .pdm.toml
116
+
117
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
118
+ __pypackages__/
119
+
120
+ # Celery stuff
121
+ celerybeat-schedule
122
+ celerybeat.pid
123
+
124
+ # SageMath parsed files
125
+ *.sage.py
126
+
127
+ # Environments
128
+ .env
129
+ .venv
130
+ env/
131
+ venv/
132
+ ENV/
133
+ env.bak/
134
+ venv.bak/
135
+
136
+ # Spyder project settings
137
+ .spyderproject
138
+ .spyproject
139
+
140
+ # Rope project settings
141
+ .ropeproject
142
+
143
+ # mkdocs documentation
144
+ /site
145
+
146
+ # mypy
147
+ .mypy_cache/
148
+ .dmypy.json
149
+ dmypy.json
150
+
151
+ # Pyre type checker
152
+ .pyre/
153
+
154
+ # pytype static type analyzer
155
+ .pytype/
156
+
157
+ # Cython debug symbols
158
+ cython_debug/
159
+
160
+ # PyCharm
161
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
162
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
163
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
164
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
165
+ #.idea/
166
+
167
+ ### Python Patch ###
168
+ # Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
169
+ poetry.toml
170
+
171
+ # ruff
172
+ .ruff_cache/
173
+
174
+ # End of https://www.toptal.com/developers/gitignore/api/python
175
+
176
+
177
+ # *.json
178
+ *.pdf
179
+ # *_ANALYSIS_CELL*
180
+ # .ipynb_checkpoints
181
+ .DS_Store
182
+ *.pyc
183
+ tmp_data
184
+ tmp_test_data
185
+ trash.*
186
+ trash_*.*
187
+
188
+ .vscode
189
+ *.code-workspace
190
+
191
+ _*.ipynb
192
+
193
+
194
+ _*\.ipynb
195
+ _[^_]*\.py.env
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 funcsnap contributors
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,34 @@
1
+ .PHONY: ci tag deploy clean
2
+
3
+ -include .env
4
+ export
5
+
6
+ ci:
7
+ pip install -e ".[dev]"
8
+ ruff check .
9
+ pytest -q
10
+
11
+ tag:
12
+ ifndef VERSION
13
+ $(error VERSION is not set. Usage: make tag VERSION=1.2.3)
14
+ endif
15
+ @if ! git diff --quiet || ! git diff --cached --quiet; then \
16
+ echo "Error: working tree is not clean. Commit or stash changes first."; \
17
+ exit 1; \
18
+ fi
19
+ git tag v$(VERSION)
20
+ git push origin v$(VERSION)
21
+
22
+ deploy:
23
+ ifndef VERSION
24
+ $(error VERSION is not set. Usage: make deploy VERSION=1.2.3)
25
+ endif
26
+ ifndef PYPI_TOKEN
27
+ $(error PYPI_TOKEN is not set. Add it to .env or pass it directly.)
28
+ endif
29
+ $(MAKE) clean
30
+ python -m build
31
+ twine upload dist/* --username __token__ --password $(PYPI_TOKEN)
32
+
33
+ clean:
34
+ rm -rf dist/ build/ *.egg-info
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: funcsnap
3
+ Version: 0.0.1.dev1
4
+ Summary: Analyze Python functions and extract dependency source for reconstruction
5
+ Project-URL: Repository, https://github.com/yourusername/funcsnap
6
+ Author: funcsnap contributors
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Keywords: ast,introspection,serialization,source
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.10
20
+ Provides-Extra: dev
21
+ Requires-Dist: build>=1.2; extra == 'dev'
22
+ Requires-Dist: numpy>=1.26; extra == 'dev'
23
+ Requires-Dist: pytest>=8; extra == 'dev'
24
+ Requires-Dist: ruff>=0.8; extra == 'dev'
25
+ Requires-Dist: twine>=5; extra == 'dev'
26
+ Description-Content-Type: text/markdown
27
+
28
+ # funcsnap
29
+
30
+ Analyze Python functions, walk their dependencies, and **reconstruct** a self-contained source string suitable for `exec()`.
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ pip install funcsnap
36
+ ```
37
+
38
+ ## Development
39
+
40
+ Clone the repo, create a virtual environment, then:
41
+
42
+ ```bash
43
+ pip install -e ".[dev]"
44
+ ruff check .
45
+ pytest
46
+ ```
47
+
48
+ Version strings are derived from Git tags ([hatch-vcs](https://github.com/ofek/hatch-vcs)). Without a repository or tags, builds use the fallback version from `pyproject.toml`.
49
+
50
+ ### PyPI releases (maintainers)
51
+
52
+ 1. Configure **trusted publishing** on [PyPI](https://pypi.org/manage/account/publishing/) for this repository and workflow `.github/workflows/publish.yml` (optional GitHub Environment `pypi`).
53
+ 2. Merge your changes to `main`, then tag and push: `git tag v0.1.0 && git push origin v0.1.0` (use the next semantic version). The publish workflow runs on tags matching `v*`.
54
+
55
+ Update the `Repository` URL in `pyproject.toml` under `[project.urls]` to match your GitHub repo.
56
+
57
+ ## License
58
+
59
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,32 @@
1
+ # funcsnap
2
+
3
+ Analyze Python functions, walk their dependencies, and **reconstruct** a self-contained source string suitable for `exec()`.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install funcsnap
9
+ ```
10
+
11
+ ## Development
12
+
13
+ Clone the repo, create a virtual environment, then:
14
+
15
+ ```bash
16
+ pip install -e ".[dev]"
17
+ ruff check .
18
+ pytest
19
+ ```
20
+
21
+ Version strings are derived from Git tags ([hatch-vcs](https://github.com/ofek/hatch-vcs)). Without a repository or tags, builds use the fallback version from `pyproject.toml`.
22
+
23
+ ### PyPI releases (maintainers)
24
+
25
+ 1. Configure **trusted publishing** on [PyPI](https://pypi.org/manage/account/publishing/) for this repository and workflow `.github/workflows/publish.yml` (optional GitHub Environment `pypi`).
26
+ 2. Merge your changes to `main`, then tag and push: `git tag v0.1.0 && git push origin v0.1.0` (use the next semantic version). The publish workflow runs on tags matching `v*`.
27
+
28
+ Update the `Repository` URL in `pyproject.toml` under `[project.urls]` to match your GitHub repo.
29
+
30
+ ## License
31
+
32
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,13 @@
1
+ # Agent instructions
2
+
3
+ ## Python environment
4
+
5
+ When running Python code, tests, or any tooling that invokes the interpreter (for example `pytest`), use the project virtual environment at **`.venv`** only.
6
+
7
+ - Prefer explicit paths such as `.venv/bin/python` and `.venv/bin/pytest`, or activate `.venv` in the shell and then run commands so they resolve to that environment.
8
+ - Do **not** use the system or “classical” global `python` / `python3` when a project `.venv` exists.
9
+ - Do **not** use **`uv`** (for example `uv run`, `uv pip`, or other `uv` commands) to execute or manage this project’s environment unless the project owner explicitly asks for it.
10
+
11
+ ## Dependencies
12
+
13
+ Do **not** install, add, or upgrade packages on your own (no `pip install`, `pip3 install`, `uv add`, `uv pip install`, `poetry add`, conda installs, or similar). If a dependency is missing or tests fail for lack of a package, report that to the project owner instead of changing the environment.
@@ -0,0 +1,12 @@
1
+ """Extract and reconstruct Python function source and dependencies."""
2
+
3
+ from importlib.metadata import PackageNotFoundError, version
4
+
5
+ from funcsnap.save_source_function import get_source_functions, reconstruct
6
+
7
+ __all__ = ["__version__", "get_source_functions", "reconstruct"]
8
+
9
+ try:
10
+ __version__ = version("funcsnap")
11
+ except PackageNotFoundError:
12
+ __version__ = "0.0.0"