modshim 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.
- modshim-0.1.0/.gitignore +147 -0
- modshim-0.1.0/LICENSE +21 -0
- modshim-0.1.0/PKG-INFO +80 -0
- modshim-0.1.0/README.md +71 -0
- modshim-0.1.0/pyproject.toml +74 -0
- modshim-0.1.0/src/modshim/__init__.py +437 -0
- modshim-0.1.0/src/modshim/py.typed +0 -0
- modshim-0.1.0/tests/__init__.py +1 -0
- modshim-0.1.0/tests/examples/__init__.py +1 -0
- modshim-0.1.0/tests/examples/csv_schema/__init__.py +71 -0
- modshim-0.1.0/tests/examples/datetime_weekend/__init__.py +21 -0
- modshim-0.1.0/tests/examples/json_formatted/__init__.py +26 -0
- modshim-0.1.0/tests/examples/json_metadata/__init__.py +22 -0
- modshim-0.1.0/tests/examples/json_single_quotes/__init__.py +65 -0
- modshim-0.1.0/tests/examples/json_single_quotes/encoder.py +83 -0
- modshim-0.1.0/tests/examples/pathlib_is_empty/__init__.py +1 -0
- modshim-0.1.0/tests/examples/pathlib_is_empty/_local.py +19 -0
- modshim-0.1.0/tests/examples/random_fixed/__init__.py +35 -0
- modshim-0.1.0/tests/examples/time_dilation/__init__.py +33 -0
- modshim-0.1.0/tests/examples/urllib_punycode/__init__.py +3 -0
- modshim-0.1.0/tests/examples/urllib_punycode/parse.py +65 -0
- modshim-0.1.0/tests/test_e2e.py +264 -0
- modshim-0.1.0/tests/test_usage.py +258 -0
- modshim-0.1.0/uv.lock +181 -0
modshim-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# AI tools
|
|
2
|
+
.aider*
|
|
3
|
+
CONVENTIONS.rst
|
|
4
|
+
|
|
5
|
+
# Byte-compiled / optimized / DLL files
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.py[cod]
|
|
8
|
+
*$py.class
|
|
9
|
+
|
|
10
|
+
# C extensions
|
|
11
|
+
*.so
|
|
12
|
+
|
|
13
|
+
# Distribution / packaging
|
|
14
|
+
.Python
|
|
15
|
+
build/
|
|
16
|
+
develop-eggs/
|
|
17
|
+
dist/
|
|
18
|
+
downloads/
|
|
19
|
+
eggs/
|
|
20
|
+
.eggs/
|
|
21
|
+
lib/
|
|
22
|
+
lib64/
|
|
23
|
+
parts/
|
|
24
|
+
sdist/
|
|
25
|
+
var/
|
|
26
|
+
wheels/
|
|
27
|
+
share/python-wheels/
|
|
28
|
+
*.egg-info/
|
|
29
|
+
.installed.cfg
|
|
30
|
+
*.egg
|
|
31
|
+
MANIFEST
|
|
32
|
+
|
|
33
|
+
# PyInstaller
|
|
34
|
+
# Usually these files are written by a python script from a template
|
|
35
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
36
|
+
*.manifest
|
|
37
|
+
*.spec
|
|
38
|
+
|
|
39
|
+
# Installer logs
|
|
40
|
+
pip-log.txt
|
|
41
|
+
pip-delete-this-directory.txt
|
|
42
|
+
|
|
43
|
+
# Unit test / coverage reports
|
|
44
|
+
htmlcov/
|
|
45
|
+
.tox/
|
|
46
|
+
.nox/
|
|
47
|
+
.coverage
|
|
48
|
+
.coverage.*
|
|
49
|
+
.cache
|
|
50
|
+
nosetests.xml
|
|
51
|
+
coverage.xml
|
|
52
|
+
*.cover
|
|
53
|
+
*.py,cover
|
|
54
|
+
.hypothesis/
|
|
55
|
+
.pytest_cache/
|
|
56
|
+
cover/
|
|
57
|
+
|
|
58
|
+
# Translations
|
|
59
|
+
*.mo
|
|
60
|
+
*.pot
|
|
61
|
+
|
|
62
|
+
# Django stuff:
|
|
63
|
+
*.log
|
|
64
|
+
local_settings.py
|
|
65
|
+
db.sqlite3
|
|
66
|
+
db.sqlite3-journal
|
|
67
|
+
|
|
68
|
+
# Flask stuff:
|
|
69
|
+
instance/
|
|
70
|
+
.webassets-cache
|
|
71
|
+
|
|
72
|
+
# Scrapy stuff:
|
|
73
|
+
.scrapy
|
|
74
|
+
|
|
75
|
+
# Sphinx documentation
|
|
76
|
+
docs/_build/
|
|
77
|
+
docs/_inc/
|
|
78
|
+
docs/reference/euporie*.rst
|
|
79
|
+
|
|
80
|
+
# PyBuilder
|
|
81
|
+
.pybuilder/
|
|
82
|
+
target/
|
|
83
|
+
|
|
84
|
+
# Jupyter Notebook
|
|
85
|
+
.ipynb_checkpoints
|
|
86
|
+
|
|
87
|
+
# IPython
|
|
88
|
+
profile_default/
|
|
89
|
+
ipython_config.py
|
|
90
|
+
|
|
91
|
+
# pyenv
|
|
92
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
93
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
94
|
+
.python-version
|
|
95
|
+
|
|
96
|
+
# pipenv
|
|
97
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
98
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
99
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
100
|
+
# install all needed dependencies.
|
|
101
|
+
#Pipfile.lock
|
|
102
|
+
|
|
103
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
104
|
+
__pypackages__/
|
|
105
|
+
|
|
106
|
+
# Celery stuff
|
|
107
|
+
celerybeat-schedule
|
|
108
|
+
celerybeat.pid
|
|
109
|
+
|
|
110
|
+
# SageMath parsed files
|
|
111
|
+
*.sage.py
|
|
112
|
+
|
|
113
|
+
# Environments
|
|
114
|
+
.env
|
|
115
|
+
.venv
|
|
116
|
+
env/
|
|
117
|
+
venv/
|
|
118
|
+
ENV/
|
|
119
|
+
env.bak/
|
|
120
|
+
venv.bak/
|
|
121
|
+
|
|
122
|
+
# Spyder project settings
|
|
123
|
+
.spyderproject
|
|
124
|
+
.spyproject
|
|
125
|
+
|
|
126
|
+
# Rope project settings
|
|
127
|
+
.ropeproject
|
|
128
|
+
|
|
129
|
+
# mkdocs documentation
|
|
130
|
+
/site
|
|
131
|
+
|
|
132
|
+
# ruff
|
|
133
|
+
.ruff_cache/
|
|
134
|
+
|
|
135
|
+
# mypy
|
|
136
|
+
.mypy_cache/
|
|
137
|
+
.dmypy.json
|
|
138
|
+
dmypy.json
|
|
139
|
+
|
|
140
|
+
# Pyre type checker
|
|
141
|
+
.pyre/
|
|
142
|
+
|
|
143
|
+
# pytype static type analyzer
|
|
144
|
+
.pytype/
|
|
145
|
+
|
|
146
|
+
# Cython debug symbols
|
|
147
|
+
cython_debug/
|
modshim-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Josiah Outram Halstead
|
|
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.
|
modshim-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: modshim
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Override and customize Python packages without touching their code.
|
|
5
|
+
Author-email: Josiah Outram Halstead <josiah@halstead.email>
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# modshim
|
|
11
|
+
|
|
12
|
+
A Python library for enhancing existing modules without modifying their source code - a clean alternative to vendoring.
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
`modshim` allows you to overlay custom functionality onto existing Python modules while preserving their original behavior. This is particularly useful when you need to:
|
|
17
|
+
|
|
18
|
+
- Fix bugs in third-party libraries without forking
|
|
19
|
+
- Modify behavior of existing functions
|
|
20
|
+
- Add new methods or properties to built-in types
|
|
21
|
+
- Test alternative implementations
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install modshim
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from modshim import shim
|
|
33
|
+
|
|
34
|
+
# Create an enhanced version of the json module that uses single quotes
|
|
35
|
+
json_single = shim(
|
|
36
|
+
upper="my_json_mods", # Module with your modifications
|
|
37
|
+
lower="json", # Original module to enhance
|
|
38
|
+
as_name="json_single" # Name for the merged result
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# Use it like the original, but with your enhancements
|
|
42
|
+
result = json_single.dumps({"hello": "world"})
|
|
43
|
+
print(result) # {'hello': 'world'}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Key Features
|
|
47
|
+
|
|
48
|
+
- **Non-invasive**: Original modules remain usable and unchanged
|
|
49
|
+
- **Transparent**: Enhanced modules behave like regular Python modules
|
|
50
|
+
- **Thread-safe**: Safe for concurrent usage
|
|
51
|
+
- **Type-safe**: Fully typed with modern Python type hints
|
|
52
|
+
|
|
53
|
+
## Example Use Cases
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
# Add weekend detection to datetime
|
|
57
|
+
dt = shim("my_datetime_ext", "datetime").datetime(2024, 1, 6)
|
|
58
|
+
print(dt.is_weekend) # True
|
|
59
|
+
|
|
60
|
+
# Add schema validation to CSV parsing
|
|
61
|
+
reader = shim("my_csv_ext", "csv").DictReader(
|
|
62
|
+
file,
|
|
63
|
+
schema={"id": int, "name": str}
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# Add automatic punycode decoding to urllib
|
|
67
|
+
url = shim("my_urllib_ext", "urllib").parse.urlparse(
|
|
68
|
+
"https://xn--bcher-kva.example.com"
|
|
69
|
+
)
|
|
70
|
+
print(url.netloc) # "bücher.example.com"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Why Not Vendor?
|
|
74
|
+
|
|
75
|
+
Unlike vendoring (copying) code:
|
|
76
|
+
- No need to maintain copies of dependencies
|
|
77
|
+
- Easier updates when upstream changes
|
|
78
|
+
- Cleaner separation between original and custom code
|
|
79
|
+
- More maintainable and testable enhancement path
|
|
80
|
+
|
modshim-0.1.0/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# modshim
|
|
2
|
+
|
|
3
|
+
A Python library for enhancing existing modules without modifying their source code - a clean alternative to vendoring.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`modshim` allows you to overlay custom functionality onto existing Python modules while preserving their original behavior. This is particularly useful when you need to:
|
|
8
|
+
|
|
9
|
+
- Fix bugs in third-party libraries without forking
|
|
10
|
+
- Modify behavior of existing functions
|
|
11
|
+
- Add new methods or properties to built-in types
|
|
12
|
+
- Test alternative implementations
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install modshim
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from modshim import shim
|
|
24
|
+
|
|
25
|
+
# Create an enhanced version of the json module that uses single quotes
|
|
26
|
+
json_single = shim(
|
|
27
|
+
upper="my_json_mods", # Module with your modifications
|
|
28
|
+
lower="json", # Original module to enhance
|
|
29
|
+
as_name="json_single" # Name for the merged result
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# Use it like the original, but with your enhancements
|
|
33
|
+
result = json_single.dumps({"hello": "world"})
|
|
34
|
+
print(result) # {'hello': 'world'}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Key Features
|
|
38
|
+
|
|
39
|
+
- **Non-invasive**: Original modules remain usable and unchanged
|
|
40
|
+
- **Transparent**: Enhanced modules behave like regular Python modules
|
|
41
|
+
- **Thread-safe**: Safe for concurrent usage
|
|
42
|
+
- **Type-safe**: Fully typed with modern Python type hints
|
|
43
|
+
|
|
44
|
+
## Example Use Cases
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
# Add weekend detection to datetime
|
|
48
|
+
dt = shim("my_datetime_ext", "datetime").datetime(2024, 1, 6)
|
|
49
|
+
print(dt.is_weekend) # True
|
|
50
|
+
|
|
51
|
+
# Add schema validation to CSV parsing
|
|
52
|
+
reader = shim("my_csv_ext", "csv").DictReader(
|
|
53
|
+
file,
|
|
54
|
+
schema={"id": int, "name": str}
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# Add automatic punycode decoding to urllib
|
|
58
|
+
url = shim("my_urllib_ext", "urllib").parse.urlparse(
|
|
59
|
+
"https://xn--bcher-kva.example.com"
|
|
60
|
+
)
|
|
61
|
+
print(url.netloc) # "bücher.example.com"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Why Not Vendor?
|
|
65
|
+
|
|
66
|
+
Unlike vendoring (copying) code:
|
|
67
|
+
- No need to maintain copies of dependencies
|
|
68
|
+
- Easier updates when upstream changes
|
|
69
|
+
- Cleaner separation between original and custom code
|
|
70
|
+
- More maintainable and testable enhancement path
|
|
71
|
+
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "modshim"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Override and customize Python packages without touching their code."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Josiah Outram Halstead", email = "josiah@halstead.email" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.9"
|
|
10
|
+
dependencies = []
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["hatchling"]
|
|
14
|
+
build-backend = "hatchling.build"
|
|
15
|
+
|
|
16
|
+
[dependency-groups]
|
|
17
|
+
dev = [
|
|
18
|
+
"pyright>=1.1.396",
|
|
19
|
+
"pytest>=4.6.11",
|
|
20
|
+
"ruff>=0.0.17",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
[tool.ruff.lint]
|
|
25
|
+
select = [ # "ANN", "B", "C", "D", "E", "F", "I", "Q", "S", "T", "UP"]
|
|
26
|
+
"ANN", #
|
|
27
|
+
"ASYNC", #
|
|
28
|
+
# "ARG", # Unused arguments
|
|
29
|
+
"B",
|
|
30
|
+
"C",
|
|
31
|
+
"C4",
|
|
32
|
+
"D",
|
|
33
|
+
"E",
|
|
34
|
+
"F",
|
|
35
|
+
"FA",
|
|
36
|
+
"G",
|
|
37
|
+
"I",
|
|
38
|
+
"PIE", # miscellaneous lints
|
|
39
|
+
"PT", # common style issues or inconsistencies with pytest-based tests
|
|
40
|
+
"PTH", # use pathlib
|
|
41
|
+
"Q", # quotes
|
|
42
|
+
"S", # bandit security testingi
|
|
43
|
+
"RUF", # ruff-specific
|
|
44
|
+
"SIM", # simplify
|
|
45
|
+
# "RET", # return values
|
|
46
|
+
"T",
|
|
47
|
+
"TCH", # type checking import blocks
|
|
48
|
+
"UP",
|
|
49
|
+
"W",
|
|
50
|
+
]
|
|
51
|
+
ignore = [
|
|
52
|
+
# Use of typing.Any
|
|
53
|
+
"ANN401",
|
|
54
|
+
# Function too complex
|
|
55
|
+
"C901",
|
|
56
|
+
# Use of assert
|
|
57
|
+
"S101",
|
|
58
|
+
# Line to long
|
|
59
|
+
"E501",
|
|
60
|
+
# Google style docstrings
|
|
61
|
+
"D203", "D204", "D213", "D215", "D400", "D404", "D406", "D407", "D408", "D409", "D413",
|
|
62
|
+
# Allow empty functions in ABCs
|
|
63
|
+
"B027",
|
|
64
|
+
# zip() without an explicit strict= parameter
|
|
65
|
+
"B905",
|
|
66
|
+
# Ignore subprocess warnings
|
|
67
|
+
"S603", "S607",
|
|
68
|
+
# Ignore ambiguous-unicode-character-string warning
|
|
69
|
+
"RUF001",
|
|
70
|
+
# Do not use `contextlib.suppress` instead of `try...except...pass`
|
|
71
|
+
"SIM105",
|
|
72
|
+
# Do not enforce ternary operators
|
|
73
|
+
"SIM108",
|
|
74
|
+
]
|