-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathcli.py
More file actions
271 lines (209 loc) · 6.62 KB
/
cli.py
File metadata and controls
271 lines (209 loc) · 6.62 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
import logging
import os
import time
from typing import Optional
import click
from click import Context, IntRange
from conda_forge_tick import lazy_json_backends
from conda_forge_tick.os_utils import override_env
from conda_forge_tick.utils import setup_logging
from .cli_context import CliContext
logger = logging.getLogger(__name__)
pass_context = click.make_pass_decorator(CliContext, ensure=True)
job_option = click.option(
"--job",
default=1,
type=IntRange(1, None),
show_default=True,
help="If given with --n-jobs, the number of the job to run in the range [1, n_jobs].",
)
n_jobs_option = click.option(
"--n-jobs",
default=1,
type=IntRange(1, None),
show_default=True,
help="If given, the total number of jobs being run.",
)
def check_job_param_relative(job: int, n_jobs: int) -> None:
if job > n_jobs:
raise click.BadParameter(f"job must be in the range [1, n_jobs], got {job}")
class TimedCommand(click.Command):
def invoke(self, ctx: click.Context):
start = time.time()
super().invoke(ctx)
click.echo(f"FINISHED STAGE {self.name} IN {time.time() - start} SECONDS")
click.Group.command_class = TimedCommand
@click.group()
@click.option("--debug/--no-debug", default=False)
@click.option(
"--dry-run/--no-dry-run",
default=False,
help="dry run: don't push changes to PRs or graph to Github",
)
@click.option(
"--online/--offline",
default=False,
help="online: Make requests to GitHub for accessing the dependency graph. This is useful for local testing. Note "
"however that any write operations will not be performed. Important: The current working directory will be "
"used to cache JSON files. Local files will be used if they exist.",
)
@click.option(
"--no-containers",
is_flag=True,
help=(
"Do not use containers for isolating recipe code from the system. "
"Turning off containers is a potential security issue."
),
)
@pass_context
@click.pass_context
def main(
click_context: Context,
ctx: CliContext,
debug: bool,
dry_run: bool,
online: bool,
no_containers: bool,
) -> None:
log_level = "debug" if debug else "info"
setup_logging(log_level)
ctx.debug = debug
ctx.dry_run = dry_run
if ctx.debug:
os.environ["CONDA_FORGE_TICK_DEBUG"] = "1"
if online:
logger.info("Running in online mode")
click_context.with_resource(
lazy_json_backends.lazy_json_override_backends(["github"]),
)
if no_containers:
logger.info("Running without containers")
click_context.with_resource(override_env("CF_TICK_IN_CONTAINER", "true"))
@main.command(name="gather-all-feedstocks")
def gather_all_feedstocks() -> None:
from . import all_feedstocks
all_feedstocks.main()
@main.command(name="make-graph")
@job_option
@n_jobs_option
@click.option(
"--update-nodes-and-edges",
is_flag=True,
help="If given, update the nodes and edges in the graph. Otherwise, only update the node attrs.",
)
@pass_context
def make_graph(
ctx: CliContext, job: int, n_jobs: int, update_nodes_and_edges: bool
) -> None:
from . import make_graph
check_job_param_relative(job, n_jobs)
make_graph.main(
ctx, job=job, n_jobs=n_jobs, update_nodes_and_edges=update_nodes_and_edges
)
@main.command(name="update-upstream-versions")
@job_option
@n_jobs_option
@click.argument(
"package",
required=False,
)
@pass_context
def update_upstream_versions(
ctx: CliContext, job: int, n_jobs: int, package: Optional[str]
) -> None:
"""
Update the upstream versions of feedstocks in the graph.
If PACKAGE is given, only update that package, otherwise update all packages.
"""
from . import update_upstream_versions
check_job_param_relative(job, n_jobs)
update_upstream_versions.main(ctx, job=job, n_jobs=n_jobs, package=package)
@main.command(name="auto-tick")
@click.argument(
"package",
required=False,
)
@pass_context
def auto_tick(ctx: CliContext, package: str | None) -> None:
"""
Run the main bot logic that runs all migrations, updates the graph accordingly, and opens the corresponding PRs.
If PACKAGE is given, only run the bot for that package, otherwise run the bot for all packages.
"""
from . import auto_tick
auto_tick.main(ctx, package=package)
@main.command(name="make-status-report")
def make_status_report() -> None:
from . import status_report
status_report.main()
@main.command(name="update-prs")
@job_option
@n_jobs_option
@pass_context
def update_prs(ctx: CliContext, job: int, n_jobs: int) -> None:
from . import update_prs
check_job_param_relative(job, n_jobs)
update_prs.main(ctx, job=job, n_jobs=n_jobs)
@main.command(name="make-mappings")
def make_mappings() -> None:
from . import mappings
mappings.main()
@main.command(name="deploy-to-github")
@pass_context
def deploy_to_github(ctx: CliContext) -> None:
from . import deploy
deploy.deploy(ctx)
@main.command(name="backup-lazy-json")
@pass_context
def backup_lazy_json(ctx: CliContext) -> None:
from . import lazy_json_backups
lazy_json_backups.main_backup(ctx)
@main.command(name="sync-lazy-json-across-backends")
@pass_context
def sync_lazy_json_across_backends(ctx: CliContext) -> None:
from . import lazy_json_backends
lazy_json_backends.main_sync(ctx)
@main.command(name="cache-lazy-json-to-disk")
@pass_context
def cache_lazy_json_to_disk(ctx: CliContext) -> None:
from . import lazy_json_backends
lazy_json_backends.main_cache(ctx)
@main.command(name="make-import-to-package-mapping")
@click.option(
"--max-artifacts",
default=30000,
type=IntRange(1, None),
show_default=True,
help="If given, the maximum number of artifacts to process.",
)
@pass_context
def make_import_to_package_mapping(
ctx: CliContext,
max_artifacts: int,
) -> None:
"""
Make the import to package mapping.
"""
from . import import_to_pkg
import_to_pkg.main(ctx, max_artifacts)
@main.command(name="make-migrators")
@click.option(
"--version-only/--all",
default=False,
help="If given, only initialize the Version migrator.",
)
@pass_context
def make_migrators(
ctx: CliContext,
version_only: bool,
) -> None:
"""
Make the migrators.
"""
from . import make_migrators as _make_migrators
_make_migrators.main(ctx, version_only=version_only)
if __name__ == "__main__":
# This entrypoint can be used for debugging.
# click will read the command line arguments and call the corresponding
# function.
# Example: python -m conda_forge_tick.cli --debug make-graph
main()