fix(package): resolve source paths relative to package root

This commit is contained in:
PierreCsn committed 2026-10-28 16:43:39 +01:00
1 parent f859ff536c
commit 1afb3a2b73
6 files changed
+31 -10

No files matched your search

+1 -1
View File
@@ -105,7 +105,7 @@ utiliser **Build and upload** avant la vérification du fichier construit.
Inspecter le `.wapt` réellement généré : Inspecter le `.wapt` réellement généré :
```powershell ```powershell
waptpython tools\package_verify.py --wapt .\comi-audit-hardeningkitty_0.9.8-0_all.wapt waptpython tools\package_verify.py --wapt .\comi-audit-hardeningkitty_0.9.9-0_all.wapt
``` ```
Cette vérification ouvre l’archive ZIP `.wapt` et contrôle les scripts, Cette vérification ouvre l’archive ZIP `.wapt` et contrôle les scripts,
+1 -1
View File
@@ -1,5 +1,5 @@
package : comi-audit-hardeningkitty package : comi-audit-hardeningkitty
version : 0.9.8-0 version : 0.9.9-0
architecture : all architecture : all
section : base section : base
priority : optional priority : optional
+2 -2
View File
@@ -1,9 +1,9 @@
{ {
"files": { "files": {
"WAPT/control": "ed77db7becfcaf15b7c95b5f169294b1afe320fdcef657f59cb5df2f6b133d14", "WAPT/control": "2d42c593fb406bf1ce99efdfa61ccfc053eb2cf125a181d12a0725494a11e566",
"audit_config.json": "9fc18f556fd491e8e00e3a8b1efd864ad8036682e293a02c1f81f3411304a69b", "audit_config.json": "9fc18f556fd491e8e00e3a8b1efd864ad8036682e293a02c1f81f3411304a69b",
"runner.ps1": "5e9787f5cc19d0fc4c0ede01a63188ed71de6ef49df596fbce7b2603093231cd", "runner.ps1": "5e9787f5cc19d0fc4c0ede01a63188ed71de6ef49df596fbce7b2603093231cd",
"setup.py": "e187cbfdd61d96e68b940f124924d2f09ad3d18eb3987116ab55937dea18dc06", "setup.py": "a7fb150a1c4f3ccb64f68b83fb7670c011b4434634dd7baa62b67d3050d4959e",
"vendor/HardeningKitty.psd1": "94378764787cd0c7125c5c3ce928803b46ee7d7d3fe21c2b27ddeb23c11377a7", "vendor/HardeningKitty.psd1": "94378764787cd0c7125c5c3ce928803b46ee7d7d3fe21c2b27ddeb23c11377a7",
"vendor/HardeningKitty.psm1": "b799ec1b17de5ce63f7a8ea34af3beba1d24fcaddf7e3774f797096f5c43e2a0", "vendor/HardeningKitty.psm1": "b799ec1b17de5ce63f7a8ea34af3beba1d24fcaddf7e3774f797096f5c43e2a0",
"vendor/LICENSE": "a879ba6ccdcd2ea55da97b999edd2c401c8589ca946f238236bf93aa40e74d56", "vendor/LICENSE": "a879ba6ccdcd2ea55da97b999edd2c401c8589ca946f238236bf93aa40e74d56",
+6 -3
View File
@@ -49,16 +49,19 @@ REQUIRED_VENDOR_FILES = (
def _source_directory(): def _source_directory():
"""Find package root and return it relative to the current working directory."""
candidates = [] candidates = []
if globals().get('__file__'): if globals().get('__file__'):
candidates.append(os.path.dirname(os.path.abspath(__file__))) candidates.append(os.path.dirname(os.path.abspath(__file__)))
for name in ('basedir', 'package_dir'): for name in ('basedir', 'package_dir'):
if globals().get(name): if globals().get(name):
candidates.append(os.path.abspath(globals()[name])) candidates.append(os.path.abspath(globals()[name]))
candidates.append(os.getcwd()) current_directory = os.getcwd()
candidates.append(current_directory)
for candidate in candidates: for candidate in candidates:
if os.path.isfile(os.path.join(candidate, 'WAPT', 'control')): relative_candidate = os.path.relpath(os.path.abspath(candidate), current_directory)
return candidate if os.path.isfile(os.path.join(relative_candidate, 'WAPT', 'control')):
return relative_candidate
raise RuntimeError('Cannot locate WAPT source directory (WAPT/control not found).') raise RuntimeError('Cannot locate WAPT source directory (WAPT/control not found).')
+19 -1
View File
@@ -356,7 +356,12 @@ class PackageTests(unittest.TestCase):
original_cwd = os.getcwd() original_cwd = os.getcwd()
try: try:
os.chdir(tmp) os.chdir(tmp)
self.assertEqual(updater._source_directory(), ROOT) source_root = updater._source_directory()
self.assertFalse(os.path.isabs(source_root))
self.assertTrue((Path(source_root) / 'WAPT' / 'control').is_file())
self.assertEqual(Path(source_root).resolve(), ROOT)
os.chdir(ROOT)
self.assertEqual(updater._source_directory(), Path('.'))
finally: finally:
os.chdir(original_cwd) os.chdir(original_cwd)
@@ -385,6 +390,19 @@ class PackageTests(unittest.TestCase):
updater._load_tool = old_loader updater._load_tool = old_loader
self.assertEqual([call[0] for call in calls], ['vendor', 'manifest', 'verify'] * 2) self.assertEqual([call[0] for call in calls], ['vendor', 'manifest', 'verify'] * 2)
def test_setup_source_directory_is_relative_to_package_root(self):
original_cwd = os.getcwd()
try:
os.chdir(ROOT)
self.assertEqual(pkg._source_directory(), '.')
with tempfile.TemporaryDirectory() as tmp:
os.chdir(tmp)
source_root = pkg._source_directory()
self.assertFalse(os.path.isabs(source_root))
self.assertTrue(os.path.isfile(os.path.join(source_root, 'WAPT', 'control')))
finally:
os.chdir(original_cwd)
def test_offline_updater_requires_expected_archive_hash(self): def test_offline_updater_requires_expected_archive_hash(self):
with tempfile.TemporaryDirectory() as tmp: with tempfile.TemporaryDirectory() as tmp:
archive = Path(tmp, 'archive.zip') archive = Path(tmp, 'archive.zip')
+2 -2
View File
@@ -7,8 +7,8 @@ import sys
def _source_directory(): def _source_directory():
"""Find the package source from this file, independent of the current cwd.""" """Find package root and return its path relative to the current directory."""
source = Path(__file__).resolve().parent source = Path(os.path.relpath(Path(__file__).resolve().parent, Path.cwd()))
if not (source / 'WAPT' / 'control').is_file(): if not (source / 'WAPT' / 'control').is_file():
raise RuntimeError('update_package.py must be inside a WAPT package source directory.') raise RuntimeError('update_package.py must be inside a WAPT package source directory.')
return source return source