dbx-patch 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.
@@ -0,0 +1,172 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+ _build/
141
+
142
+ # mypy
143
+ .mypy_cache/
144
+ .dmypy.json
145
+ dmypy.json
146
+
147
+ # Pyre type checker
148
+ .pyre/
149
+
150
+ # pytype static type analyzer
151
+ .pytype/
152
+
153
+ # Cython debug symbols
154
+ cython_debug/
155
+
156
+ # ruff
157
+ .ruff_cache/
158
+
159
+ # PyCharm
160
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
161
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
162
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
163
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
164
+ #.idea/
165
+
166
+ # default folders for storing artifacts excluded, but present for structure
167
+ /data/
168
+ /logs/
169
+ /models/
170
+
171
+ # Databricks
172
+ /databricks/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 twsl
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,133 @@
1
+ Metadata-Version: 2.4
2
+ Name: dbx-patch
3
+ Version: 0.1.0
4
+ Summary: Patchception: A library to patch the Databricks patching of Python
5
+ Project-URL: homepage, https://twsl.github.io/dbx-patch/
6
+ Project-URL: repository, https://github.com/twsl/dbx-patch
7
+ Project-URL: documentation, https://twsl.github.io/dbx-patch/
8
+ Author-email: twsl <45483159+twsl@users.noreply.github.com>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: dbx-patch
12
+ Requires-Python: >=3.12
13
+ Provides-Extra: extra
14
+ Description-Content-Type: text/markdown
15
+
16
+ # dbx-patch
17
+
18
+ [![Build](https://github.com/twsl/dbx-patch/actions/workflows/build.yaml/badge.svg)](https://github.com/twsl/dbx-patch/actions/workflows/build.yaml)
19
+ [![Documentation](https://github.com/twsl/dbx-patch/actions/workflows/docs.yaml/badge.svg)](https://github.com/twsl/dbx-patch/actions/workflows/docs.yaml)
20
+ [![Docs with MkDocs](https://img.shields.io/badge/MkDocs-docs?style=flat&logo=materialformkdocs&logoColor=white&color=%23526CFE)](https://squidfunk.github.io/mkdocs-material/)
21
+ [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
22
+ [![linting: ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
23
+ [![ty](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ty/main/assets/badge/v0.json)](https://github.com/astral-sh/ty)
24
+ [![prek](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/j178/prek/master/docs/assets/badge-v0.json)](https://github.com/j178/prek)
25
+ [![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)
26
+ [![Semantic Versions](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--versions-e10079.svg)](https://github.com/twsl/dbx-patch/releases)
27
+ [![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-border.json)](https://github.com/copier-org/copier)
28
+ [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
29
+
30
+ Patchception: A library to patch the Databricks patching of Python to enable editable package installs.
31
+
32
+ ## Features
33
+
34
+ - ✅ Enables editable Python package installs (`pip install -e .`) in Databricks notebooks
35
+ - ✅ Patches Databricks' custom import system to allow workspace directory imports
36
+ - ✅ Automatic patch application via `sitecustomize.py` (recommended)
37
+ - ✅ Manual patching via `patch_dbx()` for immediate use
38
+ - ✅ Debug mode with `DBX_PATCH_DEBUG` environment variable for troubleshooting
39
+
40
+ ## Installation
41
+
42
+ With `pip`:
43
+
44
+ ```bash
45
+ python -m pip install dbx-patch
46
+ ```
47
+
48
+ With [`uv`](https://docs.astral.sh/uv/):
49
+
50
+ ```bash
51
+ uv add dbx-patch
52
+ ```
53
+
54
+ ## Quick Start
55
+
56
+ ### 🚀 Recommended: One-Command Setup
57
+
58
+ The simplest way to get started - patches current session AND installs automatic patching:
59
+
60
+ ```python
61
+ from dbx_patch import patch_and_install
62
+ patch_and_install()
63
+ # Patches applied + sitecustomize.py installed
64
+ # Python will restart automatically in Databricks!
65
+ ```
66
+
67
+ ### ⚡ Manual Patching (Current Session Only)
68
+
69
+ If you only want to patch the current Python session without persistence:
70
+
71
+ ```python
72
+ from dbx_patch import patch_dbx
73
+ patch_dbx()
74
+ # Editable installs now work in this session!
75
+ ```
76
+
77
+ ### 🔧 Automatic Patching (Persistent)
78
+
79
+ For permanent solution that works across all Python restarts:
80
+
81
+ ```python
82
+ # Run ONCE per cluster (e.g., in init script or setup notebook)
83
+ from dbx_patch import install_sitecustomize
84
+ install_sitecustomize()
85
+ # Python will restart automatically in Databricks!
86
+ # After restart, patches are applied automatically on every Python startup
87
+ ```
88
+
89
+ - `sys_path_init.py` runs **during Python interpreter initialization**
90
+ - Your notebook code runs **after initialization completes**
91
+ - By the time you call `patch_dbx()`, the import system is already configured
92
+ - Editable install paths have already been removed from `sys.path`
93
+ - Import hooks are already installed and active
94
+
95
+ #### The Solution: sitecustomize.py
96
+
97
+ Python **automatically** imports `sitecustomize.py` during interpreter initialization, **before** any Databricks code runs:
98
+
99
+ 1. **Python interpreter starts**
100
+ 2. **`sitecustomize.py` runs** → ✅ Patches are applied **early**
101
+ 3. **Databricks code tries to run** → ✅ Already patched!
102
+ 4. **Your notebook code runs** → ✅ Editable installs work!
103
+
104
+ ```python
105
+ # ✅ This WORKS - patches applied at startup
106
+ from dbx_patch import install_sitecustomize
107
+ install_sitecustomize() # Installs sitecustomize.py + auto-restarts Python
108
+ ```
109
+
110
+ **Implementation details:**
111
+
112
+ - `sitecustomize.py` patches `sys_path_init` **before** it runs
113
+ - Import hooks are modified **before** they're installed
114
+ - Editable install paths are preserved in `sys.path`
115
+ - All patches are applied silently during startup
116
+
117
+ For detailed technical explanation, see [Technical Implementation](docs/docs/files/implementation.md#the-timing-problem)
118
+
119
+ ## Docs
120
+
121
+ ```bash
122
+ uv run mkdocs build -f ./mkdocs.yml -d ./_build/
123
+ ```
124
+
125
+ ## Update template
126
+
127
+ ```bash
128
+ copier update --trust -A --vcs-ref=HEAD
129
+ ```
130
+
131
+ ## Credits
132
+
133
+ This project was generated with [![🚀 python project template.](https://img.shields.io/badge/python--project--template-%F0%9F%9A%80-brightgreen)](https://github.com/twsl/python-project-template)
@@ -0,0 +1,118 @@
1
+ # dbx-patch
2
+
3
+ [![Build](https://github.com/twsl/dbx-patch/actions/workflows/build.yaml/badge.svg)](https://github.com/twsl/dbx-patch/actions/workflows/build.yaml)
4
+ [![Documentation](https://github.com/twsl/dbx-patch/actions/workflows/docs.yaml/badge.svg)](https://github.com/twsl/dbx-patch/actions/workflows/docs.yaml)
5
+ [![Docs with MkDocs](https://img.shields.io/badge/MkDocs-docs?style=flat&logo=materialformkdocs&logoColor=white&color=%23526CFE)](https://squidfunk.github.io/mkdocs-material/)
6
+ [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
7
+ [![linting: ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
8
+ [![ty](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ty/main/assets/badge/v0.json)](https://github.com/astral-sh/ty)
9
+ [![prek](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/j178/prek/master/docs/assets/badge-v0.json)](https://github.com/j178/prek)
10
+ [![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)
11
+ [![Semantic Versions](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--versions-e10079.svg)](https://github.com/twsl/dbx-patch/releases)
12
+ [![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-border.json)](https://github.com/copier-org/copier)
13
+ [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
14
+
15
+ Patchception: A library to patch the Databricks patching of Python to enable editable package installs.
16
+
17
+ ## Features
18
+
19
+ - ✅ Enables editable Python package installs (`pip install -e .`) in Databricks notebooks
20
+ - ✅ Patches Databricks' custom import system to allow workspace directory imports
21
+ - ✅ Automatic patch application via `sitecustomize.py` (recommended)
22
+ - ✅ Manual patching via `patch_dbx()` for immediate use
23
+ - ✅ Debug mode with `DBX_PATCH_DEBUG` environment variable for troubleshooting
24
+
25
+ ## Installation
26
+
27
+ With `pip`:
28
+
29
+ ```bash
30
+ python -m pip install dbx-patch
31
+ ```
32
+
33
+ With [`uv`](https://docs.astral.sh/uv/):
34
+
35
+ ```bash
36
+ uv add dbx-patch
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ### 🚀 Recommended: One-Command Setup
42
+
43
+ The simplest way to get started - patches current session AND installs automatic patching:
44
+
45
+ ```python
46
+ from dbx_patch import patch_and_install
47
+ patch_and_install()
48
+ # Patches applied + sitecustomize.py installed
49
+ # Python will restart automatically in Databricks!
50
+ ```
51
+
52
+ ### ⚡ Manual Patching (Current Session Only)
53
+
54
+ If you only want to patch the current Python session without persistence:
55
+
56
+ ```python
57
+ from dbx_patch import patch_dbx
58
+ patch_dbx()
59
+ # Editable installs now work in this session!
60
+ ```
61
+
62
+ ### 🔧 Automatic Patching (Persistent)
63
+
64
+ For permanent solution that works across all Python restarts:
65
+
66
+ ```python
67
+ # Run ONCE per cluster (e.g., in init script or setup notebook)
68
+ from dbx_patch import install_sitecustomize
69
+ install_sitecustomize()
70
+ # Python will restart automatically in Databricks!
71
+ # After restart, patches are applied automatically on every Python startup
72
+ ```
73
+
74
+ - `sys_path_init.py` runs **during Python interpreter initialization**
75
+ - Your notebook code runs **after initialization completes**
76
+ - By the time you call `patch_dbx()`, the import system is already configured
77
+ - Editable install paths have already been removed from `sys.path`
78
+ - Import hooks are already installed and active
79
+
80
+ #### The Solution: sitecustomize.py
81
+
82
+ Python **automatically** imports `sitecustomize.py` during interpreter initialization, **before** any Databricks code runs:
83
+
84
+ 1. **Python interpreter starts**
85
+ 2. **`sitecustomize.py` runs** → ✅ Patches are applied **early**
86
+ 3. **Databricks code tries to run** → ✅ Already patched!
87
+ 4. **Your notebook code runs** → ✅ Editable installs work!
88
+
89
+ ```python
90
+ # ✅ This WORKS - patches applied at startup
91
+ from dbx_patch import install_sitecustomize
92
+ install_sitecustomize() # Installs sitecustomize.py + auto-restarts Python
93
+ ```
94
+
95
+ **Implementation details:**
96
+
97
+ - `sitecustomize.py` patches `sys_path_init` **before** it runs
98
+ - Import hooks are modified **before** they're installed
99
+ - Editable install paths are preserved in `sys.path`
100
+ - All patches are applied silently during startup
101
+
102
+ For detailed technical explanation, see [Technical Implementation](docs/docs/files/implementation.md#the-timing-problem)
103
+
104
+ ## Docs
105
+
106
+ ```bash
107
+ uv run mkdocs build -f ./mkdocs.yml -d ./_build/
108
+ ```
109
+
110
+ ## Update template
111
+
112
+ ```bash
113
+ copier update --trust -A --vcs-ref=HEAD
114
+ ```
115
+
116
+ ## Credits
117
+
118
+ This project was generated with [![🚀 python project template.](https://img.shields.io/badge/python--project--template-%F0%9F%9A%80-brightgreen)](https://github.com/twsl/python-project-template)