Skip to content

Commit

Permalink
Merge branch 'master' into fix-install-directory-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb authored May 18, 2023
2 parents d654f17 + 0af3f1e commit 93fd76b
Show file tree
Hide file tree
Showing 41 changed files with 836 additions and 782 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ repos:
- id: validate_manifest

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.265
rev: v0.0.267
hooks:
- id: ruff
18 changes: 14 additions & 4 deletions docs/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ but they may not all be at the very latest available versions
(some dependencies listed in the `poetry.lock` file may have released newer versions since the file was created).
This is by design, it ensures that your project does not break because of unexpected changes in dependencies.

### Commit your `poetry.lock` file to version control
### Committing your `poetry.lock` file to version control

#### As an application developer

Application developers commit `poetry.lock` to get more reproducible builds.

Committing this file to VC is important because it will cause anyone who sets up the project
to use the exact same versions of the dependencies that you are using.
Expand All @@ -230,9 +234,15 @@ Even if you develop alone, in six months when reinstalling the project you can f
the dependencies installed are still working even if your dependencies released many new versions since then.
(See note below about using the update command.)

{{% note %}}
For libraries it is not necessary to commit the lock file.
{{% /note %}}
#### As a library developer

Library developers have more to consider. Your users are application developers, and your library will run in a Python environment you don't control.

The application ignores your library's lock file. It can use whatever dependency version meets the constraints in your `pyproject.toml`. The application will probably use the latest compatible dependency version. If your library's `poetry.lock` falls behind some new dependency version that breaks things for your users, you're likely to be the last to find out about it.

A simple way to avoid such a scenario is to omit the `poetry.lock` file. However, by doing so, you sacrifice reproducibility and performance to a certain extent. Without a lockfile, it can be difficult to find the reason for failing tests, because in addition to obvious code changes an unnoticed library update might be the culprit. Further, Poetry will have to lock before installing a dependency if `poetry.lock` has been omitted. Depending on the number of dependencies, locking may take a significant amount of time.

If you do not want to give up the reproducibility and performance benefits, consider a regular refresh of `poetry.lock` to stay up-to-date and reduce the risk of sudden breakage for users.

### Installing dependencies only

Expand Down
1 change: 1 addition & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ about dependency groups.
* `--group (-G)`: The group to remove the dependency from.
* `--dev (-D)`: Removes a package from the development dependencies. (**Deprecated**, use `-G dev` instead)
* `--dry-run` : Outputs the operations but will not execute anything (implicitly enables --verbose).
* `--lock`: Do not perform operations (only update the lockfile).


## show
Expand Down
6 changes: 3 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ Use parallel execution when using the new (`>=1.1.0`) installer.

Create a new virtual environment if one doesn't already exist.

If set to `false`, Poetry will not create a new virtual environment. If it detects a virtual environment
in `{cache-dir}/virtualenvs` or `{project-dir}/.venv` it will install dependencies into them, otherwise it will install
dependencies into the systems python environment.
If set to `false`, Poetry will not create a new virtual environment. If it detects an already enabled virtual
environment or an existing one in `{cache-dir}/virtualenvs` or `{project-dir}/.venv` it will
install dependencies into them, otherwise it will install dependencies into the systems python environment.

{{% note %}}
If Poetry detects it's running within an activated virtual environment, it will never create a new virtual environment,
Expand Down
7 changes: 7 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,10 @@ RUN poetry install --no-dev

The two key options we are using here are `--no-root` (skips installing the project source) and `--no-directory` (skips installing any local directory path dependencies, you can omit this if you don't have any).
[More information on the options available for `poetry install`]({{< relref "cli#install" >}}).


### My requests are timing out!

Poetry's default HTTP request timeout is 15 seconds, the same as `pip`.
Similar to `PIP_REQUESTS_TIMEOUT`, the **experimental** environment variable `POETRY_REQUESTS_TIMEOUT`
can be set to alter this value.
995 changes: 497 additions & 498 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Changelog = "https://python-poetry.org/history/"
[tool.poetry.dependencies]
python = "^3.7"

poetry-core = "1.5.2"
poetry-core = "1.6.0"
poetry-plugin-export = "^1.3.1"
"backports.cached-property" = { version = "^1.0.2", python = "<3.8" }
build = "^0.10.0"
Expand All @@ -54,7 +54,7 @@ pkginfo = "^1.9.4"
platformdirs = "^3.0.0"
pyproject-hooks = "^1.0.0"
requests = "^2.18"
requests-toolbelt = ">=0.9.1,<0.11.0"
requests-toolbelt = ">=0.9.1,<2"
shellingham = "^1.5"
tomli = { version = "^2.0.1", python = "<3.11" }
tomlkit = ">=0.11.4,<1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/config/file_config_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def secure(self) -> Iterator[TOMLDocument]:
mode = 0o600

if new_file:
self.file.touch(mode=mode)
self.file.path.touch(mode=mode)

self.file.write(config)
except Exception:
Expand Down
9 changes: 3 additions & 6 deletions src/poetry/console/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,12 @@ def handle(self) -> int:
constraint_name,
constraint,
groups=[group],
root_dir=self.poetry.file.parent,
root_dir=self.poetry.file.path.parent,
)
)

# Refresh the locker
self.poetry.set_locker(
self.poetry.locker.__class__(self.poetry.locker.lock, poetry_content)
)
self.poetry.locker.set_local_config(poetry_content)
self.installer.set_locker(self.poetry.locker)

# Cosmetic new line
Expand All @@ -266,8 +264,7 @@ def handle(self) -> int:
self.installer.dry_run(self.option("dry-run"))
self.installer.verbose(self.io.is_verbose())
self.installer.update(True)
if self.option("lock"):
self.installer.lock()
self.installer.execute_operations(not self.option("lock"))

self.installer.whitelist([r["name"] for r in requirements])

Expand Down
4 changes: 2 additions & 2 deletions src/poetry/console/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def handle(self) -> int:
config_file = TOMLFile(CONFIG_DIR / "config.toml")

try:
local_config_file = TOMLFile(self.poetry.file.parent / "poetry.toml")
local_config_file = TOMLFile(self.poetry.file.path.parent / "poetry.toml")
if local_config_file.exists():
config.merge(local_config_file.read())
except (RuntimeError, PyProjectException):
Expand All @@ -106,7 +106,7 @@ def handle(self) -> int:

if not config_file.exists():
config_file.path.parent.mkdir(parents=True, exist_ok=True)
config_file.touch(mode=0o0600)
config_file.path.touch(mode=0o0600)

if self.option("list"):
self._list_configuration(config.all(), config.raw())
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def _parse_requirements(self, requirements: list[str]) -> list[dict[str, Any]]:
from poetry.core.pyproject.exceptions import PyProjectException

try:
cwd = self.poetry.file.parent
cwd = self.poetry.file.path.parent
artifact_cache = self.poetry.pool.artifact_cache
except (PyProjectException, RuntimeError):
cwd = Path.cwd()
Expand Down
7 changes: 3 additions & 4 deletions src/poetry/console/commands/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RemoveCommand(InstallerCommand):
"(implicitly enables --verbose)."
),
),
option("lock", None, "Do not perform operations (only update the lockfile)."),
]

help = """The <info>remove</info> command removes a package from the current
Expand Down Expand Up @@ -108,15 +109,13 @@ def handle(self) -> int:
)

# Refresh the locker
self.poetry.set_locker(
self.poetry.locker.__class__(self.poetry.locker.lock, poetry_content)
)
self.poetry.locker.set_local_config(poetry_content)
self.installer.set_locker(self.poetry.locker)

self.installer.set_package(self.poetry.package)
self.installer.dry_run(self.option("dry-run", False))
self.installer.verbose(self.io.is_verbose())
self.installer.update(True)
self.installer.execute_operations(not self.option("lock"))
self.installer.whitelist(removed_set)

status = self.installer.run()
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _module(self) -> Module:

poetry = self.poetry
package = poetry.package
path = poetry.file.parent
path = poetry.file.path.parent
module = Module(package.name, path.as_posix(), package.packages)

return module
Expand Down
10 changes: 5 additions & 5 deletions src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,15 @@ def _display_packages_information(
version_length,
len(
get_package_version_display_string(
locked, root=self.poetry.file.parent
locked, root=self.poetry.file.path.parent
)
),
)
latest_length = max(
latest_length,
len(
get_package_version_display_string(
latest, root=self.poetry.file.parent
latest, root=self.poetry.file.path.parent
)
),
)
Expand All @@ -292,7 +292,7 @@ def _display_packages_information(
version_length,
len(
get_package_version_display_string(
locked, root=self.poetry.file.parent
locked, root=self.poetry.file.path.parent
)
),
)
Expand Down Expand Up @@ -353,7 +353,7 @@ def _display_packages_information(
)
if write_version:
version = get_package_version_display_string(
locked, root=self.poetry.file.parent
locked, root=self.poetry.file.path.parent
)
line += f" <b>{version:{version_length}}</b>"
if show_latest:
Expand All @@ -368,7 +368,7 @@ def _display_packages_information(
color = "yellow"

version = get_package_version_display_string(
latest, root=self.poetry.file.parent
latest, root=self.poetry.file.path.parent
)
line += f" <fg={color}>{version:{latest_length}}</>"

Expand Down
7 changes: 1 addition & 6 deletions src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ def create_poetry(

base_poetry = super().create_poetry(cwd=cwd, with_groups=with_groups)

# TODO: backward compatibility, can be simplified if poetry-core with
# https://github.com/python-poetry/poetry-core/pull/483 is available
poetry_file: Path = (
getattr(base_poetry, "pyproject_path", None) or base_poetry.file.path
)

poetry_file = base_poetry.pyproject_path
locker = Locker(poetry_file.parent / "poetry.lock", base_poetry.local_config)

# Loading global configuration
Expand Down
7 changes: 2 additions & 5 deletions src/poetry/layouts/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,10 @@ def get_package_include(self) -> InlineTable | None:
return None

include = parts[0]
package.append("include", include) # type: ignore[no-untyped-call]
package.append("include", include)

if self.basedir != Path():
package.append( # type: ignore[no-untyped-call]
"from",
self.basedir.as_posix(),
)
package.append("from", self.basedir.as_posix())
else:
if include == self._project:
# package include and package name are the same,
Expand Down
10 changes: 5 additions & 5 deletions src/poetry/masonry/builders/editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _setup_build(self) -> None:
pip_install(self._path, self._env, upgrade=True, editable=True)
else:
# Temporarily rename pyproject.toml
renamed_pyproject = self._poetry.file.with_suffix(".tmp")
renamed_pyproject = self._poetry.file.path.with_suffix(".tmp")
self._poetry.file.path.rename(renamed_pyproject)
try:
pip_install(self._path, self._env, upgrade=True, editable=True)
Expand All @@ -130,7 +130,7 @@ def _add_pth(self) -> list[Path]:
for file in self._env.site_packages.find(path=pth_file, writable_only=True):
self._debug(
f" - Removing existing <c2>{file.name}</c2> from <b>{file.parent}</b>"
f" for {self._poetry.file.parent}"
f" for {self._poetry.file.path.parent}"
)
# We can't use unlink(missing_ok=True) because it's not always available
if file.exists():
Expand All @@ -142,14 +142,14 @@ def _add_pth(self) -> list[Path]:
)
self._debug(
f" - Adding <c2>{pth_file.name}</c2> to <b>{pth_file.parent}</b> for"
f" {self._poetry.file.parent}"
f" {self._poetry.file.path.parent}"
)
return [pth_file]
except OSError:
# TODO: Replace with PermissionError
self._io.write_error_line(
f" - Failed to create <c2>{pth_file.name}</c2> for"
f" {self._poetry.file.parent}"
f" {self._poetry.file.path.parent}"
)
return []

Expand All @@ -163,7 +163,7 @@ def _add_scripts(self) -> list[Path]:
else:
self._io.write_error_line(
" - Failed to find a suitable script installation directory for"
f" {self._poetry.file.parent}"
f" {self._poetry.file.path.parent}"
)
return []

Expand Down
4 changes: 4 additions & 0 deletions src/poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def is_fresh(self) -> bool:

return False

def set_local_config(self, local_config: dict[str, Any]) -> None:
self._local_config = local_config
self._content_hash = self._get_content_hash()

def locked_repository(self) -> LockfileRepository:
"""
Searches and returns a repository of locked packages.
Expand Down
12 changes: 2 additions & 10 deletions src/poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,7 @@ def __init__(
) -> None:
from poetry.repositories.repository_pool import RepositoryPool

try:
super().__init__( # type: ignore[call-arg]
file, local_config, package, pyproject_type=PyProjectTOML
)
except TypeError:
# TODO: backward compatibility, can be simplified if poetry-core with
# https://github.com/python-poetry/poetry-core/pull/483 is available
super().__init__(file, local_config, package)
self._pyproject = PyProjectTOML(file)
super().__init__(file, local_config, package, pyproject_type=PyProjectTOML)

self._locker = locker
self._config = config
Expand All @@ -59,7 +51,7 @@ def pyproject(self) -> PyProjectTOML:
return cast("PyProjectTOML", pyproject)

@property
def file(self) -> TOMLFile: # type: ignore[override]
def file(self) -> TOMLFile:
return self.pyproject.file

@property
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/publishing/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def adapter(self) -> adapters.HTTPAdapter:

@property
def files(self) -> list[Path]:
dist = self._poetry.file.parent / "dist"
dist = self._poetry.file.path.parent / "dist"
version = self._package.version.to_string()
escaped_name = distribution_name(self._package.name)

Expand Down Expand Up @@ -301,7 +301,7 @@ def _register(self, session: requests.Session, url: str) -> requests.Response:
"""
Register a package to a repository.
"""
dist = self._poetry.file.parent / "dist"
dist = self._poetry.file.path.parent / "dist"
escaped_name = distribution_name(self._package.name)
file = dist / f"{escaped_name}-{self._package.version.to_string()}.tar.gz"

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/pyproject/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, path: Path) -> None:
self._toml_document: TOMLDocument | None = None

@property
def file(self) -> TOMLFile: # type: ignore[override]
def file(self) -> TOMLFile:
return self._toml_file

@property
Expand Down
Loading

0 comments on commit 93fd76b

Please sign in to comment.