Skip to content

Commit 566c34a

Browse files
Reload modules after scratch install (#316)
Changes: - For any modules in scratch that replace exisitnng dependnecies, `importlib.reload()` is called - Dockerfile now includes a larger Python container with tools needed to pip install
1 parent 789ec2d commit 566c34a

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ WORKDIR /context
2424
# install python package into /venv
2525
RUN pip install ${PIP_OPTIONS}
2626

27-
FROM python:3.11-slim as runtime
27+
FROM python:3.11 as runtime
2828

2929
# Add apt-get system dependecies for runtime here if needed
3030

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
url=f"https://github.com/{github_user}/{github_repo}/releases",
171171
)
172172
],
173+
navigation_with_keys=True,
173174
)
174175

175176
# A dictionary of values to pass into the template engine’s context for all pages

src/blueapi/service/scratch.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib
12
import logging
23
import os
34
import subprocess
@@ -44,6 +45,16 @@ def install_editable(
4445
]
4546
)
4647

48+
def reload_modules_within(self, root: Path) -> None:
49+
for module in sys.modules.values():
50+
if (
51+
hasattr(module, "__file__")
52+
and module.__file__ is not None
53+
and root in Path(module.__file__).parents
54+
):
55+
logging.info(f"Reloading {module}")
56+
importlib.reload(module)
57+
4758

4859
class ScratchManager:
4960
"""
@@ -82,7 +93,9 @@ def sync_packages(self) -> None:
8293
self._pip.install_editable(directory, [])
8394
except subprocess.CalledProcessError as ex:
8495
logging.error(f"Unable to install {directory}", ex)
85-
logging.info("Scratch packages installed")
96+
logging.info("Scratch packages installed, reloading modules")
97+
self._pip.reload_modules_within(self._root_path)
98+
logging.info("Reload complete")
8699

87100
def _get_directories_in_scratch(self) -> Set[Path]:
88101
self._check_scratch_exists()

0 commit comments

Comments
 (0)