Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit bce03cb

Browse files
committed
Add feature to install komodo-shims at the end
komodo-shims thus becomes a magic package name that if found, will always be the last pip-package to be installed. This allows such a package to overwrite endpoints that are also installed by other packages.
1 parent ea11a81 commit bce03cb

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

komodo/cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
from komodo.shell import pushd, shell
2020
from komodo.yaml_file_types import ReleaseFile, RepositoryFile
2121

22+
# If this package is included in a build, it will always
23+
# be installed as the last pip package
24+
LAST_PIP_PACKAGE_TO_INSTALL = "komodo-shims"
25+
2226

2327
class KomodoNamespace(argparse.Namespace):
2428
"""
@@ -288,7 +292,12 @@ def pip_shell_command(
288292
makeopts,
289293
]
290294

295+
komodo_shims: Optional[Tuple[str, str]] = None
291296
for pkg, ver in release_file_content.items():
297+
if pkg == LAST_PIP_PACKAGE_TO_INSTALL:
298+
# This is a magic package name that will always be installed after all other pip packages if found.
299+
komodo_shims = (pkg, ver)
300+
continue
292301
pkg_data = repository_file_content[pkg][ver]
293302
if pkg_data["make"] != "pip":
294303
continue
@@ -298,6 +307,9 @@ def pip_shell_command(
298307
)
299308
print(shell(shell_input))
300309

310+
if komodo_shims is not None:
311+
print(shell(pip_shell_command(komodo_shims[0], komodo_shims[1], None)))
312+
301313

302314
def run_post_installation_scripts_if_set(
303315
postinst: Optional[str], release_path: Path

tests/test_cli.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import shutil
33
import sys
44
from pathlib import Path
5+
from unittest.mock import Mock, patch
56

67
import pytest
8+
import yaml
79

10+
from komodo import cli
811
from komodo.cli import cli_main
912
from tests import _get_test_root
1013

@@ -234,3 +237,54 @@ def count_release_folders_to_be_deleted() -> int:
234237
assert count_release_folders_to_be_deleted() == len(test_dirs)
235238
cli_main()
236239
assert count_release_folders_to_be_deleted() == 0
240+
241+
242+
def test_komodo_shims_is_installed_at_the_end(tmpdir):
243+
(Path(tmpdir) / "release.yml").write_text(
244+
"komodo-shims: 1.0.0\npython: 3-builtin\ntreelib: 1.7.0", encoding="utf-8"
245+
)
246+
repo = {
247+
"python": {
248+
"3-builtin": {
249+
"make": "pip", # because why not
250+
"maintainer": "foo",
251+
}
252+
},
253+
"treelib": {
254+
"1.7.0": {
255+
"source": "pypi",
256+
"make": "pip",
257+
"maintainer": "bar",
258+
"depends": ["python"],
259+
}
260+
},
261+
"komodo-shims": {
262+
"1.0.0": {"source": "pypi", "make": "pip", "maintainer": "com"}
263+
},
264+
}
265+
(Path(tmpdir) / "repository.yml").write_text(yaml.dump(repo), encoding="utf-8")
266+
sys.argv = [
267+
"kmd",
268+
"--workspace",
269+
str(tmpdir),
270+
str(tmpdir / "release.yml"),
271+
str(tmpdir / "repository.yml"),
272+
"--release",
273+
"a_komodo_release_with_shims",
274+
"--prefix",
275+
str(tmpdir),
276+
]
277+
278+
mocked_shell = Mock(return_value=b"")
279+
mocked_fetch = Mock(return_value={})
280+
with patch.object(cli, "shell", mocked_shell), patch.object(
281+
cli, "fetch", mocked_fetch
282+
):
283+
cli_main()
284+
pip_install_calls = [
285+
shell_call
286+
for shell_call in mocked_shell.mock_calls
287+
if "'pip', 'install " in str(shell_call.args[0])
288+
]
289+
assert len(pip_install_calls) == 3
290+
assert "komodo-shims" in str(pip_install_calls[-1])

0 commit comments

Comments
 (0)