Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulse install & ensure fixes #28

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 35 additions & 31 deletions pulse/core/git/git_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,41 +127,45 @@ def download_requirements(requirements: list, dependency: bool = False) -> None:

dependency_package = os.path.join(PACKAGE_PATH, f"{req[0]}/{req[1]}")
install_path = dependency_package if dependency else REQUIREMENTS_PATH
if not os.path.exists(install_path):
os.makedirs(install_path)
try:
response = requests.get(
f"https://api.github.com/repos/{req[0]}/{req[1]}/{'zipball' if system() == 'Windows' else 'tarball'}/{branch}",
stream=True,
)

except Exception as e:
print(f"An unexpected error occurred: {e}")

if system() == "Windows":
with ZipFile(BytesIO(response.content)) as z:
z.extractall(install_path)

if system() == "Linux":
with tarfile.open(BytesIO(response.content), "r:gz") as tar_ref:
tar_ref.extractall(install_path)

renamed_dir = os.path.join(install_path, branch if dependency else req[1])
print(
f"Installed {'dependency' if dependency else 'requirement'}: {os.listdir(install_path)[0]} in {install_path}"
)
os.rename(
os.path.join(install_path, os.listdir(install_path)[0]),
renamed_dir,
try:
response = requests.get(
f"https://api.github.com/repos/{req[0]}/{req[1]}/{'zipball' if system() == 'Windows' else 'tarball'}/{branch}",
stream=True,
)
renamed_dir = copy_if_plugin(req[0], req[1], renamed_dir, requirement=True)
libs = git_get.get_requirements(renamed_dir)
if libs:
print("Found requirements!\nInstalling..")
download_requirements(libs)

except Exception as e:
print(f"An unexpected error occurred: {e}")

if dependency:
renamed_dir = os.path.join(install_path, branch)
else:
renamed_dir = os.path.join(install_path, req[1])

if os.path.exists(renamed_dir):
print(f"Found installed package: {req[0]}/{req[1]}..")
continue

os.makedirs(install_path, exist_ok=True)
if system() == "Windows":
with ZipFile(BytesIO(response.content)) as z:
z.extractall(install_path)

if system() == "Linux":
with tarfile.open(BytesIO(response.content), "r:gz") as tar_ref:
tar_ref.extractall(install_path)

print(
f"Installed {'dependency' if dependency else 'requirement'}: {os.listdir(install_path)[0]} in {install_path}"
)
os.rename(
os.path.join(install_path, os.listdir(install_path)[0]),
renamed_dir,
)
renamed_dir = copy_if_plugin(req[0], req[1], renamed_dir, requirement=True)
libs = git_get.get_requirements(renamed_dir)
if libs:
print("Found requirements!\nInstalling..")
download_requirements(libs)


def copy_if_plugin(owner: str, repo: str, directory, requirement: bool = False):
Expand Down
17 changes: 7 additions & 10 deletions pulse/ensure/ensure.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,18 @@ def ensure() -> None:
tmp_dir = os.path.join(REQUIREMENTS_PATH, f"{re_package[1]}")
if not os.path.exists(tmp_dir):
os.makedirs(tmp_dir)
is_plugin: bool = False
for file in os.listdir(package_path):
shutil.copy2(os.path.join(package_path, file), tmp_dir)

plugins_path = os.path.join(
PLUGINS_PATH, f"{re_package[0]}/{re_package[1]}"
)
for file in os.listdir(plugins_path):
if file.endswith(
f"{'.dll' if platform.system() == 'Windows' else '.so'}"
):
if file.endswith((".dll", ".so")):
click.echo(f"Found plugin: {file}!")
shutil.copy2(os.path.join(plugins_path, file), tmp_dir)
is_plugin = True
break

if not is_plugin:
shutil.copy2(os.path.join(package_path, file), tmp_dir)
tmp_plugins_path = os.path.join(REQUIREMENTS_PATH, "plugins")
os.makedirs(tmp_plugins_path)
shutil.copy2(os.path.join(plugins_path, file), tmp_plugins_path)

else:
click.echo("The requirement already exists..")
Expand Down