kebe-ship 0.0.6__py3-none-any.whl
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.
- kebe_ship/__init__.py +10 -0
- kebe_ship/assets.py +106 -0
- kebe_ship/data/tars/FlashMLA-46d64a8ebef03fa50b4ae74937276a5c940e3f95.zip +0 -0
- kebe_ship-0.0.6.dist-info/METADATA +38 -0
- kebe_ship-0.0.6.dist-info/RECORD +8 -0
- kebe_ship-0.0.6.dist-info/WHEEL +5 -0
- kebe_ship-0.0.6.dist-info/licenses/LICENSE +21 -0
- kebe_ship-0.0.6.dist-info/top_level.txt +1 -0
kebe_ship/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Utilities for accessing bundled data files.
|
|
2
|
+
|
|
3
|
+
This package bundles configuration files, templates and binary resources in
|
|
4
|
+
``bundled_assets/data``. Use the functions from :mod:`bundled_assets.assets`
|
|
5
|
+
to read these resources as text or bytes.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .assets import read_text, read_bytes, as_file_path
|
|
9
|
+
|
|
10
|
+
__all__ = ["read_text", "read_bytes", "as_file_path"]
|
kebe_ship/assets.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Helper functions to access resources bundled with this package.
|
|
2
|
+
|
|
3
|
+
These functions provide a high-level API to read text or binary files from
|
|
4
|
+
within the installed ``bundled_assets`` package. They rely on the
|
|
5
|
+
``importlib.resources`` module, which correctly handles files inside zip
|
|
6
|
+
archives (such as wheel distributions) without assuming that the data lives
|
|
7
|
+
on the filesystem. See the Python documentation for more details:
|
|
8
|
+
https://docs.python.org/3/library/importlib.resources.html
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from contextlib import contextmanager
|
|
14
|
+
from importlib import resources
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Iterator
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _resource_path(rel_path: str) -> resources.abc.Traversable:
|
|
20
|
+
"""Return a Traversable pointing to a resource under ``data``.
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
rel_path: str
|
|
25
|
+
The relative path under the ``data`` directory. For example
|
|
26
|
+
``"templates/prompt.txt"``.
|
|
27
|
+
|
|
28
|
+
Returns
|
|
29
|
+
-------
|
|
30
|
+
resources.abc.Traversable
|
|
31
|
+
An object representing the resource. This can be passed to
|
|
32
|
+
:func:`importlib.resources.as_file` to obtain a real filesystem path.
|
|
33
|
+
"""
|
|
34
|
+
base = resources.files(__package__).joinpath("data")
|
|
35
|
+
return base.joinpath(rel_path)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def read_text(rel_path: str, encoding: str = "utf-8") -> str:
|
|
39
|
+
"""Read a text resource bundled with the package.
|
|
40
|
+
|
|
41
|
+
This function reads a file located in the ``data`` directory of
|
|
42
|
+
``bundled_assets`` and returns its contents as a string.
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
rel_path: str
|
|
47
|
+
The relative path to the file inside the ``data`` directory.
|
|
48
|
+
|
|
49
|
+
encoding: str, optional
|
|
50
|
+
The text encoding to use. Defaults to ``"utf-8"``.
|
|
51
|
+
|
|
52
|
+
Returns
|
|
53
|
+
-------
|
|
54
|
+
str
|
|
55
|
+
The decoded text contents of the file.
|
|
56
|
+
"""
|
|
57
|
+
resource = _resource_path(rel_path)
|
|
58
|
+
return resource.read_text(encoding=encoding)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def read_bytes(rel_path: str) -> bytes:
|
|
62
|
+
"""Read a binary resource bundled with the package.
|
|
63
|
+
|
|
64
|
+
Parameters
|
|
65
|
+
----------
|
|
66
|
+
rel_path: str
|
|
67
|
+
The relative path to the file inside the ``data`` directory.
|
|
68
|
+
|
|
69
|
+
Returns
|
|
70
|
+
-------
|
|
71
|
+
bytes
|
|
72
|
+
The raw bytes of the resource.
|
|
73
|
+
"""
|
|
74
|
+
resource = _resource_path(rel_path)
|
|
75
|
+
return resource.read_bytes()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@contextmanager
|
|
79
|
+
def as_file_path(rel_path: str) -> Iterator[Path]:
|
|
80
|
+
"""Yield a real filesystem path to a bundled resource.
|
|
81
|
+
|
|
82
|
+
Some libraries require a path on disk rather than a file-like object.
|
|
83
|
+
This context manager yields a :class:`~pathlib.Path` pointing to a
|
|
84
|
+
temporary copy of the resource if the package is installed as a zip
|
|
85
|
+
archive. When the context exits, any temporary files are cleaned up.
|
|
86
|
+
|
|
87
|
+
Example
|
|
88
|
+
-------
|
|
89
|
+
>>> from bundled_assets.assets import as_file_path
|
|
90
|
+
>>> with as_file_path("templates/prompt.txt") as path:
|
|
91
|
+
... print(path.read_text())
|
|
92
|
+
|
|
93
|
+
Parameters
|
|
94
|
+
----------
|
|
95
|
+
rel_path: str
|
|
96
|
+
The relative path to the file inside the ``data`` directory.
|
|
97
|
+
|
|
98
|
+
Yields
|
|
99
|
+
------
|
|
100
|
+
pathlib.Path
|
|
101
|
+
A path object pointing to the resource.
|
|
102
|
+
"""
|
|
103
|
+
resource = _resource_path(rel_path)
|
|
104
|
+
# resources.as_file returns a context manager that yields a real Path
|
|
105
|
+
with resources.as_file(resource) as tmp_path:
|
|
106
|
+
yield tmp_path
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kebe-ship
|
|
3
|
+
Version: 0.0.6
|
|
4
|
+
Summary: Example package that bundles data files.
|
|
5
|
+
Author: Your Name
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Your Name
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Classifier: Programming Language :: Python :: 3
|
|
28
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
29
|
+
Requires-Python: >=3.9
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
## Bundled Assets Package
|
|
35
|
+
|
|
36
|
+
This package demonstrates how to include data files in a Python package so that they can be distributed via PyPI and accessed at runtime. It uses [`importlib.resources`](https://docs.python.org/3/library/importlib.resources.html) to read text and binary files from within the installed package.
|
|
37
|
+
|
|
38
|
+
After installing this package with `pip install`, you can use the helper functions in `bundled_assets.assets` to load the bundled data files. See the docstrings in `assets.py` for more information.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
kebe_ship/__init__.py,sha256=DulURsLvuJd7Bbwyk4U0izc9a7LSiLPdE0ySgE7xxzI,359
|
|
2
|
+
kebe_ship/assets.py,sha256=OswMEvD80fDILkA3iYS2pUYq7uMjRZx0BxCELWqS2o0,3235
|
|
3
|
+
kebe_ship/data/tars/FlashMLA-46d64a8ebef03fa50b4ae74937276a5c940e3f95.zip,sha256=1sSELoNTDJXivMG7VAnofRyLIlrjX0tFPG2v25VJ6HE,262429
|
|
4
|
+
kebe_ship-0.0.6.dist-info/licenses/LICENSE,sha256=0SJU1dVe5uk0rKC9g3BKPevyAWTYQxcqVtDVW9ORk5Y,1065
|
|
5
|
+
kebe_ship-0.0.6.dist-info/METADATA,sha256=W_hSclsB7HoWJ8niP2G4PZ1o0I4Yr5fK6cELSNpeYts,2086
|
|
6
|
+
kebe_ship-0.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
+
kebe_ship-0.0.6.dist-info/top_level.txt,sha256=m2HIr7it44V-cGjgvCXioP-IfClk5ypCmZx5fUM3WSc,10
|
|
8
|
+
kebe_ship-0.0.6.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Your Name
|
|
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 @@
|
|
|
1
|
+
kebe_ship
|