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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ poetry export -f requirements.txt --output requirements.txt
* `--all-groups`: Include all dependency groups.
* `--without-hashes`: Exclude hashes from the exported file.
* `--with-credentials`: Include credentials for extra indices.
* `--without-markers`: Exclude markers in the exported file.
11 changes: 11 additions & 0 deletions src/poetry_plugin_export/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class ExportCommand(GroupCommand):
),
option("all-extras", None, "Include all sets of extra dependencies."),
option("with-credentials", None, "Include credentials for extra indices."),
option(
"without-markers",
None,
"Exclude markers in the exported file.",
flag=True,
),
]

@property
Expand Down Expand Up @@ -146,6 +152,10 @@ def handle(self) -> int:
)
return 1

without_markers = False
if self.option("without-markers"):
without_markers = self.option("without-markers")

groups = (
self.poetry.package.dependency_group_names(include_optional=True)
if self.option("all-groups")
Expand All @@ -158,6 +168,7 @@ def handle(self) -> int:
exporter.with_hashes(not self.option("without-hashes"))
exporter.with_credentials(self.option("with-credentials"))
exporter.with_urls(not self.option("without-urls"))
exporter.with_markers(not without_markers)
exporter.export(fmt, Path.cwd(), output or self.io)

return 0
8 changes: 7 additions & 1 deletion src/poetry_plugin_export/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, poetry: Poetry, io: IO) -> None:
self._with_hashes = True
self._with_credentials = False
self._with_urls = True
self._with_markers = True
self._extras: Collection[NormalizedName] = ()
self._groups: Iterable[str] = [MAIN_GROUP]

Expand Down Expand Up @@ -77,6 +78,11 @@ def with_credentials(self, with_credentials: bool = True) -> Exporter:

return self

def with_markers(self, with_markers: bool = True) -> Exporter:
self._with_markers = with_markers

return self

def export(self, fmt: str, cwd: Path, output: IO | str) -> None:
if not self.is_format_supported(fmt):
raise ValueError(f"Invalid export format: {fmt}")
Expand Down Expand Up @@ -153,7 +159,7 @@ def _export_generic_txt(

if not is_direct_remote_reference and ";" in requirement:
markers = requirement.split(";", 1)[1].strip()
if markers:
if markers and self._with_markers:
line += f" ; {markers}"

if (
Expand Down
58 changes: 58 additions & 0 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,64 @@ def test_exporter_can_export_requirements_txt_with_nested_packages_and_markers(
assert expected == {}


@pytest.mark.parametrize("lock_version", ["2.1"])
def test_exporter_with_no_markers_flag(
tmp_path: Path, poetry: Poetry, lock_version: str
) -> None:
lock_data = {
"package": [
{
"name": "greenlet",
"version": "3.2.1",
"optional": False,
"python-versions": ">=3.9",
"markers": 'python_version < "3.14" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32")',
},
{
"name": "typing-extensions",
"version": "4.13.2",
"optional": False,
"python-versions": ">=3.8",
},
{
"name": "sqlalchemy",
"version": "2.0.40",
"optional": False,
"python-versions": ">=3.7",
"dependencies": {
"greenlet": {
"version": ">=1",
"markers": 'python_version < "3.14" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32")',
},
"typing-extensions": ">=4.6.0",
},
},
],
"metadata": {
"lock-version": lock_version,
"files": {"greenlet": [], "typing-extensions": [], "sqlalchemy": []},
},
}

fix_lock_data(lock_data)
poetry.locker.mock_lock_data(lock_data) # type: ignore[attr-defined]

exporter = Exporter(poetry, NullIO())
exporter.with_markers(False)
exporter.export("requirements.txt", tmp_path, "requirements.txt")

with open(tmp_path / "requirements.txt") as f:
lines = set(f.read().strip().splitlines())

expected = {
"greenlet==3.2.1",
"sqlalchemy==2.0.40",
"typing-extensions==4.13.2",
}

assert lines == expected


@pytest.mark.parametrize(
["dev", "lines"],
[
Expand Down