Skip to content

Commit

Permalink
Merge branch 'master' into skip-path-dep-install
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering authored Apr 10, 2023
2 parents c940cbf + d2e6ad6 commit f41c035
Show file tree
Hide file tree
Showing 26 changed files with 798 additions and 260 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Change Log


## [1.4.2] - 2023-04-02

### Changed

- When trying to install wheels with invalid `RECORD` files, Poetry does not fail anymore but only prints a warning.
This mitigates an unintended change introduced in Poetry 1.4.1 ([#7694](https://github.com/python-poetry/poetry/pull/7694)).

### Fixed

- Fix an issue where relative git submodule urls were not parsed correctly ([#7017](https://github.com/python-poetry/poetry/pull/7017)).
- Fix an issue where Poetry could freeze when building a project with a build script if it generated enough output to fill the OS pipe buffer ([#7699](https://github.com/python-poetry/poetry/pull/7699)).


## [1.4.1] - 2023-03-19

### Fixed
Expand Down Expand Up @@ -1786,7 +1799,8 @@ Initial release



[Unreleased]: https://github.com/python-poetry/poetry/compare/1.4.1...master
[Unreleased]: https://github.com/python-poetry/poetry/compare/1.4.2...master
[1.4.2]: https://github.com/python-poetry/poetry/releases/tag/1.4.2
[1.4.1]: https://github.com/python-poetry/poetry/releases/tag/1.4.1
[1.4.0]: https://github.com/python-poetry/poetry/releases/tag/1.4.0
[1.3.2]: https://github.com/python-poetry/poetry/releases/tag/1.3.2
Expand Down
9 changes: 5 additions & 4 deletions src/poetry/installation/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from poetry.core.utils.helpers import temporary_directory
from pyproject_hooks import quiet_subprocess_runner # type: ignore[import]

from poetry.utils._compat import decode
from poetry.utils.env import ephemeral_environment


Expand Down Expand Up @@ -94,8 +95,8 @@ def prepare(
return archive

if archive.is_dir():
tmp_dir = tempfile.mkdtemp(prefix="poetry-chef-")
return self._prepare(archive, Path(tmp_dir), editable=editable)
destination = output_dir or Path(tempfile.mkdtemp(prefix="poetry-chef-"))
return self._prepare(archive, destination=destination, editable=editable)

return self._prepare_sdist(archive, destination=output_dir)

Expand Down Expand Up @@ -135,9 +136,9 @@ def _prepare(
e.exception.stdout is not None or e.exception.stderr is not None
):
message_parts.append(
e.exception.stderr.decode()
decode(e.exception.stderr)
if e.exception.stderr is not None
else e.exception.stdout.decode()
else decode(e.exception.stdout)
)

error = ChefBuildError("\n\n".join(message_parts))
Expand Down
48 changes: 39 additions & 9 deletions src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def _install(self, operation: Install | Update) -> int:
cleanup_archive: bool = False
if package.source_type == "git":
archive = self._prepare_git_archive(operation)
cleanup_archive = True
cleanup_archive = operation.package.develop
elif package.source_type == "file":
archive = self._prepare_archive(operation)
elif package.source_type == "directory":
Expand Down Expand Up @@ -584,7 +584,9 @@ def _remove(self, package: Package) -> int:

raise

def _prepare_archive(self, operation: Install | Update) -> Path:
def _prepare_archive(
self, operation: Install | Update, *, output_dir: Path | None = None
) -> Path:
package = operation.package
operation_message = self.get_operation_message(operation)

Expand All @@ -603,20 +605,35 @@ def _prepare_archive(self, operation: Install | Update) -> Path:

self._populate_hashes_dict(archive, package)

return self._chef.prepare(archive, editable=package.develop)
return self._chef.prepare(
archive, editable=package.develop, output_dir=output_dir
)

def _prepare_git_archive(self, operation: Install | Update) -> Path:
from poetry.vcs.git import Git

package = operation.package
assert package.source_url is not None

if package.source_resolved_reference and not package.develop:
# Only cache git archives when we know precise reference hash,
# otherwise we might get stale archives
cached_archive = self._artifact_cache.get_cached_archive_for_git(
package.source_url,
package.source_resolved_reference,
package.source_subdirectory,
env=self._env,
)
if cached_archive is not None:
return cached_archive

operation_message = self.get_operation_message(operation)

message = (
f" <fg=blue;options=bold>•</> {operation_message}: <info>Cloning...</info>"
)
self._write(operation, message)

assert package.source_url is not None
source = Git.clone(
url=package.source_url,
source_root=self._env.path / "src",
Expand All @@ -627,9 +644,22 @@ def _prepare_git_archive(self, operation: Install | Update) -> Path:
original_url = package.source_url
package._source_url = str(source.path)

archive = self._prepare_archive(operation)
output_dir = None
if package.source_resolved_reference and not package.develop:
output_dir = self._artifact_cache.get_cache_directory_for_git(
original_url,
package.source_resolved_reference,
package.source_subdirectory,
)

archive = self._prepare_archive(operation, output_dir=output_dir)
if not package.develop:
package._source_url = original_url

package._source_url = original_url
if output_dir is not None and output_dir.is_dir():
# Mark directories with cached git packages, to distinguish from
# "normal" cache
(output_dir / ".created_from_git_dependency").touch()

return archive

Expand Down Expand Up @@ -864,12 +894,12 @@ def _save_url_reference(self, operation: Operation) -> None:

url_reference: dict[str, Any] | None = None

if package.source_type == "git":
if package.source_type == "git" and not package.develop:
url_reference = self._create_git_url_reference(package)
elif package.source_type in ("directory", "git"):
url_reference = self._create_directory_url_reference(package)
elif package.source_type == "url":
url_reference = self._create_url_url_reference(package)
elif package.source_type == "directory":
url_reference = self._create_directory_url_reference(package)
elif package.source_type == "file":
url_reference = self._create_file_url_reference(package)

Expand Down
16 changes: 10 additions & 6 deletions src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,10 @@ def _do_install(self) -> int:
lockfile_repo = LockfileRepository()
self._populate_lockfile_repo(lockfile_repo, ops)

if self._update:
if self._lock and self._update:
# If we are only in lock mode, no need to go any further
self._write_lock_file(lockfile_repo)

if self._lock:
# If we are only in lock mode, no need to go any further
return 0
return 0

if self._groups is not None:
root = self._package.with_dependency_groups(list(self._groups), only=True)
Expand Down Expand Up @@ -369,7 +367,13 @@ def _do_install(self) -> int:
self._filter_operations(ops, lockfile_repo)

# Execute operations
return self._execute(ops)
status = self._execute(ops)

if status == 0 and self._update:
# Only write lock file when installation is success
self._write_lock_file(lockfile_repo)

return status

def _write_lock_file(self, repo: LockfileRepository, force: bool = False) -> None:
if self._write_lock and (force or self._update):
Expand Down
4 changes: 3 additions & 1 deletion src/poetry/mixology/version_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ def _resolve_conflict(self, incompatibility: Incompatibility) -> Incompatibility
# .. _algorithm documentation:
# https://github.com/dart-lang/pub/tree/master/doc/solver.md#conflict-resolution # noqa: E501
if difference is not None:
new_terms.append(difference.inverse)
inverse = difference.inverse
if inverse.dependency != most_recent_satisfier.dependency:
new_terms.append(inverse)

incompatibility = Incompatibility(
new_terms, ConflictCause(incompatibility, most_recent_satisfier.cause)
Expand Down
18 changes: 16 additions & 2 deletions src/poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ def locked_repository(self) -> LockfileRepository:
return repository

def set_lock_data(self, root: Package, packages: list[Package]) -> bool:
"""Store lock data and eventually persist to the lock file"""
lock = self._compute_lock_data(root, packages)

if self._should_write(lock):
self._write_lock_data(lock)
return True

return False

def _compute_lock_data(
self, root: Package, packages: list[Package]
) -> TOMLDocument:
package_specs = self._lock_packages(packages)
# Retrieving hashes
for package in package_specs:
Expand Down Expand Up @@ -254,6 +266,10 @@ def set_lock_data(self, root: Package, packages: list[Package]) -> bool:
"content-hash": self._content_hash,
}

return lock

def _should_write(self, lock: TOMLDocument) -> bool:
# if lock file exists: compare with existing lock data
do_write = True
if self.is_locked():
try:
Expand All @@ -263,8 +279,6 @@ def set_lock_data(self, root: Package, packages: list[Package]) -> bool:
pass
else:
do_write = lock != lock_data
if do_write:
self._write_lock_data(lock)
return do_write

def _write_lock_data(self, data: TOMLDocument) -> None:
Expand Down
7 changes: 4 additions & 3 deletions src/poetry/repositories/installed_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,8 @@ def load(cls, env: Env, with_dependencies: bool = False) -> InstalledRepository:
if path in skipped:
continue

try:
name = canonicalize_name(distribution.metadata["name"])
except TypeError:
name = distribution.metadata.get("name") # type: ignore[attr-defined]
if name is None:
logger.warning(
(
"Project environment contains an invalid distribution"
Expand All @@ -271,6 +270,8 @@ def load(cls, env: Env, with_dependencies: bool = False) -> InstalledRepository:
skipped.add(path)
continue

name = canonicalize_name(name)

if name in seen:
continue

Expand Down
Loading

0 comments on commit f41c035

Please sign in to comment.