From 6cc92ba4022118019d822179dffbd7434dfad10f Mon Sep 17 00:00:00 2001 From: Agah Date: Tue, 5 Nov 2024 21:10:44 +0300 Subject: [PATCH] build exec conditional --- myst_libre/builders/myst_builder.py | 35 +++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/myst_libre/builders/myst_builder.py b/myst_libre/builders/myst_builder.py index b3f0a67..648074f 100644 --- a/myst_libre/builders/myst_builder.py +++ b/myst_libre/builders/myst_builder.py @@ -2,22 +2,33 @@ from myst_libre.abstract_class import AbstractClass class MystBuilder(AbstractClass): - def __init__(self, hub): - if not isinstance(hub, JupyterHubLocalSpawner): - raise TypeError(f"Expected 'hub' to be an instance of JupyterHubLocalSpawner, got {type(hub).__name__} instead") + def __init__(self, hub=None, build_dir=None): + if hub is not None: + if not isinstance(hub, JupyterHubLocalSpawner): + raise TypeError(f"Expected 'hub' to be an instance of JupyterHubLocalSpawner, got {type(hub).__name__} instead") + self.hub = hub + self.env_vars = { + "JUPYTER_BASE_URL": f"{self.hub.jh_url}", + "JUPYTER_TOKEN": f"{self.hub.jh_token}", + "port": f"{self.hub.port}" + } + self.build_dir = self.hub.rees.build_dir + else: + if build_dir is None: + raise ValueError("If 'hub' is None, 'build_dir' must be provided") + self.build_dir = build_dir + self.env_vars = {} + self.hub = None + super().__init__() - self.env_vars = {} - self.build_dir = "" - self.hub = hub - self.env_vars = {"JUPYTER_BASE_URL":f"{self.hub.jh_url}", - "JUPYTER_TOKEN":f"{self.hub.jh_token}", - "port":f"{self.hub.port}" - } - self.myst_client = MystMD(hub.rees.build_dir, self.env_vars) + self.myst_client = MystMD(self.build_dir, self.env_vars) def setenv(self,key,value): self.env_vars[key] = value def build(self,*args): - self.cprint(f'Starting MyST build {self.hub.jh_url}','yellow') + if self.hub is not None: + self.cprint(f'Starting MyST build {self.hub.jh_url}','yellow') + else: + self.cprint(f'Starting MyST build no exec.','yellow') self.myst_client.build('build',*args) \ No newline at end of file