Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export: replace in-tree implementation with poetry-plugin-export #5413

Merged
merged 8 commits into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,19 @@ jobs:

- name: Run pytest
run: poetry run python -m pytest -p no:sugar -q tests/

- name: Get Plugin Version (poetry-plugin-export)
id: poetry-plugin-export-version
run: |
echo ::set-output name=version::$(\
poetry show poetry-plugin-export | grep version | cut -d : -f 2 | xargs)

- name: Checkout Plugin Source (poetry-plugin-export)
uses: actions/checkout@v2
with:
path: poetry-plugin-export
repository: python-poetry/poetry-plugin-export
ref: refs/tags/${{ steps.poetry-plugin-export-version.outputs.version }}

- name: Run pytest (poetry-plugin-export)
run: poetry run python -m pytest -p no:sugar -q poetry-plugin-export/tests/
15 changes: 12 additions & 3 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,13 @@ poetry export -f requirements.txt --output requirements.txt
```

{{% note %}}
Only the `requirements.txt` format is currently supported.
This command is also available as a pre-commit hook. See [pre-commit hooks](/docs/pre-commit-hooks#poetry-export) for more information.
This command is provided by the [Export Poetry Plugin](https://github.com/python-poetry/poetry-plugin-export)
and is also available as a pre-commit hook. See [pre-commit hooks](/docs/pre-commit-hooks#poetry-export) for more information.
{{% /note %}}

{{% note %}}
Unlike the `install` command, this command only includes the project's dependencies defined in the implicit `default`
group defined in `tool.poetry.dependencies` when used without specifying any options.
{{% /note %}}

### Options
Expand All @@ -631,8 +636,12 @@ This command is also available as a pre-commit hook. See [pre-commit hooks](/doc
Currently, only `requirements.txt` is supported.
* `--output (-o)`: The name of the output file. If omitted, print to standard
output.
* `--dev`: Include development dependencies.
* `--dev`: Include development dependencies. (**Deprecated**)
* `--extras (-E)`: Extra sets of dependencies to include.
* `--without`: The dependency groups to ignore.
* `--with`: The optional dependency groups to include.
* `--only`: The only dependency groups to include.
* `--default`: Only include the default dependencies. (**Deprecated**)
* `--without-hashes`: Exclude hashes from the exported file.
* `--without-urls`: Exclude source repository urls from the exported file.
* `--with-credentials`: Include credentials for extra indices.
Expand Down
157 changes: 88 additions & 69 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "poetry"
version = "1.2.0-beta.1"
version = "1.2.0-beta.2.dev0"
description = "Python dependency management and packaging made easy."
authors = [
"Sébastien Eustace <[email protected]>"
Expand Down Expand Up @@ -35,6 +35,7 @@ generate-setup-file = false
python = "^3.7"

poetry-core = "^1.1.0a7"
poetry-plugin-export = "^1.0"
cachecontrol = { version = "^0.12.9", extras = ["filecache"] }
cachy = "^0.3.0"
cleo = "^1.0.0a4"
Expand Down
7 changes: 5 additions & 2 deletions src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from cleo.exceptions import CleoException
from cleo.formatters.style import Style
from cleo.io.inputs.argv_input import ArgvInput
from cleo.io.null_io import NullIO

from poetry.__version__ import __version__
from poetry.console.command_loader import CommandLoader
Expand Down Expand Up @@ -52,7 +53,6 @@ def _load() -> type[Command]:
"build",
"check",
"config",
"export",
"init",
"install",
"lock",
Expand Down Expand Up @@ -306,10 +306,13 @@ def _configure_installer(self, command: InstallerCommand, io: IO) -> None:
installer.use_executor(poetry.config.get("experimental.new-installer", False))
command.set_installer(installer)

def _load_plugins(self, io: IO) -> None:
def _load_plugins(self, io: IO = None) -> None:
if self._plugins_loaded:
return

if io is None:
io = NullIO()

radoering marked this conversation as resolved.
Show resolved Hide resolved
self._disable_plugins = io.input.has_parameter_option("--no-plugins")

if not self._disable_plugins:
Expand Down
80 changes: 0 additions & 80 deletions src/poetry/console/commands/export.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/poetry/console/commands/group_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def activated_groups(self) -> set[str]:
for opt, new, group in [
("default", "only", "default"),
("no-dev", "only", "default"),
("dev", "without", "default"),
("dev", "with", "dev"),
("dev-only", "without", "default"),
]:
if self.io.input.has_option(opt) and self.option(opt):
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def handle(self) -> int | None:
)
return 1

locked_repo = self.poetry.locker.locked_repository(True)
locked_repo = self.poetry.locker.locked_repository()
root = self.project_with_activated_groups_only()

# Show tree view if requested
Expand Down
6 changes: 3 additions & 3 deletions src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _do_refresh(self) -> int:
if extra not in self._package.extras:
raise ValueError(f"Extra [{extra}] is not specified.")

locked_repository = self._locker.locked_repository(True)
locked_repository = self._locker.locked_repository()
solver = Solver(
self._package,
self._pool,
Expand All @@ -214,7 +214,7 @@ def _do_install(self, local_repo: Repository) -> int:
locked_repository = Repository()
if self._update:
if self._locker.is_locked() and not self._lock:
locked_repository = self._locker.locked_repository(True)
locked_repository = self._locker.locked_repository()

# If no packages have been whitelisted (The ones we want to update),
# we whitelist every package in the lock file.
Expand All @@ -240,7 +240,7 @@ def _do_install(self, local_repo: Repository) -> int:
else:
self._io.write_line("<info>Installing dependencies from lock file</>")

locked_repository = self._locker.locked_repository(True)
locked_repository = self._locker.locked_repository()

if not self._locker.is_fresh():
self._io.write_error_line(
Expand Down
16 changes: 4 additions & 12 deletions src/poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@


if TYPE_CHECKING:
from poetry.core.semver.version_constraint import VersionConstraint
from poetry.core.version.markers import BaseMarker
from tomlkit.items import InlineTable
from tomlkit.toml_document import TOMLDocument
Expand Down Expand Up @@ -86,7 +85,7 @@ def is_fresh(self) -> bool:

return False

def locked_repository(self, with_dev_reqs: bool = False) -> Repository:
def locked_repository(self) -> Repository:
"""
Searches and returns a repository of locked packages.
"""
Expand All @@ -98,13 +97,7 @@ def locked_repository(self, with_dev_reqs: bool = False) -> Repository:

lock_data = self.lock_data
packages = Repository()

if with_dev_reqs:
locked_packages = lock_data["package"]
else:
locked_packages = [
p for p in lock_data["package"] if p["category"] == "main"
]
locked_packages = lock_data["package"]

if not locked_packages:
return packages
Expand Down Expand Up @@ -316,8 +309,7 @@ def get_project_dependencies(
def get_project_dependency_packages(
self,
project_requires: list[Dependency],
project_python_marker: VersionConstraint | None = None,
dev: bool = False,
project_python_marker: BaseMarker | None = None,
extras: bool | Sequence[str] | None = None,
) -> Iterator[DependencyPackage]:
# Apply the project python marker to all requirements.
Expand All @@ -329,7 +321,7 @@ def get_project_dependency_packages(
marked_requires.append(require)
project_requires = marked_requires

repository = self.locked_repository(with_dev_reqs=dev)
repository = self.locked_repository()

# Build a set of all packages required by our selected extras
extra_package_names: set[str] | None = None
Expand Down
Loading