Skip to content
Open
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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ poetry export -f requirements.txt --output requirements.txt
> which are exported with their resolved hashes, are included.

> [!NOTE]
> Only the `constraints.txt` and `requirements.txt` formats are currently supported.
> The following formats are currently supported:
> * `requirements.txt`
> * `constraints.txt`
> * `pylock.toml`

### Available options

* `--format (-f)`: The format to export to (default: `requirements.txt`). Currently, only `constraints.txt` and `requirements.txt` are supported.
* `--format (-f)`: The format to export to (default: `requirements.txt`). Additionally, `constraints.txt` and `pylock.toml` are supported.
* `--output (-o)`: The name of the output file. If omitted, print to standard output.
* `--with`: The optional and non-optional dependency groups to include. By default, only the main dependencies are included.
* `--only`: The only dependency groups to include. It is possible to exclude the `main` group this way.
Expand Down
2 changes: 1 addition & 1 deletion docs/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ poetry export --only test,docs

### Available options

* `--format (-f)`: The format to export to (default: `requirements.txt`). Currently, only `constraints.txt` and `requirements.txt` are supported.
* `--format (-f)`: The format to export to (default: `requirements.txt`). Additionally, `constraints.txt` and `pylock.toml` are supported.
* `--output (-o)`: The name of the output file. If omitted, print to standard output.
* `--with`: The optional and non-optional dependency groups to include. By default, only the main dependencies are included.
* `--only`: The only dependency groups to include. It is possible to exclude the `main` group this way.
Expand Down
103 changes: 53 additions & 50 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ license = "MIT"
readme = "README.md"
requires-python = ">=3.10,<4.0"
dependencies = [
"poetry>=2.1.0,<3.0.0",
"poetry @ git+https://github.com/radoering/poetry.git@repo-file-url-size-upload-time",
"poetry-core>=2.1.0,<3.0.0",
"tomlkit (>=0.11.4,<1.0.0)",
]
dynamic = ["classifiers"]

Expand Down
20 changes: 18 additions & 2 deletions src/poetry_plugin_export/command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import re

from pathlib import Path
from typing import TYPE_CHECKING

Expand All @@ -24,8 +26,7 @@ class ExportCommand(GroupCommand):
option(
"format",
"f",
"Format to export to. Currently, only constraints.txt and"
" requirements.txt are supported.",
"Format to export to: constraints.txt, requirements.txt, pylock.toml",
flag=False,
default=Exporter.FORMAT_REQUIREMENTS_TXT,
),
Expand Down Expand Up @@ -89,6 +90,21 @@ def handle(self) -> int:

output = self.option("output")

pylock_pattern = r"^pylock\.([^.]+)\.toml$"
if (
fmt == Exporter.FORMAT_PYLOCK_TOML
and output
and Path(output).name != "pylock.toml"
and not re.match(pylock_pattern, Path(output).name)
):
self.line_error(
"<error>"
'The output file for pylock.toml export must be named "pylock.toml"'
f' or must follow the regex "{pylock_pattern}", e.g. "pylock.dev.toml"'
"</error>"
)
return 1

locker = self.poetry.locker
if not locker.is_locked():
self.line_error("<comment>The lock file does not exist. Locking.</comment>")
Expand Down
Loading