Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Replit user committed Dec 7, 2023
1 parent d6e38f1 commit e2ad6ea
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 79 deletions.
6 changes: 6 additions & 0 deletions install_poetry_in_venv.sh
Original file line number Diff line number Diff line change
@@ -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
97 changes: 53 additions & 44 deletions src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import subprocess
import contextlib
import csv
import itertools
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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" <fg=blue;options=bold>•</> {operation_message}: <info>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 + " <b>%percent%%</b>")

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" <fg=blue;options=bold>•</> {operation_message}: <info>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 + " <b>%percent%%</b>")

# 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
Expand Down
7 changes: 5 additions & 2 deletions src/poetry/installation/wheel_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 22 additions & 5 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -206,7 +220,6 @@ def _version_nodot(version):
print(json.dumps(paths))
"""


class SitePackages:
def __init__(
self,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
64 changes: 36 additions & 28 deletions src/poetry/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import subprocess
import hashlib
import io
import os
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e2ad6ea

Please sign in to comment.