Skip to content

Commit 2aebb18

Browse files
committed
Fix keywords not being loaded for child processes
Remove redundant conditions with ollama trigger
1 parent 884fbeb commit 2aebb18

File tree

6 files changed

+60
-47
lines changed

6 files changed

+60
-47
lines changed

docs/index.html

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7352,11 +7352,20 @@ <h1>Crontab<a class="headerlink" href="#id2" title="Permalink to this heading">
73527352
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
73537353
<dd class="field-odd"><p><strong>filename</strong> – Name of the env file.</p>
73547354
</dd>
7355-
<dt class="field-even">Returns<span class="colon">:</span></dt>
7356-
<dd class="field-even"><p>Loads the <code class="docutils literal notranslate"><span class="pre">EnvConfig</span></code> model.</p>
7355+
</dl>
7356+
<div class="admonition seealso">
7357+
<p class="admonition-title">See also</p>
7358+
<ul class="simple">
7359+
<li><p>Loading environment variables from files are an additional feature.</p></li>
7360+
<li><p>Both the system’s and session’s env vars are processed by default.</p></li>
7361+
</ul>
7362+
</div>
7363+
<dl class="field-list simple">
7364+
<dt class="field-odd">Returns<span class="colon">:</span></dt>
7365+
<dd class="field-odd"><p>Loads the <code class="docutils literal notranslate"><span class="pre">EnvConfig</span></code> model.</p>
73577366
</dd>
7358-
<dt class="field-odd">Return type<span class="colon">:</span></dt>
7359-
<dd class="field-odd"><p><a class="reference internal" href="#jarvis.modules.models.classes.EnvConfig" title="jarvis.modules.models.classes.EnvConfig">EnvConfig</a></p>
7367+
<dt class="field-even">Return type<span class="colon">:</span></dt>
7368+
<dd class="field-even"><p><a class="reference internal" href="#jarvis.modules.models.classes.EnvConfig" title="jarvis.modules.models.classes.EnvConfig">EnvConfig</a></p>
73607369
</dd>
73617370
</dl>
73627371
</dd></dl>

docs/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jarvis/__init__.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
version = "5.0.0"
77

8-
if current_process().name == "MainProcess":
9-
current_process().name = os.environ.get("PROCESS_NAME", "JARVIS")
10-
118

129
def __preflight_check__() -> Callable:
1310
"""Startup validator that imports Jarvis' main module to validate all dependencies' installation status.
@@ -43,34 +40,40 @@ def start() -> None:
4340

4441
def commandline() -> None:
4542
"""Starter function to invoke Jarvis using commandline."""
46-
if sys.argv[0].endswith("jarvis"):
47-
choices = "\n\t* " + "\n\t* ".join(
48-
("install", "dev-install", "start | run", "version | -v | --version | -V")
43+
# This is to validate that only 'jarvis' command triggers this function and not invoked by other functions
44+
assert sys.argv[0].endswith("jarvis"), "Invalid commandline trigger!!"
45+
_pretext = "\n\t* "
46+
choices = _pretext + _pretext.join(
47+
("install", "dev-install", "start | run", "version | -v | --version | -V")
48+
)
49+
try:
50+
arg = sys.argv[1].lower()
51+
except (IndexError, AttributeError):
52+
print(
53+
f"Cannot proceed without arbitrary commands. Please choose from {choices}"
4954
)
50-
try:
51-
arg = sys.argv[1].lower()
52-
except (IndexError, AttributeError):
53-
print(
54-
f"Cannot proceed without arbitrary commands. Please choose from {choices}"
55-
)
56-
exit(1)
57-
match arg:
58-
case "install":
59-
from jarvis.lib import install # noqa: F401
55+
exit(1)
56+
match arg:
57+
case "install":
58+
from jarvis.lib import install # noqa: F401
59+
60+
install.main()
61+
case "dev-install":
62+
from jarvis.lib import install # noqa: F401
63+
64+
install.dev()
65+
case "start" | "run":
66+
init = __preflight_check__()
67+
init()
68+
case "version" | "-v" | "-V" | "--version":
69+
print(f"Jarvis {version}")
70+
case _:
71+
print(f"Unknown Option: {arg}\nArbitrary commands must be one of {choices}")
6072

61-
install.main()
62-
case "dev-install":
63-
from jarvis.lib import install # noqa: F401
6473

65-
install.dev()
66-
case "start" | "run":
67-
init = __preflight_check__()
68-
init()
69-
case "version" | "-v" | "-V" | "--version":
70-
print(f"Jarvis {version}")
71-
case _:
72-
print(
73-
f"Unknown Option: {arg}\nArbitrary commands must be one of {choices}"
74-
)
75-
else:
76-
__preflight_check__()
74+
# MainProcess has specific conditions to land at 'start' or 'commandline'
75+
# __preflight_check__ still needs to be loaded for all other child processes
76+
if current_process().name == "MainProcess":
77+
current_process().name = os.environ.get("PROCESS_NAME", "JARVIS")
78+
else:
79+
__preflight_check__()

jarvis/modules/models/classes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,10 @@ def from_env_file(cls, filename: pathlib.Path) -> "EnvConfig":
553553
Args:
554554
filename: Name of the env file.
555555
556+
See Also:
557+
- Loading environment variables from files are an additional feature.
558+
- Both the system's and session's env vars are processed by default.
559+
556560
Returns:
557561
EnvConfig:
558562
Loads the ``EnvConfig`` model.

jarvis/modules/models/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@
6262
}
6363
KEEP_TABLES = ("vpn", "party", "listener") # TABLES to keep from `fileio.base_db`
6464
startup = settings.pname in ("JARVIS", "telegram_api", "jarvis_api")
65-
if startup and env.startup_options and StartupOptions.all in env.startup_options:
65+
# 'startup_gpt' is required since it has to be invoked only for certain child processes
66+
# this will avoid running GPT instance for pre-commit as well
67+
if startup and StartupOptions.all in env.startup_options:
6668
startup_car = True
67-
startup_gpt = True
69+
startup_gpt = env.ollama
6870
startup_thermostat = True
69-
elif startup and env.startup_options:
71+
elif startup:
7072
startup_car = StartupOptions.car in env.startup_options
71-
# Hard coded since GPT has its own trigger 'ollama' and it's not actually a background functionality
72-
startup_gpt = True
73+
startup_gpt = env.ollama
7374
startup_thermostat = StartupOptions.thermostat in env.startup_options
7475
else:
7576
startup_car = False
76-
# Hard coded since GPT has its own trigger 'ollama' and it's not actually a background functionality
7777
startup_gpt = False
7878
startup_thermostat = False
7979

jarvis/modules/transformer/gpt.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def query(self, phrase: str) -> None:
279279
static_responses.un_processable()
280280

281281

282-
if models.startup_gpt and models.env.ollama:
282+
if models.startup_gpt:
283283
if models.env.ollama_reuse_threshold:
284284
start = (
285285
f"Initiating GPT instance for {models.settings.pname!r} with a "
@@ -300,8 +300,5 @@ def query(self, phrase: str) -> None:
300300
logger.error("Failed to load GPT instance for '%s'", models.settings.pname)
301301
instance = None
302302
else:
303-
if models.startup_gpt and not models.env.ollama:
304-
logger.warning(
305-
"GPT has been disabled! To enable it, set the env var ollama=True"
306-
)
303+
logger.warning("GPT has been disabled! To enable it, set the env var ollama=True")
307304
instance = None

0 commit comments

Comments
 (0)