From e78072b7cde0ebe30f0c6e03d4420b21cbfb295c Mon Sep 17 00:00:00 2001 From: Ykpauneu Date: Wed, 27 Mar 2024 13:40:07 +0300 Subject: [PATCH 1/2] Fixed a bug during package downloading (requirements fix) --- pulse/core/git/git_download.py | 66 ++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/pulse/core/git/git_download.py b/pulse/core/git/git_download.py index 16c9f15..6526b57 100644 --- a/pulse/core/git/git_download.py +++ b/pulse/core/git/git_download.py @@ -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): From eba94a1573ebab31db9639d500a90cde2904ba96 Mon Sep 17 00:00:00 2001 From: Ykpauneu Date: Wed, 27 Mar 2024 21:03:41 +0300 Subject: [PATCH 2/2] Fixed pulse ensure --- pulse/ensure/ensure.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pulse/ensure/ensure.py b/pulse/ensure/ensure.py index 3961610..f711d22 100644 --- a/pulse/ensure/ensure.py +++ b/pulse/ensure/ensure.py @@ -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..")