-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathcommand.py
More file actions
81 lines (69 loc) · 2.77 KB
/
command.py
File metadata and controls
81 lines (69 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from __future__ import annotations
from cleo.helpers import option
from poetry.console.commands.installer_command import InstallerCommand
from poetry_plugin_export.exporter import Exporter
class ExportCommand(InstallerCommand):
name = "export"
description = "Exports the lock file to alternative formats."
options = [
option(
"format",
"f",
"Format to export to. Currently, only requirements.txt is supported.",
flag=False,
default=Exporter.FORMAT_REQUIREMENTS_TXT,
),
option("output", "o", "The name of the output file.", flag=False),
option("without-hashes", None, "Exclude hashes from the exported file."),
option(
"without-urls",
None,
"Exclude source repository urls from the exported file.",
),
option(
"dev",
None,
"Include development dependencies. (<warning>Deprecated</warning>)",
),
*InstallerCommand._group_dependency_options(),
option(
"extras",
"E",
"Extra sets of dependencies to include.",
flag=False,
multiple=True,
),
option("with-credentials", None, "Include credentials for extra indices."),
]
def handle(self) -> None:
fmt = self.option("format")
if not Exporter.is_format_supported(fmt):
raise ValueError(f"Invalid export format: {fmt}")
output = self.option("output")
locker = self.poetry.locker
if not locker.is_locked():
self.line_error("<comment>The lock file does not exist. Locking.</comment>")
options = []
if self.io.is_debug():
options.append(("-vvv", None))
elif self.io.is_very_verbose():
options.append(("-vv", None))
elif self.io.is_verbose():
options.append(("-v", None))
self.call("lock", " ".join(options)) # type: ignore[arg-type]
if not locker.is_fresh():
self.line_error(
"<warning>"
"Warning: The lock file is not up to date with "
"the latest changes in pyproject.toml. "
"You may be getting outdated dependencies. "
"Run update to update them."
"</warning>"
)
exporter = Exporter(self.poetry)
exporter.only_groups(list(self.activated_groups))
exporter.with_extras(self.option("extras"))
exporter.with_hashes(not self.option("without-hashes"))
exporter.with_credentials(self.option("with-credentials"))
exporter.with_urls(not self.option("without-urls"))
exporter.export(fmt, self.poetry.file.parent, output or self.io)