From e2ad6ea9ec780d183f82dd020bd3bf78e0db2ca1 Mon Sep 17 00:00:00 2001 From: Replit user <> Date: Thu, 7 Dec 2023 16:21:31 +0000 Subject: [PATCH] wip --- install_poetry_in_venv.sh | 6 ++ src/poetry/installation/executor.py | 97 ++++++++++++---------- src/poetry/installation/wheel_installer.py | 7 +- src/poetry/utils/env.py | 27 ++++-- src/poetry/utils/helpers.py | 64 +++++++------- 5 files changed, 122 insertions(+), 79 deletions(-) create mode 100755 install_poetry_in_venv.sh diff --git a/install_poetry_in_venv.sh b/install_poetry_in_venv.sh new file mode 100755 index 00000000000..e9851408742 --- /dev/null +++ b/install_poetry_in_venv.sh @@ -0,0 +1,6 @@ +rm -fr poetry_env +poetry build +python -m venv poetry_env +touch poetry_env/poetry_env +poetry_env/bin/pip install dist/poetry-1.5.2-py3-none-any.whl +# need to edit poetry_env/bin/poetry shebang line \ No newline at end of file diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index 3b6b14f6c57..96bd1b8731a 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -1,5 +1,6 @@ from __future__ import annotations +import subprocess import contextlib import csv import itertools @@ -608,7 +609,7 @@ def _traditional_install(self, operation: Install | Update) -> int: ) self._write(operation, message) return self.pip_install(req, upgrade=operation.job_type == "update") - + def _update(self, operation: Install | Update) -> int: return self._install(operation) @@ -783,7 +784,7 @@ def _maybe_add_yanked_warning(self, link: Link, operation: Install | Update) -> if link.yanked_reason: message += f" Reason for being yanked: {link.yanked_reason}" self._yanked_warnings.append(message) - + def _download(self, operation: Install | Update) -> Path: link = self._chooser.choose_for(operation.package) self._maybe_add_yanked_warning(link, operation) @@ -863,55 +864,63 @@ def _validate_archive_hash(archive: Path, package: Package) -> str: return archive_hash def _download_archive(self, operation: Install | Update, link: Link) -> Path: - response = self._authenticator.request( - "get", link.url, stream=True, io=self._sections.get(id(operation), self._io) - ) - wheel_size = response.headers.get("content-length") - operation_message = self.get_operation_message(operation) - message = ( - f" • {operation_message}: Downloading..." - ) - progress = None - if self.supports_fancy_output(): - if wheel_size is None: - self._write(operation, message) - else: - from cleo.ui.progress_bar import ProgressBar - - progress = ProgressBar( - self._sections[id(operation)], max=int(wheel_size) - ) - progress.set_format(message + " %percent%%") - - if progress: - with self._lock: - self._sections[id(operation)].clear() - progress.start() - - done = 0 archive = ( self._artifact_cache.get_cache_directory_for_link(link) / link.filename ) archive.parent.mkdir(parents=True, exist_ok=True) - with atomic_open(archive) as f: - for chunk in response.iter_content(chunk_size=4096): - if not chunk: - break - - done += len(chunk) - - if progress: - with self._lock: - progress.set_progress(done) - - f.write(chunk) - - if progress: - with self._lock: - progress.finish() + curlcmd = 'curl %s --silent --output %s; exit 0' % (str(link), str(archive)) + output = subprocess.check_output( + curlcmd, + stderr=subprocess.STDOUT, + shell=True, + ) return archive + # response = self._authenticator.request( + # "get", link.url, stream=True, io=self._sections.get(id(operation), self._io) + # ) + # wheel_size = response.headers.get("content-length") + # operation_message = self.get_operation_message(operation) + # message = ( + # f" • {operation_message}: Downloading..." + # ) + # progress = None + # if self.supports_fancy_output(): + # if wheel_size is None: + # self._write(operation, message) + # else: + # from cleo.ui.progress_bar import ProgressBar + + # progress = ProgressBar( + # self._sections[id(operation)], max=int(wheel_size) + # ) + # progress.set_format(message + " %percent%%") + + # if progress: + # with self._lock: + # self._sections[id(operation)].clear() + # progress.start() + + # done = 0 + # with atomic_open(archive) as f: + # for chunk in response.iter_content(chunk_size=4096): + # if not chunk: + # break + + # done += len(chunk) + + # if progress: + # with self._lock: + # progress.set_progress(done) + # f.write(chunk) + + # if progress: + # with self._lock: + # progress.finish() + + # return archive + def _should_write_operation(self, operation: Operation) -> bool: return ( not operation.skipped or self._dry_run or self._verbose or not self._enabled diff --git a/src/poetry/installation/wheel_installer.py b/src/poetry/installation/wheel_installer.py index 9e2d0ce87f8..2d06c4e0c5a 100644 --- a/src/poetry/installation/wheel_installer.py +++ b/src/poetry/installation/wheel_installer.py @@ -40,8 +40,11 @@ def write_to_fs( from installer.utils import copyfileobj_with_hashing from installer.utils import make_file_executable - if scheme in ["platlib", "purelib"] and "usersite" in self.scheme_dict: - scheme = "usersite" + if os.getenv("POETRY_USE_USER_SITE") == "1": + if scheme in ["platlib", "purelib"] and "usersite" in self.scheme_dict: + scheme = "usersite" + if scheme == "data" and "userbase" in self.scheme_dict: + scheme = "userbase" target_path = Path(self.scheme_dict[scheme]) / path if target_path.exists(): # Contrary to the base library we don't raise an error diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 9d204d1a9d6..ea0f25fcd6e 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -195,6 +195,20 @@ def _version_nodot(version): paths = sysconfig.get_paths().copy() +if site.check_enableusersite(): + paths["usersite"] = site.getusersitepackages() + paths["userbase"] = site.getuserbase() + +print(json.dumps(paths)) +""" + +GET_PATHS_FOR_GENERIC_ENVS_USE_USERSITE = """\ +import json +import site +import sysconfig + +paths = sysconfig.get_paths().copy() + if site.check_enableusersite(): paths["usersite"] = site.getusersitepackages() paths["userbase"] = site.getuserbase() @@ -206,7 +220,6 @@ def _version_nodot(version): print(json.dumps(paths)) """ - class SitePackages: def __init__( self, @@ -1619,9 +1632,10 @@ def get_paths(self) -> dict[str, str]: paths["usersite"] = site.getusersitepackages() paths["userbase"] = site.getuserbase() - paths["platlib"] = paths["usersite"] - paths["purelib"] = paths["usersite"] - paths["scripts"] = paths["userbase"] + "/bin" + if os.getenv("POETRY_USE_USER_SITE") == "1": + paths["platlib"] = paths["usersite"] + paths["purelib"] = paths["usersite"] + paths["scripts"] = paths["userbase"] + "/bin" return paths @@ -1836,7 +1850,10 @@ def find_executables(self) -> None: self._pip_executable = pip_executable def get_paths(self) -> dict[str, str]: - output = self.run_python_script(GET_PATHS_FOR_GENERIC_ENVS, isolate=False) + if os.getenv("POETRY_USE_USER_SITE") == "1": + output = self.run_python_script(GET_PATHS_FOR_GENERIC_ENVS_USE_USERSITE, isolate=False) + else: + output = self.run_python_script(GET_PATHS_FOR_GENERIC_ENVS, isolate=False) paths: dict[str, str] = json.loads(output) return paths diff --git a/src/poetry/utils/helpers.py b/src/poetry/utils/helpers.py index ab2f369aa6e..97248831295 100644 --- a/src/poetry/utils/helpers.py +++ b/src/poetry/utils/helpers.py @@ -1,5 +1,6 @@ from __future__ import annotations +import subprocess import hashlib import io import os @@ -95,43 +96,50 @@ def download_file( session: Authenticator | Session | None = None, chunk_size: int = 1024, ) -> None: - import requests + curlcmd = 'curl %s --silent --output %s; exit 0' % (url, str(dest)) + # logger.warn('TOBY: curlcmd: %s' % curlcmd) + output = subprocess.check_output( + curlcmd, + stderr=subprocess.STDOUT, + shell=True, + ) + # import requests - from poetry.puzzle.provider import Indicator + # from poetry.puzzle.provider import Indicator - get = requests.get if not session else session.get + # get = requests.get if not session else session.get - response = get(url, stream=True, timeout=REQUESTS_TIMEOUT) - response.raise_for_status() + # response = get(url, stream=True, timeout=REQUESTS_TIMEOUT) + # response.raise_for_status() - set_indicator = False - with Indicator.context() as update_context: - update_context(f"Downloading {url}") + # set_indicator = False + # with Indicator.context() as update_context: + # update_context(f"Downloading {url}") - if "Content-Length" in response.headers: - try: - total_size = int(response.headers["Content-Length"]) - except ValueError: - total_size = 0 + # if "Content-Length" in response.headers: + # try: + # total_size = int(response.headers["Content-Length"]) + # except ValueError: + # total_size = 0 - fetched_size = 0 - last_percent = 0 + # fetched_size = 0 + # last_percent = 0 - # if less than 1MB, we simply show that we're downloading - # but skip the updating - set_indicator = total_size > 1024 * 1024 + # # if less than 1MB, we simply show that we're downloading + # # but skip the updating + # set_indicator = total_size > 1024 * 1024 - with atomic_open(dest) as f: - for chunk in response.iter_content(chunk_size=chunk_size): - if chunk: - f.write(chunk) + # with atomic_open(dest) as f: + # for chunk in response.iter_content(chunk_size=chunk_size): + # if chunk: + # f.write(chunk) - if set_indicator: - fetched_size += len(chunk) - percent = (fetched_size * 100) // total_size - if percent > last_percent: - last_percent = percent - update_context(f"Downloading {url} {percent:3}%") + # if set_indicator: + # fetched_size += len(chunk) + # percent = (fetched_size * 100) // total_size + # if percent > last_percent: + # last_percent = percent + # update_context(f"Downloading {url} {percent:3}%") def get_package_version_display_string(