Page MenuHomeSoftware Heritage

D3909.diff
No OneTemporary

D3909.diff

diff --git a/swh/deposit/cli/__init__.py b/swh/deposit/cli/__init__.py
--- a/swh/deposit/cli/__init__.py
+++ b/swh/deposit/cli/__init__.py
@@ -3,6 +3,8 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
+# WARNING: do not import unnecessary things here to keep cli startup time under
+# control
import click
import logging
diff --git a/swh/deposit/cli/admin.py b/swh/deposit/cli/admin.py
--- a/swh/deposit/cli/admin.py
+++ b/swh/deposit/cli/admin.py
@@ -3,9 +3,10 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
+# WARNING: do not import unnecessary things here to keep cli startup time under
+# control
import click
-from swh.deposit.config import setup_django_for
from swh.deposit.cli import deposit
@@ -26,6 +27,8 @@
@click.pass_context
def admin(ctx, config_file, platform):
"""Server administration tasks (manipulate user or collections)"""
+ from swh.deposit.config import setup_django_for
+
# configuration happens here
setup_django_for(platform, config_file=config_file)
diff --git a/swh/deposit/cli/client.py b/swh/deposit/cli/client.py
--- a/swh/deposit/cli/client.py
+++ b/swh/deposit/cli/client.py
@@ -3,18 +3,14 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
+# WARNING: do not import unnecessary things here to keep cli startup time under
+# control
import os
import logging
import sys
-import tempfile
-import uuid
-import json
-import yaml
import click
-import xmltodict
-from swh.deposit.client import PublicApiDepositClient, MaintenanceError
from swh.deposit.cli import deposit
@@ -33,6 +29,8 @@
"""Generate a slug (sample purposes).
"""
+ import uuid
+
return str(uuid.uuid4())
@@ -70,6 +68,8 @@
Filepath to the metadata generated file
"""
+ import xmltodict
+
path = os.path.join(temp_dir, "metadata.xml")
# generate a metadata file with the minimum required metadata
codemetadata = {
@@ -102,6 +102,8 @@
password (str): User's password
"""
+ from swh.deposit.client import PublicApiDepositClient
+
client = PublicApiDepositClient(
{"url": url, "auth": {"username": username, "password": password},}
)
@@ -403,6 +405,9 @@
https://docs.softwareheritage.org/devel/swh-deposit/getting-started.html.
"""
+ import tempfile
+ from swh.deposit.client import MaintenanceError
+
url = _url(url)
config = {}
@@ -470,6 +475,8 @@
"""Deposit's status
"""
+ from swh.deposit.client import MaintenanceError
+
url = _url(url)
logger.debug("Status deposit")
try:
@@ -489,6 +496,9 @@
def print_result(data, output_format):
+ import json
+ import yaml
+
if output_format == "json":
click.echo(json.dumps(data))
elif output_format == "yaml":
diff --git a/swh/deposit/tests/cli/test_client.py b/swh/deposit/tests/cli/test_client.py
--- a/swh/deposit/tests/cli/test_client.py
+++ b/swh/deposit/tests/cli/test_client.py
@@ -144,7 +144,7 @@
metadata_path = os.path.join(tmp_path, "metadata.xml")
mocker.patch(
- "swh.deposit.cli.client.tempfile.TemporaryDirectory",
+ "tempfile.TemporaryDirectory",
return_value=contextlib.nullcontext(str(tmp_path)),
)
@@ -211,7 +211,7 @@
metadata_path = os.path.join(tmp_path, "metadata.xml")
mocker.patch(
- "swh.deposit.cli.client.tempfile.TemporaryDirectory",
+ "tempfile.TemporaryDirectory",
return_value=contextlib.nullcontext(str(tmp_path)),
)
with open(metadata_path, "a"):
@@ -320,7 +320,7 @@
metadata_path = os.path.join(tmp_path, "metadata.xml")
mocker.patch(
- "swh.deposit.cli.client.tempfile.TemporaryDirectory",
+ "tempfile.TemporaryDirectory",
return_value=contextlib.nullcontext(str(tmp_path)),
)

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 18, 4:41 PM (4 h, 10 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3216839

Event Timeline