Skip to content

Commit

Permalink
Remove support for legacy macOS machines
Browse files Browse the repository at this point in the history
Add global validations for crontab executions
  • Loading branch information
dormant-user committed Jul 21, 2024
1 parent c11ccd3 commit 899e21b
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 110 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jarvis start
> Use `jarvis --help` for usage instructions.
## Prerequisites
- **MacOS** <br> _Tested on **macOS High Sierra, Mojave, Catalina, Big Sur, Monterey and Ventura**_
- **MacOS** <br> _Tested on **Mojave, Catalina, Big Sur, Monterey and Ventura**_
- `System Preferences``Security & Privacy``Privacy`
- Click `+` sign and add the preferred `IDE` and `Terminal` in the following sections in left pane.
- `Microphone` - **Required** to listen and respond.
Expand Down
2 changes: 1 addition & 1 deletion docs/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ <h1>Kick off<a class="headerlink" href="#kick-off" title="Permalink to this head
<section id="prerequisites">
<h1>Prerequisites<a class="headerlink" href="#prerequisites" title="Permalink to this heading"></a></h1>
<ul class="simple">
<li><p><strong>MacOS</strong> <br> <em>Tested on <strong>macOS High Sierra, Mojave, Catalina, Big Sur, Monterey and Ventura</strong></em></p>
<li><p><strong>MacOS</strong> <br> <em>Tested on <strong>Mojave, Catalina, Big Sur, Monterey and Ventura</strong></em></p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">System</span> <span class="pre">Preferences</span></code><code class="docutils literal notranslate"><span class="pre">Security</span> <span class="pre">&amp;</span> <span class="pre">Privacy</span></code><code class="docutils literal notranslate"><span class="pre">Privacy</span></code></p></li>
<li><p>Click <code class="docutils literal notranslate"><span class="pre">+</span></code> sign and add the preferred <code class="docutils literal notranslate"><span class="pre">IDE</span></code> and <code class="docutils literal notranslate"><span class="pre">Terminal</span></code> in the following sections in left pane.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jarvis start
> Use `jarvis --help` for usage instructions.
## Prerequisites
- **MacOS** <br> _Tested on **macOS High Sierra, Mojave, Catalina, Big Sur, Monterey and Ventura**_
- **MacOS** <br> _Tested on **Mojave, Catalina, Big Sur, Monterey and Ventura**_
- `System Preferences``Security & Privacy``Privacy`
- Click `+` sign and add the preferred `IDE` and `Terminal` in the following sections in left pane.
- `Microphone` - **Required** to listen and respond.
Expand Down
2 changes: 1 addition & 1 deletion docs/_sources/README.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jarvis start
> Use `jarvis --help` for usage instructions.

## Prerequisites
- **MacOS** <br> _Tested on **macOS High Sierra, Mojave, Catalina, Big Sur, Monterey and Ventura**_
- **MacOS** <br> _Tested on **Mojave, Catalina, Big Sur, Monterey and Ventura**_
- `System Preferences` → `Security & Privacy` → `Privacy`
- Click `+` sign and add the preferred `IDE` and `Terminal` in the following sections in left pane.
- `Microphone` - **Required** to listen and respond.
Expand Down
12 changes: 7 additions & 5 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -2030,8 +2030,6 @@ <h2 id="L">L</h2>
</li>
</ul></li>
<li><a href="index.html#jarvis.modules.facenet.face.FaceNet.LEARNING_RATE">LEARNING_RATE (jarvis.modules.facenet.face.FaceNet attribute)</a>
</li>
<li><a href="index.html#jarvis.modules.models.classes.Settings.legacy">legacy (jarvis.modules.models.classes.Settings attribute)</a>
</li>
<li><a href="index.html#jarvis.modules.tv.lg.LGWebOS">LGWebOS (class in jarvis.modules.tv.lg)</a>
</li>
Expand Down Expand Up @@ -2065,10 +2063,10 @@ <h2 id="L">L</h2>
</ul></li>
<li><a href="index.html#jarvis.modules.camera.camera.list_splitter">list_splitter() (in module jarvis.modules.camera.camera)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#jarvis.modules.audio.listener.listen">listen() (in module jarvis.modules.audio.listener)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="index.html#jarvis.modules.audio.listener.listen_recursive">listen_recursive() (in module jarvis.modules.audio.listener)</a>
</li>
<li><a href="index.html#jarvis.executors.listener_controls.listener_control">listener_control() (in module jarvis.executors.listener_controls)</a>
Expand Down Expand Up @@ -3064,8 +3062,12 @@ <h2 id="S">S</h2>
</li>
<li><a href="index.html#jarvis.executors.controls.starter">starter() (in module jarvis.executors.controls)</a>
</li>
<li><a href="index.html#jarvis.modules.tv.roku.RokuECP.startup">startup() (jarvis.modules.tv.roku.RokuECP method)</a>
<li><a href="index.html#jarvis.api.main.startup">startup() (in module jarvis.api.main)</a>

<ul>
<li><a href="index.html#jarvis.modules.tv.roku.RokuECP.startup">(jarvis.modules.tv.roku.RokuECP method)</a>
</li>
</ul></li>
<li><a href="index.html#jarvis.modules.models.classes.FileIO.startup_dir">startup_dir (jarvis.modules.models.classes.FileIO attribute)</a>
</li>
<li><a href="index.html#jarvis.api.main.startup_func">startup_func() (in module jarvis.api.main)</a>
Expand Down
13 changes: 7 additions & 6 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,12 @@ <h1>———-Jarvis API———-<a class="headerlink" href="#jarvis-api" title
<dd><p>Allow CORS: Cross-Origin Resource Sharing to allow restricted resources on the API.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="jarvis.api.main.startup">
<span class="sig-prename descclassname"><span class="pre">jarvis.api.main.</span></span><span class="sig-name descname"><span class="pre">startup</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#jarvis.api.main.startup" title="Permalink to this definition">¶</a></dt>
<dd><p>Runs startup scripts (<code class="docutils literal notranslate"><span class="pre">.py</span></code>, <code class="docutils literal notranslate"><span class="pre">.sh</span></code>, <code class="docutils literal notranslate"><span class="pre">.zsh</span></code>) stored in <code class="docutils literal notranslate"><span class="pre">fileio/startup</span></code> directory.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="jarvis.api.main.startup_func">
<em class="property"><span class="k"><span class="pre">async</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">jarvis.api.main.</span></span><span class="sig-name descname"><span class="pre">startup_func</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#jarvis.api.main.startup_func" title="Permalink to this definition">¶</a></dt>
Expand Down Expand Up @@ -3407,7 +3413,7 @@ <h1>———-Executors———-<a class="headerlink" href="#executors" title="
<dl class="py method">
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">-</span> <span class="pre">volume</span></span></dt>
<dd><p>To default the master volume 50%.</p>
<dd><p>To default the master volume a specific percent.</p>
</dd></dl>

<dl class="py method">
Expand Down Expand Up @@ -5753,11 +5759,6 @@ <h1>———-Models———-<a class="headerlink" href="#models" title="Permal
<span class="sig-name descname"><span class="pre">os</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">str</span></em><a class="headerlink" href="#jarvis.modules.models.classes.Settings.os" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="jarvis.modules.models.classes.Settings.legacy">
<span class="sig-name descname"><span class="pre">legacy</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">bool</span></em><a class="headerlink" href="#jarvis.modules.models.classes.Settings.legacy" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="jarvis.modules.models.classes.Settings.model_post_init">
<span class="sig-name descname"><span class="pre">model_post_init</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">__context</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Any</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#jarvis.modules.models.classes.Settings.model_post_init" title="Permalink to this definition">¶</a></dt>
Expand Down
Binary file modified docs/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions jarvis/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@ def enable_cors() -> None:
app.include_router(router)


@app.on_event(event_type="startup")
async def startup_func() -> None:
"""Simple startup function to add anything that has to be triggered when Jarvis API starts up."""
logger.info(
"Hosting at http://%s:%s", models.env.offline_host, models.env.offline_port
)
if models.env.author_mode:
Thread(target=stockanalysis_squire.nasdaq).start()
def startup() -> None:
"""Runs startup scripts (``.py``, ``.sh``, ``.zsh``) stored in ``fileio/startup`` directory."""
if not os.path.isdir(models.fileio.startup_dir):
return
for startup_script in os.listdir(models.fileio.startup_dir):
Expand Down Expand Up @@ -102,3 +96,14 @@ async def startup_func() -> None:
logger.warning(
"Unsupported file format for startup script: %s", startup_script
)


@app.on_event(event_type="startup")
async def startup_func() -> None:
"""Simple startup function to add anything that has to be triggered when Jarvis API starts up."""
logger.info(
"Hosting at http://%s:%s", models.env.offline_host, models.env.offline_port
)
if models.env.author_mode:
Thread(target=stockanalysis_squire.nasdaq).start()
startup()
2 changes: 1 addition & 1 deletion jarvis/executors/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def starter() -> None:
Methods:
- put_listener_state: To activate listener enabling voice conversations.
- volume: To default the master volume 50%.
- volume: To default the master volume a specific percent.
- voices: To change the voice to default value.
- delete_logs: To purge log files older than the set log retention time.
- delete_pycache: To purge pycache directories.
Expand Down
39 changes: 14 additions & 25 deletions jarvis/lib/install_darwin.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,23 @@ brew install portaudio coreutils ffmpeg lame
# Install macOS specifics
python -m pip install playsound==1.3.0 ftransc==7.0.3 pyobjc-framework-CoreWLAN==9.0.1

# Checks current version and installs legacy version of dependencies if macOS is older han 10.14
base_ver="10.14" # Versions older than Mojave (High Sierra and older versions)
os_ver=$(sw_vers | grep ProductVersion | cut -d':' -f2 | tr -d ' ' | xargs)
# Uninstall any remaining cmake packages from pypi before brew installing it to avoid conflict
python -m pip uninstall --no-cache --no-cache-dir cmake && brew install cmake
if awk "BEGIN {exit !($base_ver > $os_ver)}"; then
echo ""
echo "*****************************************************************************************************************"
echo " macOS $os_ver will be deprecated in the near future"
echo " Please upgrade to $base_ver to continue using Jarvis"
echo "*****************************************************************************************************************"
echo ""
python -m pip install pvporcupine==1.6.0 dlib==19.21.0 opencv-python==4.4.0.44

# shellcheck disable=SC2154
if [ "$pyversion" -eq 310 ]; then
python -m pip install dlib==19.24.0
fi
if [ "$pyversion" -eq 311 ]; then
python -m pip install dlib==19.24.4
fi
python -m pip install opencv-python==4.9.0.80

# shellcheck disable=SC2154
if [[ "$architecture" == "arm64" ]]; then
python -m pip install pvporcupine==3.0.2
else
# shellcheck disable=SC2154
if [ "$pyversion" -eq 310 ]; then
python -m pip install dlib==19.24.0
fi
if [ "$pyversion" -eq 311 ]; then
python -m pip install dlib==19.24.4
fi
python -m pip install opencv-python==4.9.0.80
# shellcheck disable=SC2154
if [[ "$architecture" == "arm64" ]]; then
python -m pip install pvporcupine==3.0.2
else
python -m pip install pvporcupine==1.9.5
fi
python -m pip install pvporcupine==1.9.5
fi

# Install as stand alone as face recognition depends on dlib
Expand Down
19 changes: 4 additions & 15 deletions jarvis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ def constructor() -> Dict[str, str | List[float] | List[str]]:
if models.WAKE_WORD_DETECTOR == "1.9.5":
arguments["library_path"] = pvporcupine.LIBRARY_PATH
keyword_paths = [pvporcupine.KEYWORD_PATHS[x] for x in models.env.wake_words]
if models.settings.legacy:
arguments["model_file_path"] = pvporcupine.MODEL_PATH
arguments["keyword_file_paths"] = keyword_paths
else:
arguments["model_path"] = pvporcupine.MODEL_PATH
arguments["keyword_paths"] = keyword_paths
arguments["model_path"] = pvporcupine.MODEL_PATH
arguments["keyword_paths"] = keyword_paths
elif Version(models.WAKE_WORD_DETECTOR) >= Version("3.0.2"):
arguments["access_key"] = models.env.porcupine_key
else:
Expand Down Expand Up @@ -149,7 +145,6 @@ def executor(self) -> None:
def start(self) -> None:
"""Runs ``audio_stream`` in a forever loop and calls ``initiator`` when the phrase ``Jarvis`` is heard."""
try:
wake_len = len(models.env.wake_words)
support.write_screen(text=self.label)
while True:
result = self.detector.process(
Expand All @@ -161,14 +156,8 @@ def start(self) -> None:
),
)
)
if models.settings.legacy:
if wake_len == 1 and result:
self.executor()
elif wake_len > 1 and result >= 0:
self.executor()
else:
if result >= 0:
self.executor()
if result >= 0:
self.executor()
if models.settings.limited:
continue
restart_checker()
Expand Down
12 changes: 5 additions & 7 deletions jarvis/modules/models/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ class Settings(BaseModel):
distro: str = squire.get_distributor_info_linux()

os: str = platform.system()
legacy: bool = False
if os == enums.SupportedPlatforms.macOS and Version(
platform.mac_ver()[0]
) < Version("10.14"):
legacy: bool = True
raise DeprecationWarning(
f"\nmacOS {platform.mac_ver()[0]} has been deprecated\n"
f"Please upgrade to 10.14 or above to continue using Jarvis",
)


settings = Settings()
Expand Down Expand Up @@ -354,11 +356,7 @@ class EnvConfig(BaseSettings):
wifi_password: str | None = None
connection_retry: PositiveInt | PositiveFloat = 10

# Legacy macOS config
if settings.legacy:
wake_words: List[str] = ["alexa"]
else:
wake_words: List[str] = ["jarvis"]
wake_words: List[str] = ["jarvis"]

class Config:
"""Environment variables configuration."""
Expand Down
54 changes: 16 additions & 38 deletions jarvis/modules/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import os
import pathlib
import platform
import warnings
from importlib import metadata

Expand Down Expand Up @@ -128,38 +127,16 @@ def _set_default_voice_name() -> None:

def _main_process_validations() -> None:
"""Validations that should happen only when the main process is triggered."""
if settings.legacy:
try:
assert WAKE_WORD_DETECTOR == "1.6.0"
except AssertionError:
raise DependencyError(
"Legacy macOS is only supported with porcupine version 1.6.0"
)
pvporcupine.KEYWORD_PATHS = {}
base_path = os.path.dirname(pvporcupine.__file__)
pvporcupine.MODEL_PATH = os.path.join(
base_path, "lib/common/porcupine_params.pv"
try:
# 3.0.2 is the last tested version on macOS - arm64 - 14.5
assert WAKE_WORD_DETECTOR == "1.9.5" or Version(WAKE_WORD_DETECTOR) >= Version(
"3.0.2"
)
pvporcupine.LIBRARY_PATH = os.path.join(
base_path, "lib/mac/x86_64/libpv_porcupine.dylib"
except AssertionError:
raise DependencyError(
f"{settings.os} is only supported with porcupine versions 1.9.5 or 3.0.2 and above (requires key)"
)

# Iterates over the available flash files, to override the object reference
for x in os.listdir(os.path.join(base_path, "resources/keyword_files/mac/")):
pvporcupine.KEYWORD_PATHS[x.split("_")[0]] = os.path.join(
base_path, f"resources/keyword_files/mac/{x}"
)
else:
try:
# 3.0.2 is the last tested version on macOS - arm64 - 14.5
assert WAKE_WORD_DETECTOR == "1.9.5" or Version(
WAKE_WORD_DETECTOR
) >= Version("3.0.2")
except AssertionError:
raise DependencyError(
f"{settings.os} is only supported with porcupine versions 1.9.5 or 3.0.2 and above (requires key)"
)

for keyword in env.wake_words:
if not pvporcupine.KEYWORD_PATHS.get(keyword) or not os.path.isfile(
pvporcupine.KEYWORD_PATHS[keyword]
Expand Down Expand Up @@ -193,13 +170,6 @@ def _main_process_validations() -> None:
def _global_validations() -> None:
"""Validations that should happen for all processes including parent and child."""
main = True if settings.pname == "JARVIS" else False
if settings.legacy:
warnings.warn(
f"\nmacOS {platform.mac_ver()[0]} will be deprecated in the near future\n"
f"Please upgrade to 10.14 or above to continue using Jarvis",
DeprecationWarning,
)

if voice_names := [__voice.name for __voice in voices]:
if not env.voice_name:
_set_default_voice_name()
Expand Down Expand Up @@ -325,10 +295,18 @@ def _global_validations() -> None:


_global_validations()

# Required at top level to let other modules access it
if env.temperature_unit == TemperatureUnits.IMPERIAL:
temperature_symbol = "F"
elif env.temperature_unit == TemperatureUnits.METRIC:
temperature_symbol = "C"
if settings.pname in ("JARVIS", "pre_commit"):

if settings.pname in (
"JARVIS",
"pre_commit",
"startup_script",
"plot_mic",
"crontab_executor",
):
_main_process_validations()

0 comments on commit 899e21b

Please sign in to comment.