Skip to content

Commit 7b97d3b

Browse files
authored
Release 34.6.1 (#1260)
* Remove print statements from migration files. Signed-off-by: tdruez <[email protected]> * Display full traceback on error in execute command Signed-off-by: tdruez <[email protected]> * Refactor the ``get_env_from_config_file`` to support empty config file Signed-off-by: tdruez <[email protected]> --------- Signed-off-by: tdruez <[email protected]>
1 parent 9858953 commit 7b97d3b

File tree

7 files changed

+54
-26
lines changed

7 files changed

+54
-26
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
v34.6.1 (2024-06-07)
5+
--------------------
6+
7+
- Remove print statements from migration files.
8+
- Display full traceback on error in the ``execute`` management command.
9+
- Log the Project message creation.
10+
- Refactor the ``get_env_from_config_file`` to support empty config file.
11+
412
v34.6.0 (2024-06-07)
513
--------------------
614

scancodeio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import git
3030

31-
VERSION = "34.6.0"
31+
VERSION = "34.6.1"
3232

3333
PROJECT_DIR = Path(__file__).resolve().parent
3434
ROOT_DIR = PROJECT_DIR.parent

scanpipe/management/commands/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import shutil
2424
import sys
25+
import traceback
2526
from pathlib import Path
2627

2728
from django.apps import apps
@@ -405,9 +406,10 @@ def execute_project(project, run_async=False, command=None): # noqa: C901
405406
except KeyboardInterrupt:
406407
run.set_task_stopped()
407408
raise CommandError("Pipeline execution stopped.")
408-
except Exception as e:
409-
run.set_task_ended(exitcode=1, output=str(e))
410-
raise CommandError(e)
409+
except Exception:
410+
traceback_str = traceback.format_exc()
411+
run.set_task_ended(exitcode=1, output=traceback_str)
412+
raise CommandError(traceback_str)
411413

412414
run.refresh_from_db()
413415

scanpipe/migrations/0031_scancode_toolkit_v32_data_updates.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Generated by Django 4.2 on 2023-05-05 10:11
22

3+
import logging
4+
35
from django.db import migrations
46
from django.db.models import Q
57
from django.conf import settings
68

9+
logger = logging.getLogger("django")
10+
711

812
def compute_package_declared_license_expression_spdx(apps, schema_editor):
913
"""
@@ -21,7 +25,7 @@ def compute_package_declared_license_expression_spdx(apps, schema_editor):
2125
).only("declared_license_expression")
2226

2327
object_count = queryset.count()
24-
print(f"\nCompute declared_license_expression_spdx for {object_count:,} packages.")
28+
logger.info(f"\nCompute declared_license_expression_spdx for {object_count:,} packages.")
2529

2630
chunk_size = 2000
2731
iterator = queryset.iterator(chunk_size=chunk_size)
@@ -33,9 +37,9 @@ def compute_package_declared_license_expression_spdx(apps, schema_editor):
3337
unsaved_objects.append(package)
3438

3539
if not (index % chunk_size) and unsaved_objects:
36-
print(f" {index:,} / {object_count:,} computed")
40+
logger.info(f" {index:,} / {object_count:,} computed")
3741

38-
print("Updating DB objects...")
42+
logger.info("Updating DB objects...")
3943
DiscoveredPackage.objects.bulk_update(
4044
objs=unsaved_objects,
4145
fields=["declared_license_expression_spdx"],
@@ -61,7 +65,7 @@ def compute_resource_detected_license_expression(apps, schema_editor):
6165
)
6266

6367
object_count = queryset.count()
64-
print(f"\nCompute detected_license_expression for {object_count:,} resources.")
68+
logger.info(f"\nCompute detected_license_expression for {object_count:,} resources.")
6569

6670
chunk_size = 2000
6771
iterator = queryset.iterator(chunk_size=chunk_size)
@@ -88,9 +92,9 @@ def compute_resource_detected_license_expression(apps, schema_editor):
8892
unsaved_objects.append(resource)
8993

9094
if not (index % chunk_size) and unsaved_objects:
91-
print(f" {index:,} / {object_count:,} computed")
95+
logger.info(f" {index:,} / {object_count:,} computed")
9296

93-
print("Updating DB objects...")
97+
logger.info("Updating DB objects...")
9498
CodebaseResource.objects.bulk_update(
9599
objs=unsaved_objects,
96100
fields=[
@@ -164,7 +168,7 @@ def compute_resource_license_detections(apps, schema_editor):
164168
queryset = CodebaseResource.objects.filter(~Q(licenses=[])).only("licenses")
165169

166170
object_count = queryset.count()
167-
print(f"\nCompute license_detections for {object_count:,} resources.")
171+
logger.info(f"\nCompute license_detections for {object_count:,} resources.")
168172

169173
chunk_size = 2000
170174
iterator = queryset.iterator(chunk_size=chunk_size)
@@ -176,9 +180,9 @@ def compute_resource_license_detections(apps, schema_editor):
176180
unsaved_objects.append(resource)
177181

178182
if not (index % chunk_size):
179-
print(f" {index:,} / {object_count:,} computed")
183+
logger.info(f" {index:,} / {object_count:,} computed")
180184

181-
print("Updating DB objects...")
185+
logger.info("Updating DB objects...")
182186
# Keeping the batch_size small as the `license_detections` content is often large,
183187
# and it may raise `django.db.utils.OperationalError: out of memory`
184188
CodebaseResource.objects.bulk_update(

scanpipe/migrations/0055_discoveredpackage_datafile_paths.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Generated by Django 5.0.2 on 2024-03-01 16:09
22

3+
import logging
4+
35
from django.db import migrations, models
46
from django.db.models import Q
57

8+
logger = logging.getLogger("django")
9+
610

711
def update_package_datasource_ids(apps, schema_editor):
812
"""
@@ -14,7 +18,7 @@ def update_package_datasource_ids(apps, schema_editor):
1418

1519
object_count = queryset.count()
1620
if object_count:
17-
print(f"\nCompute datasource_ids for {object_count:,} packages.")
21+
logger.info(f"\nCompute datasource_ids for {object_count:,} packages.")
1822

1923
chunk_size = 2000
2024
iterator = queryset.iterator(chunk_size=chunk_size)
@@ -26,7 +30,7 @@ def update_package_datasource_ids(apps, schema_editor):
2630
unsaved_objects.append(package)
2731

2832
if not (index % chunk_size) and unsaved_objects:
29-
print(f" {index:,} / {object_count:,} computed")
33+
logger.info(f" {index:,} / {object_count:,} computed")
3034

3135
DiscoveredPackage.objects.bulk_update(
3236
objs=unsaved_objects,

scanpipe/models.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,21 @@ def get_enabled_settings(self):
804804
if value not in EMPTY_VALUES
805805
}
806806

807+
def get_env_from_config_file(self):
808+
"""Return ``env`` dict loaded from the ``scancode-config.yml`` config file."""
809+
config_file = self.get_input_config_file()
810+
if not config_file:
811+
return
812+
813+
logger.info(f"Loading env from {config_file.relative_to(self.work_path)}")
814+
try:
815+
return saneyaml.load(config_file.read_text())
816+
except (saneyaml.YAMLError, Exception):
817+
self.add_error(
818+
f'Failed to load configuration from "{config_file}". '
819+
f"The file format is invalid."
820+
)
821+
807822
def get_env(self, field_name=None):
808823
"""
809824
Return the project environment loaded from the ``scancode-config.yml`` config
@@ -814,15 +829,8 @@ def get_env(self, field_name=None):
814829
env = {}
815830

816831
# 1. Load settings from config file when available.
817-
if config_file := self.get_input_config_file():
818-
logger.info(f"Loading env from {config_file.relative_to(self.work_path)}")
819-
try:
820-
env = saneyaml.load(config_file.read_text())
821-
except saneyaml.YAMLError:
822-
self.add_error(
823-
f'Failed to load configuration from "{config_file}". '
824-
f"The file format is invalid."
825-
)
832+
if env_from_config_file := self.get_env_from_config_file():
833+
env = env_from_config_file
826834

827835
# 2. Update with defined values from the Project ``settings`` field.
828836
env.update(self.get_enabled_settings())
@@ -1173,6 +1181,8 @@ def add_message(
11731181
A ``resource`` can be provided to keep track of the codebase resource that was
11741182
analyzed when the error occurred.
11751183
"""
1184+
logger.info(f"[{severity}] {description}")
1185+
11761186
if inspect.isclass(model):
11771187
model = model.__name__
11781188

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = scancodeio
3-
version = 34.6.0
3+
version = 34.6.1
44
license = Apache-2.0
55
description = Automate software composition analysis pipelines
66
long_description = file:README.rst
@@ -170,7 +170,7 @@ ignore = D1,D203,D205,D212,D400,D415
170170

171171
[bumpver]
172172
version_pattern = "MAJOR.MINOR.PATCH"
173-
current_version = "34.6.0"
173+
current_version = "34.6.1"
174174

175175
[bumpver:file_patterns]
176176
setup.cfg =

0 commit comments

Comments
 (0)