Skip to content

Commit 82bd1eb

Browse files
authored
feat: find out the installed mosec path (#624)
Signed-off-by: Keming <[email protected]>
1 parent b0a3685 commit 82bd1eb

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

.github/workflows/check.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ jobs:
5757
runs-on: ${{ matrix.os }}
5858
timeout-minutes: 20
5959
strategy:
60-
max-parallel: 18
6160
matrix:
6261
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
6362
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-13, macos-14]

mosec/runtime.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from mosec.coordinator import Coordinator
2727
from mosec.env import env_var_context, validate_env, validate_int_ge
2828
from mosec.log import get_internal_logger
29+
from mosec.utils import get_mosec_path
2930
from mosec.worker import Worker
3031

3132
logger = get_internal_logger()
@@ -270,5 +271,5 @@ def start(self, config_path: Path) -> subprocess.Popen:
270271
271272
"""
272273
# pylint: disable=consider-using-with
273-
self.process = subprocess.Popen([str("mosec"), config_path])
274+
self.process = subprocess.Popen([str(get_mosec_path()), config_path])
274275
return self.process

mosec/utils/types.py renamed to mosec/utils.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 MOSEC Authors
1+
# Copyright 2025 MOSEC Authors
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -15,9 +15,43 @@
1515
"""Provide useful utils to inspect function type."""
1616

1717
import inspect
18+
import os
1819
import sys
20+
import sysconfig
1921
from enum import Enum
20-
from typing import Any, List
22+
from pathlib import Path
23+
from typing import Any, List, Optional
24+
25+
26+
# adopted from https://github.com/PyO3/maturin/blob/main/maturin/__main__.py
27+
# License: Apache-2.0 or MIT
28+
def get_mosec_path() -> Optional[Path]:
29+
"""Get `mosec` binary path."""
30+
SCRIPT_NAME = "mosec"
31+
32+
def script_dir(scheme: str) -> str:
33+
return sysconfig.get_path("scripts", scheme)
34+
35+
def script_exists(dir: str) -> bool:
36+
for _, _, files in os.walk(dir):
37+
for f in files:
38+
name, *_ = os.path.splitext(f)
39+
if name == SCRIPT_NAME:
40+
return True
41+
42+
return False
43+
44+
paths = list(
45+
filter(
46+
script_exists,
47+
filter(os.path.exists, map(script_dir, sysconfig.get_scheme_names())),
48+
)
49+
)
50+
51+
if paths:
52+
return Path(paths[0]) / SCRIPT_NAME
53+
54+
return None
2155

2256

2357
def get_annotations(func) -> dict:

mosec/utils/__init__.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)