Skip to content

Add MANIFEST.in and Make Download Schema Accessible Through Module#156

Merged
Urist-McGit merged 3 commits intosiemens:mainfrom
Aequitosh:2025-12-download-schema-path
Dec 12, 2025
Merged

Add MANIFEST.in and Make Download Schema Accessible Through Module#156
Urist-McGit merged 3 commits intosiemens:mainfrom
Aequitosh:2025-12-download-schema-path

Conversation

@Aequitosh
Copy link
Contributor

@Aequitosh Aequitosh commented Dec 11, 2025

While packaging debsbom for Debian, I found that some tests would fail when ran by pybuild, because it is assumed that schema-download.json in a fixed path relative to the tests/ directory (L270):

@pytest.fixture(scope="session")
def dlschema():
schemapath = Path(__file__).parent / "../src/debsbom/schema/schema-download.json"
with open(schemapath) as f:
schema = json.load(f)
return schema

So, instead of loading schema-download.json in the fixture, make debsbom.schema a proper Python module and load it during module import. This makes the JSON accessible without requiring a specific directory structure.

I got the idea for this from the following band-aid fix I used for our internal packaging:

diff --git a/tests/test_download.py b/tests/test_download.py
index 5e7ccf2..672bbde 100644
--- a/tests/test_download.py
+++ b/tests/test_download.py
@@ -259,6 +259,10 @@ def test_srcpkg_with_checksum(sdl):
 @pytest.fixture(scope="session")
 def dlschema():
     schemapath = Path(__file__).parent / "../src/debsbom/schema/schema-download.json"
+
+    if not schemapath.exists():
+        schemapath = Path(__file__).parent / "../debsbom/schema/schema-download.json"
+
     with open(schemapath) as f:
         schema = json.load(f)
     return schema

Since that felt a bit too dirty to upstream, I cooked up this PR instead.

Edit: Added acc8e9a, which I was originally planning to add through a separate PR; it adds a MANIFEST.in file that ensures that everything under src/ is included in the built package. This is necessary to make schema-download.json accessible.

@Aequitosh
Copy link
Contributor Author

Ah, nevermind, this fails in CI:

ERROR tests/test_download.py - FileNotFoundError: [Errno 2] No such file or directory: '/opt/hostedtoolcache/Python/3.11.14/x64/lib/python3.11/site-packages/debsbom/schema/schema-download.json'

I wonder why it's included in the .whl for me locally, but not here... will see if I can find a fix.

Having a MANIFEST.in file is necessary so that setuptools can figure
out what files to include in the final sdist (source distribution).
By extension, this also lets Debian tooling like  pybuild / dh_python3
[0] infer what to include in the final binary Debian package.

The file contains a list of commands, each telling setuptools what
files to include or exclude in the sdist. [1]

In particular, this file ensures that
`src/debsbom/schema/schema-download.json` is included in the final
sdist, which is necessary for the `debsbom.schema` module.

[0] https://packages.debian.org/dh-python
[1] https://setuptools.pypa.io/en/latest/userguide/miscellaneous.html

Signed-off-by: Max R. Carrara <max@aequito.sh>
Make `schema` a proper Python module and load `schema-download.json`
when the module is imported. This means that the schema can be
accessed as a "quasi-constant" via `debsbom.schema.download` (similar
to `math.pi`, for example).

Note that module-level code is only executed once, namely during the
initial import of the module, which means that the file is only loaded
into memory once.

Signed-off-by: Max R. Carrara <max@aequito.sh>
Instead of loading the download result schema as fixture, access it
through the `schema` submodule of `debsbom` directly.

This avoids any unexpected errors when running the tests in an
environment where the directory structure may be slightly different,
for example when building and testing the `debsbom` package using
Debian's Python packaging tooling (pybuild specifically).

Signed-off-by: Max R. Carrara <max@aequito.sh>
@Aequitosh Aequitosh force-pushed the 2025-12-download-schema-path branch 2 times, most recently from 619e8ce to d232297 Compare December 11, 2025 15:18
@Aequitosh Aequitosh changed the title Make Download Schema Accessible Through Module Add MANIFEST.in and Make Download Schema Accessible Through Module Dec 11, 2025
@Aequitosh
Copy link
Contributor Author

Alright, seems good now. Sorry for the noise.

This was referenced Dec 11, 2025
@Urist-McGit Urist-McGit self-requested a review December 12, 2025 10:08
@Urist-McGit Urist-McGit merged commit e4f1b1e into siemens:main Dec 12, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants