iirds 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,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ name: py${{ matrix.python }}
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ python: ["3.9", "3.13"]
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - uses: actions/setup-python@v5
21
+ with:
22
+ python-version: ${{ matrix.python }}
23
+ - run: pip install -e ".[dev]"
24
+ - run: ruff check .
25
+ - run: pytest -q
@@ -0,0 +1,29 @@
1
+ # Every pull-request commit must carry a Signed-off-by line — the Developer
2
+ # Certificate of Origin, explained in CONTRIBUTING.md. Checked here rather
3
+ # than trusted, for the same reason everything else in this repository is.
4
+ name: dco
5
+
6
+ on: pull_request
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ signoff:
13
+ name: every commit certifies its origin
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ with:
18
+ fetch-depth: 0
19
+ - name: look for Signed-off-by on each commit in the range
20
+ run: |
21
+ missing=0
22
+ for sha in $(git rev-list --no-merges \
23
+ "${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}"); do
24
+ if ! git log -1 --format=%B "$sha" | grep -Eq '^Signed-off-by: .+ <.+@.+>'; then
25
+ echo "::error::commit $sha has no Signed-off-by line (git commit -s; see CONTRIBUTING.md)"
26
+ missing=1
27
+ fi
28
+ done
29
+ exit "$missing"
@@ -0,0 +1,52 @@
1
+ # Tag v* → build and publish both distributions via Trusted Publishing
2
+ # (OIDC, no tokens). Two jobs, two environments, because PyPI requires each
3
+ # pending publisher's (repo, workflow, environment) tuple to be unique per
4
+ # project name:
5
+ # project `iirds` ← environment `pypi`
6
+ # project `iirds-sdk` ← environment `pypi-sdk`
7
+ name: release
8
+
9
+ on:
10
+ push:
11
+ tags: ["v*"]
12
+
13
+ permissions:
14
+ contents: read
15
+
16
+ jobs:
17
+ publish-iirds:
18
+ runs-on: ubuntu-latest
19
+ environment: pypi
20
+ permissions:
21
+ id-token: write
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ - uses: actions/setup-python@v5
25
+ with:
26
+ python-version: "3.12"
27
+ - run: |
28
+ pip install build
29
+ python -m build --outdir dist .
30
+ - uses: pypa/gh-action-pypi-publish@release/v1
31
+ with:
32
+ packages-dir: dist
33
+
34
+ publish-iirds-sdk:
35
+ # After the main package, so the alias's `iirds==X` pin resolves the
36
+ # moment it lands.
37
+ needs: publish-iirds
38
+ runs-on: ubuntu-latest
39
+ environment: pypi-sdk
40
+ permissions:
41
+ id-token: write
42
+ steps:
43
+ - uses: actions/checkout@v4
44
+ - uses: actions/setup-python@v5
45
+ with:
46
+ python-version: "3.12"
47
+ - run: |
48
+ pip install build
49
+ python -m build --outdir dist alias
50
+ - uses: pypa/gh-action-pypi-publish@release/v1
51
+ with:
52
+ packages-dir: dist
iirds-0.1.0/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ __pycache__/
2
+ *.egg-info/
3
+ dist/
4
+ .pytest_cache/
5
+ .ruff_cache/
iirds-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Wooyong Lee (dev365code)
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
iirds-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.5
2
+ Name: iirds
3
+ Version: 0.1.0
4
+ Summary: Read and write iiRDS packages. The seed of a community SDK, held in stewardship for the iiRDS ecosystem.
5
+ Project-URL: Homepage, https://github.com/dev365code/iirds
6
+ Project-URL: Validator, https://github.com/dev365code/iirds-validate
7
+ Author-email: Wooyong Lee <zero8004paz@gmail.com>
8
+ License: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: iirds,intelligent-information,rdf,technical-documentation
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Requires-Python: >=3.9
17
+ Requires-Dist: rdflib>=6
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest; extra == 'dev'
20
+ Requires-Dist: ruff; extra == 'dev'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # iirds
24
+
25
+ Read and write [iiRDS](https://iirds.org) packages in Python.
26
+
27
+ ```sh
28
+ pip install iirds
29
+ ```
30
+
31
+ ```python
32
+ import iirds
33
+
34
+ with iirds.open("machine-docs.iirds") as pkg:
35
+ print(pkg.version, pkg.variant) # "1.3" "unrestricted"
36
+ graph = pkg.graph # rdflib.Graph of META-INF/metadata.rdf
37
+ data = pkg.read("content/topic1.xhtml")
38
+
39
+ iirds.pack("my-package-directory/") # → my-package-directory.iirds,
40
+ # mimetype first and stored,
41
+ # byte-identical on every run
42
+ ```
43
+
44
+ Deliberately small: open a container, get the metadata as an RDF graph, read
45
+ files, write a conformant container back. **It does not validate** — that is
46
+ [iirds-validate](https://github.com/dev365code/iirds-validate)'s job (185
47
+ rules, offline, CI-friendly), and keeping the two apart keeps this library at
48
+ one dependency (rdflib).
49
+
50
+ Two things the `pack()` half gets right that generic ZIP tooling gets wrong:
51
+ the `mimetype` entry is first and stored uncompressed, and packing the same
52
+ directory twice produces byte-identical output (honouring
53
+ `SOURCE_DATE_EPOCH`), so "this archive came from that directory" is checkable
54
+ with a hash instead of taken on trust.
55
+
56
+ ## Stewardship
57
+
58
+ The `iirds` name on PyPI belongs to the standard's community more than to any
59
+ one project. **Should the iiRDS Consortium want this name for an official
60
+ SDK, it will be transferred on request** — until then it does real work
61
+ rather than squatting. `iirds-sdk` is an alias of this package and travels
62
+ under the same pledge.
63
+
64
+ This is an unofficial project, not affiliated with or endorsed by the iiRDS
65
+ Consortium or tekom Deutschland e.V. "iiRDS" is used descriptively, to name
66
+ the standard these functions read and write.
67
+
68
+ ## API stability
69
+
70
+ 0.x: the surface will grow (query helpers, JSON-LD, writing metadata — in
71
+ that rough order); what is published is intended not to break. The API is
72
+ small on purpose — additions are cheap, retractions are not.
73
+
74
+ ## Licence
75
+
76
+ Apache-2.0, © 2026 Wooyong Lee. Contributions need a `Signed-off-by` line
77
+ (DCO); see the workflow in `.github/`.
iirds-0.1.0/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # iirds
2
+
3
+ Read and write [iiRDS](https://iirds.org) packages in Python.
4
+
5
+ ```sh
6
+ pip install iirds
7
+ ```
8
+
9
+ ```python
10
+ import iirds
11
+
12
+ with iirds.open("machine-docs.iirds") as pkg:
13
+ print(pkg.version, pkg.variant) # "1.3" "unrestricted"
14
+ graph = pkg.graph # rdflib.Graph of META-INF/metadata.rdf
15
+ data = pkg.read("content/topic1.xhtml")
16
+
17
+ iirds.pack("my-package-directory/") # → my-package-directory.iirds,
18
+ # mimetype first and stored,
19
+ # byte-identical on every run
20
+ ```
21
+
22
+ Deliberately small: open a container, get the metadata as an RDF graph, read
23
+ files, write a conformant container back. **It does not validate** — that is
24
+ [iirds-validate](https://github.com/dev365code/iirds-validate)'s job (185
25
+ rules, offline, CI-friendly), and keeping the two apart keeps this library at
26
+ one dependency (rdflib).
27
+
28
+ Two things the `pack()` half gets right that generic ZIP tooling gets wrong:
29
+ the `mimetype` entry is first and stored uncompressed, and packing the same
30
+ directory twice produces byte-identical output (honouring
31
+ `SOURCE_DATE_EPOCH`), so "this archive came from that directory" is checkable
32
+ with a hash instead of taken on trust.
33
+
34
+ ## Stewardship
35
+
36
+ The `iirds` name on PyPI belongs to the standard's community more than to any
37
+ one project. **Should the iiRDS Consortium want this name for an official
38
+ SDK, it will be transferred on request** — until then it does real work
39
+ rather than squatting. `iirds-sdk` is an alias of this package and travels
40
+ under the same pledge.
41
+
42
+ This is an unofficial project, not affiliated with or endorsed by the iiRDS
43
+ Consortium or tekom Deutschland e.V. "iiRDS" is used descriptively, to name
44
+ the standard these functions read and write.
45
+
46
+ ## API stability
47
+
48
+ 0.x: the surface will grow (query helpers, JSON-LD, writing metadata — in
49
+ that rough order); what is published is intended not to break. The API is
50
+ small on purpose — additions are cheap, retractions are not.
51
+
52
+ ## Licence
53
+
54
+ Apache-2.0, © 2026 Wooyong Lee. Contributions need a `Signed-off-by` line
55
+ (DCO); see the workflow in `.github/`.
@@ -0,0 +1,5 @@
1
+ # iirds-sdk
2
+
3
+ An alias of [`iirds`](https://pypi.org/project/iirds/) — install that.
4
+ Both names are held in stewardship for the iiRDS ecosystem and will be
5
+ transferred to the iiRDS Consortium on request.
@@ -0,0 +1,19 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "iirds-sdk"
7
+ version = "0.1.0"
8
+ description = "Alias of the `iirds` package. Install `iirds`; this name is held under the same stewardship pledge."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "Wooyong Lee", email = "zero8004paz@gmail.com" }]
13
+ dependencies = ["iirds==0.1.0"]
14
+
15
+ [project.urls]
16
+ Homepage = "https://github.com/dev365code/iirds"
17
+
18
+ [tool.hatch.build.targets.wheel]
19
+ packages = ["src/iirds_sdk"]
@@ -0,0 +1,5 @@
1
+ """Alias package: everything lives in `iirds`. This exists so both obvious
2
+ names resolve to the same, real library — and both travel under the same
3
+ pledge: transferred to the iiRDS Consortium on request."""
4
+ from iirds import * # noqa: F401,F403
5
+ from iirds import __version__ # noqa: F401
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "iirds"
7
+ version = "0.1.0"
8
+ description = "Read and write iiRDS packages. The seed of a community SDK, held in stewardship for the iiRDS ecosystem."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "Wooyong Lee", email = "zero8004paz@gmail.com" }]
13
+ keywords = ["iirds", "technical-documentation", "rdf", "intelligent-information"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: Apache Software License",
18
+ "Programming Language :: Python :: 3",
19
+ "Topic :: Software Development :: Libraries",
20
+ ]
21
+ dependencies = ["rdflib>=6"]
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/dev365code/iirds"
25
+ Validator = "https://github.com/dev365code/iirds-validate"
26
+
27
+ [project.optional-dependencies]
28
+ dev = ["pytest", "ruff"]
29
+
30
+ [tool.hatch.build.targets.wheel]
31
+ packages = ["src/iirds"]
32
+
33
+ [tool.ruff]
34
+ line-length = 100
35
+ target-version = "py39"
36
+
37
+ [tool.ruff.lint]
38
+ select = ["E", "F", "W", "I", "UP", "B", "C4", "SIM"]
39
+ ignore = [
40
+ "UP006", "UP007", "UP035", "UP045", # py39 target: keep typing.List / Optional
41
+ "UP031", # %-formatting matches the sibling repo's voice
42
+ "B905", # zip(strict=) is 3.10+
43
+ "E501", # long lines are the formatter's business
44
+ ]
@@ -0,0 +1,23 @@
1
+ """Read and write iiRDS packages.
2
+
3
+ This is deliberately a small library: open a package, get its metadata as an
4
+ RDF graph, read its files, and write a conformant container back. It does not
5
+ validate — that is `iirds-validate`'s job, and keeping the two apart keeps
6
+ this one dependency-light (rdflib and the standard library, nothing else).
7
+
8
+ Held in stewardship: the `iirds` name on PyPI belongs to the standard's
9
+ community more than to any one project. Should the iiRDS Consortium want the
10
+ name for an official SDK, it will be transferred on request. Until then it
11
+ does real work rather than squatting.
12
+
13
+ The API is 0.x: it will grow, and what is published here is intended not to
14
+ break. `open()` returns a `Package`; `pack()` writes one.
15
+ """
16
+ from __future__ import annotations
17
+
18
+ from ._pack import PackError, pack
19
+ from ._package import IirdsError, Package
20
+ from ._package import open_package as open # noqa: A001 - deliberate, like gzip.open
21
+
22
+ __version__ = "0.1.0"
23
+ __all__ = ["IirdsError", "PackError", "Package", "open", "pack", "__version__"]
@@ -0,0 +1,100 @@
1
+ """Writing a conformant container.
2
+
3
+ Ported from iirds-validate's packer (same author, Apache-2.0), because the
4
+ container rules people get wrong most — mimetype first and stored, stable
5
+ bytes — belong in the SDK layer that every tool shares. iirds-validate will
6
+ import from here as its own next release; until then the two copies are
7
+ byte-for-byte siblings and this header is the note that says so.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import os
12
+ import time
13
+ import zipfile
14
+ from pathlib import Path
15
+ from typing import List, Optional
16
+
17
+ from ._package import METADATA_RDF
18
+
19
+ MIMETYPE_FILE = "mimetype"
20
+ MIMETYPE_VALUE = "application/iirds+zip"
21
+
22
+ #: A fixed timestamp for every entry, so packing the same directory twice
23
+ #: produces the same bytes. Override with SOURCE_DATE_EPOCH if a build
24
+ #: system wants its own.
25
+ FIXED_TIMESTAMP = (1980, 1, 1, 0, 0, 0)
26
+
27
+
28
+ def _timestamp():
29
+ epoch = os.environ.get("SOURCE_DATE_EPOCH")
30
+ if not epoch:
31
+ return FIXED_TIMESTAMP
32
+ try:
33
+ return time.gmtime(int(epoch))[:6]
34
+ except (ValueError, OSError):
35
+ return FIXED_TIMESTAMP
36
+
37
+
38
+ #: Compressing these again wastes time and space for no gain.
39
+ ALREADY_COMPRESSED = (".png", ".jpg", ".jpeg", ".gif", ".webp", ".mp4", ".m4v",
40
+ ".mp3", ".zip", ".iirds", ".woff", ".woff2")
41
+
42
+
43
+ class PackError(Exception):
44
+ """The directory is not something that can be packed into a container."""
45
+
46
+
47
+ def _entries(source: Path) -> List[Path]:
48
+ files = sorted(p for p in source.rglob("*") if p.is_file())
49
+ mimetype = source / MIMETYPE_FILE
50
+ rest = [p for p in files if p != mimetype]
51
+ return ([mimetype] if mimetype.exists() else []) + rest
52
+
53
+
54
+ def pack(source, output=None, *, overwrite: bool = False) -> Path:
55
+ """Write `source` as a conformant .iirds archive and return its path.
56
+
57
+ The mimetype file is created if missing — a directory with
58
+ META-INF/metadata.rdf is plainly meant to be a package.
59
+ """
60
+ source = Path(source)
61
+ if not source.is_dir():
62
+ raise PackError("not a directory: %s" % source)
63
+ if not (source / METADATA_RDF).exists():
64
+ raise PackError("%s has no %s, so it is not an iiRDS container"
65
+ % (source, METADATA_RDF))
66
+
67
+ output = Path(output) if output else source.with_suffix(".iirds")
68
+ if output.suffix.lower() != ".iirds":
69
+ output = output.with_suffix(".iirds")
70
+ if output.exists() and not overwrite:
71
+ raise PackError("%s exists; pass overwrite=True to replace it" % output)
72
+ output.parent.mkdir(parents=True, exist_ok=True)
73
+
74
+ mimetype_content: Optional[bytes] = None
75
+ if (source / MIMETYPE_FILE).exists():
76
+ mimetype_content = (source / MIMETYPE_FILE).read_bytes()
77
+ if mimetype_content != MIMETYPE_VALUE.encode("ascii"):
78
+ raise PackError("%s does not contain %r; fix it rather than have this "
79
+ "overwrite it" % (MIMETYPE_FILE, MIMETYPE_VALUE))
80
+
81
+ stamp = _timestamp()
82
+ with zipfile.ZipFile(output, "w", zipfile.ZIP_DEFLATED) as archive:
83
+ # First entry, stored uncompressed — the rule every other tool gets
84
+ # wrong, and it has to happen before anything else is written.
85
+ info = zipfile.ZipInfo(MIMETYPE_FILE, date_time=stamp)
86
+ info.compress_type = zipfile.ZIP_STORED
87
+ archive.writestr(info, mimetype_content or MIMETYPE_VALUE.encode("ascii"))
88
+
89
+ for path in _entries(source):
90
+ name = path.relative_to(source).as_posix()
91
+ if name == MIMETYPE_FILE:
92
+ continue
93
+ info = zipfile.ZipInfo(name, date_time=stamp)
94
+ info.compress_type = (zipfile.ZIP_STORED
95
+ if name.lower().endswith(ALREADY_COMPRESSED)
96
+ else zipfile.ZIP_DEFLATED)
97
+ info.external_attr = 0o644 << 16
98
+ archive.writestr(info, path.read_bytes())
99
+
100
+ return output
@@ -0,0 +1,98 @@
1
+ """Reading an iiRDS container."""
2
+ from __future__ import annotations
3
+
4
+ import zipfile
5
+ from pathlib import Path
6
+ from typing import List, Optional
7
+
8
+ from rdflib import Graph, Namespace
9
+
10
+ #: Where the metadata lives; the one path iiRDS fixes.
11
+ METADATA_RDF = "META-INF/metadata.rdf"
12
+
13
+ #: The base IRI this ecosystem's tools agree on for rdf:about="" — the same
14
+ #: convention iirds-validate and its published SHACL shapes document.
15
+ PACKAGE_BASE = "urn:iirds:package:"
16
+
17
+ IIRDS = Namespace("http://iirds.tekom.de/iirds#")
18
+
19
+
20
+ class IirdsError(Exception):
21
+ """The file is not something this library can read as an iiRDS package."""
22
+
23
+
24
+ class Package:
25
+ """An opened iiRDS container. Use as a context manager, like ZipFile.
26
+
27
+ Reading is lazy: the ZIP directory is read on open, the metadata graph
28
+ only when `.graph` is first touched.
29
+ """
30
+
31
+ def __init__(self, path):
32
+ self.path = Path(path)
33
+ try:
34
+ self._zip = zipfile.ZipFile(self.path)
35
+ except (OSError, zipfile.BadZipFile) as exc:
36
+ raise IirdsError("cannot open %s as a ZIP container: %s" % (self.path, exc)) from exc
37
+ if METADATA_RDF not in self._zip.namelist():
38
+ self._zip.close()
39
+ raise IirdsError("%s has no %s, so it is not an iiRDS package"
40
+ % (self.path, METADATA_RDF))
41
+ self._graph: Optional[Graph] = None
42
+
43
+ # -- files ---------------------------------------------------------------
44
+ def names(self) -> List[str]:
45
+ """Every entry in the container, in archive order."""
46
+ return self._zip.namelist()
47
+
48
+ def read(self, name: str) -> bytes:
49
+ return self._zip.read(name)
50
+
51
+ # -- metadata ------------------------------------------------------------
52
+ @property
53
+ def graph(self) -> Graph:
54
+ """META-INF/metadata.rdf as an rdflib Graph, parsed against the
55
+ `urn:iirds:package:` base so rdf:about="" resolves the way the
56
+ ecosystem's validators and shapes expect."""
57
+ if self._graph is None:
58
+ graph = Graph()
59
+ graph.parse(data=self.read(METADATA_RDF), format="xml", publicID=PACKAGE_BASE)
60
+ self._graph = graph
61
+ return self._graph
62
+
63
+ @property
64
+ def version(self) -> Optional[str]:
65
+ """The declared iiRDSVersion, stripped, or None if the package omits
66
+ it. No judgement about whether it is a published version — that is
67
+ validation, which lives in iirds-validate."""
68
+ for _s, value in self.graph.subject_objects(IIRDS.iiRDSVersion):
69
+ return str(value).strip()
70
+ return None
71
+
72
+ @property
73
+ def variant(self) -> str:
74
+ """"A", "H", or "unrestricted" — from iirds:formatRestriction, with an
75
+ absent or blank value meaning unrestricted, as the standard reads."""
76
+ for _s, value in self.graph.subject_objects(IIRDS.formatRestriction):
77
+ text = str(value).strip()
78
+ if text:
79
+ return text
80
+ return "unrestricted"
81
+
82
+ # -- lifecycle -----------------------------------------------------------
83
+ def close(self) -> None:
84
+ self._zip.close()
85
+
86
+ def __enter__(self) -> Package:
87
+ return self
88
+
89
+ def __exit__(self, *exc) -> None:
90
+ self.close()
91
+
92
+ def __repr__(self) -> str:
93
+ return "Package(%r)" % str(self.path)
94
+
95
+
96
+ def open_package(path) -> Package:
97
+ """Open an .iirds container for reading."""
98
+ return Package(path)
@@ -0,0 +1,68 @@
1
+ """The SDK's one promise: what pack() writes, open() reads, faithfully."""
2
+ import zipfile
3
+
4
+ import pytest
5
+
6
+ import iirds
7
+
8
+ MINIMAL_RDF = """<?xml version="1.0" encoding="utf-8"?>
9
+ <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
10
+ xmlns:iirds="http://iirds.tekom.de/iirds#">
11
+ <iirds:Package rdf:about="urn:test:package">
12
+ <iirds:iiRDSVersion> 1.3 </iirds:iiRDSVersion>
13
+ <iirds:title>SDK fixture</iirds:title>
14
+ </iirds:Package>
15
+ </rdf:RDF>
16
+ """
17
+
18
+
19
+ @pytest.fixture
20
+ def source(tmp_path):
21
+ root = tmp_path / "pkg"
22
+ (root / "META-INF").mkdir(parents=True)
23
+ (root / "META-INF" / "metadata.rdf").write_text(MINIMAL_RDF, "utf-8")
24
+ (root / "content").mkdir()
25
+ (root / "content" / "topic1.xhtml").write_text("<html/>", "utf-8")
26
+ return root
27
+
28
+
29
+ def test_pack_then_open_round_trips(source):
30
+ packed = iirds.pack(source)
31
+ with iirds.open(packed) as pkg:
32
+ assert pkg.version == "1.3" # stripped, as consumers compare it
33
+ assert pkg.variant == "unrestricted"
34
+ assert "content/topic1.xhtml" in pkg.names()
35
+ assert pkg.read("content/topic1.xhtml") == b"<html/>"
36
+ assert len(pkg.graph) >= 2
37
+
38
+
39
+ def test_mimetype_is_first_and_stored(source):
40
+ packed = iirds.pack(source)
41
+ with zipfile.ZipFile(packed) as archive:
42
+ first = archive.infolist()[0]
43
+ assert first.filename == "mimetype"
44
+ assert first.compress_type == zipfile.ZIP_STORED
45
+ assert archive.read("mimetype") == b"application/iirds+zip"
46
+
47
+
48
+ def test_packing_twice_produces_identical_bytes(source, tmp_path):
49
+ one = iirds.pack(source, tmp_path / "a.iirds")
50
+ two = iirds.pack(source, tmp_path / "b.iirds")
51
+ assert one.read_bytes() == two.read_bytes()
52
+
53
+
54
+ def test_a_zip_without_metadata_is_refused(tmp_path):
55
+ plain = tmp_path / "plain.zip"
56
+ with zipfile.ZipFile(plain, "w") as archive:
57
+ archive.writestr("hello.txt", "hi")
58
+ with pytest.raises(iirds.IirdsError):
59
+ iirds.open(plain)
60
+
61
+
62
+ def test_variant_reads_h(source):
63
+ meta = source / "META-INF" / "metadata.rdf"
64
+ meta.write_text(MINIMAL_RDF.replace(
65
+ "</iirds:Package>",
66
+ " <iirds:formatRestriction>H</iirds:formatRestriction>\n </iirds:Package>"), "utf-8")
67
+ with iirds.open(iirds.pack(source, overwrite=True)) as pkg:
68
+ assert pkg.variant == "H"