Skip to content

Commit

Permalink
fix: handle deps in grapycal ext install
Browse files Browse the repository at this point in the history
  • Loading branch information
eri24816 committed Jun 23, 2024
1 parent a899e9f commit f9f0a57
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
52 changes: 46 additions & 6 deletions backend/src/grapycal/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
import pathlib
import subprocess
import threading
import time
from typing import Callable
Expand Down Expand Up @@ -203,7 +204,8 @@ def license_file_valid():
def acquire_license():
import requests

serial = input_colored("Please enter your serial number: ")
# serial = input_colored("Please enter your serial number: ")
serial = "2501dc76b11a43e3b2421803f4f1f660" # demo serial number. no need to input

def get_ip_addresses(family):
for interface, snics in psutil.net_if_addrs().items():
Expand All @@ -226,15 +228,18 @@ def get_ip_addresses(family):

if response.status_code == 200:
response = response.json()
print(
"License acquired successfully. Remaining uses: ",
response["remaining_uses"],
)

# Not need to print remaining uses for demo license
# print(
# "License acquired successfully. Remaining uses: ",
# response["remaining_uses"],
# )

with open(GRAPYCAL_ROOT / "license.json", "w") as f:
json.dump(response["license"], f)
elif response.status_code == 403:
print(
"Invalid serial number. Maybe it has been used too many times, or it's invalid."
"Invalid serial number. Maybe it has been used too many times, or it's invalid. If you believe this is an error, please contact us at [email protected]"
)
sys.exit(1)
else: # error
Expand Down Expand Up @@ -349,10 +354,45 @@ def ext(cmds: CmdSelector):
def install_ext():
if not cmds.has_next():
print("Please specify the extension name.")
available_exts = os.listdir(GRAPYCAL_ROOT / "extensions")
print("Available extensions:")
for ext in available_exts:
if ext.startswith("grapycal_"):
print(f" {ext[9:]}")
return
ext_name = cmds.next()
if not ext_name.startswith("grapycal_"):
ext_name = "grapycal_" + ext_name
ext_name = ext_name.replace("-", "_")
# check its dependency extensions are installed
# read the extension's pyproject.toml
ext_path = GRAPYCAL_ROOT / "extensions" / ext_name
if not ext_path.exists():
print(f"Extension {ext_name} not found.")
return
if (ext_path / "pyproject.toml").exists():
with open(ext_path / "pyproject.toml") as f:
lines = f.readlines()
for line in lines:
if line.startswith("grapycal-"):
dep = line.split("=")[0].strip()
if (
subprocess.run(
f"pip show {dep}",
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).returncode
!= 0
):
short_dep = dep[9:]
print(
f"Befor installing {ext_name}, please install {dep.replace('-','_')} first: `{termcolor.colored(f'grapycal ext install {short_dep}', 'green')}`"
)
return
else:
print(f"Dependency {dep} installed.")

print(f"Installing extension {ext_name}...")
pip_install_from_path(GRAPYCAL_ROOT / "extensions" / ext_name)
print(f"Extension {ext_name} installed.")
Expand Down
14 changes: 14 additions & 0 deletions packaging/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,20 @@ def run(self, src: Path, dst: Path):
pyarmor_config=self.pyarmor_config.copyWith(prefix="grapycal"),
)
* ToRelative("extensions/grapycal_torch")
+ From(src / "extensions/grapycal_audio")
* PackPythonPackage(
edition=self.edition,
package_src_dir="grapycal_audio",
pyarmor_config=self.pyarmor_config.copyWith(prefix="grapycal"),
)
* ToRelative("extensions/grapycal_audio")
+ From(src / "extensions/grapycal_audio_torch")
* PackPythonPackage(
edition=self.edition,
package_src_dir="grapycal_audio_torch",
pyarmor_config=self.pyarmor_config.copyWith(prefix="grapycal"),
)
* ToRelative("extensions/grapycal_audio_torch")
+ From(src / "frontend") * PackFrontend() * ToRelative("frontend")
+ From(src / "packaging/template")
) * To(dst)
Expand Down

0 comments on commit f9f0a57

Please sign in to comment.