Skip to content

Commit 2b587ae

Browse files
authored
Add support for Python3.13 (#1469)
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 61c93ac commit 2b587ae

File tree

14 files changed

+52
-10
lines changed

14 files changed

+52
-10
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
strategy:
3232
max-parallel: 4
3333
matrix:
34-
python-version: ["3.10", "3.11", "3.12"]
34+
python-version: ["3.10", "3.11", "3.12", "3.13"]
3535

3636
steps:
3737
- name: Checkout code

.github/workflows/pypi-release-aboutcode-pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Python
1818
uses: actions/setup-python@v5
1919
with:
20-
python-version: 3.12
20+
python-version: 3.13
2121

2222
- name: Install flot
2323
run: python -m pip install flot --user

.github/workflows/pypi-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Python
1818
uses: actions/setup-python@v5
1919
with:
20-
python-version: 3.12
20+
python-version: 3.13
2121

2222
- name: Install pypa/build
2323
run: python -m pip install build --user

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Changelog
44
v34.12.0 (unreleased)
55
---------------------
66

7+
- Add support for Python 3.13.
8+
Upgrade the base image in Dockerfile to ``python:3.13-slim``.
9+
https://github.com/aboutcode-org/scancode.io/pull/1469/files
10+
711
- Display matched snippets details in "Resource viewer", including the package,
812
resource, and similarity values.
913
https://github.com/aboutcode-org/scancode.io/issues/1688

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
2121
# Visit https://github.com/aboutcode-org/scancode.io for support and download.
2222

23-
FROM python:3.12-slim
23+
FROM python:3.13-slim
2424

2525
LABEL org.opencontainers.image.source="https://github.com/aboutcode-org/scancode.io"
2626
LABEL org.opencontainers.image.description="ScanCode.io"

docs/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ Pre-installation Checklist
245245

246246
Before you install ScanCode.io, make sure you have the following prerequisites:
247247

248-
* **Python: versions 3.10 to 3.12** found at https://www.python.org/downloads/
248+
* **Python: versions 3.10 to 3.13** found at https://www.python.org/downloads/
249249
* **Git**: most recent release available at https://git-scm.com/
250250
* **PostgreSQL**: release 11 or later found at https://www.postgresql.org/ or
251251
https://postgresapp.com/ on macOS

scanpipe/apps.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
2121
# Visit https://github.com/aboutcode-org/scancode.io for support and download.
2222

23+
import importlib.util
2324
import inspect
2425
import logging
2526
import sys
@@ -134,7 +135,14 @@ def register_pipeline_from_file(self, path):
134135
after being found.
135136
"""
136137
module_name = inspect.getmodulename(path)
137-
module = SourceFileLoader(module_name, str(path)).load_module()
138+
139+
loader = SourceFileLoader(module_name, str(path))
140+
spec = importlib.util.spec_from_loader(module_name, loader)
141+
if spec and spec.loader:
142+
module = importlib.util.module_from_spec(spec)
143+
spec.loader.exec_module(module)
144+
else:
145+
raise ImportError(f"Could not load module from path: {path}")
138146

139147
def is_local_module_pipeline(obj):
140148
return is_pipeline(obj) and obj.__module__ == module_name

scanpipe/pipes/fetch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
2121
# Visit https://github.com/aboutcode-org/scancode.io for support and download.
2222

23-
import cgi
2423
import json
2524
import logging
2625
import os
@@ -33,6 +32,7 @@
3332
from urllib.parse import urlparse
3433

3534
from django.conf import settings
35+
from django.utils.http import parse_header_parameters
3636

3737
import git
3838
import requests
@@ -126,7 +126,7 @@ def fetch_http(uri, to=None):
126126
raise requests.RequestException
127127

128128
content_disposition = response.headers.get("content-disposition", "")
129-
_, params = cgi.parse_header(content_disposition)
129+
_, params = parse_header_parameters(content_disposition)
130130
filename = params.get("filename")
131131
if not filename:
132132
# Using `response.url` in place of provided `Scan.uri` since the former

scanpipe/pipes/spdx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from dataclasses import dataclass
2727
from dataclasses import field
2828
from datetime import datetime
29+
from datetime import timezone
2930
from pathlib import Path
3031
from typing import List # Python 3.8 compatibility
3132

@@ -125,7 +126,7 @@ class CreationInfo:
125126
Format: YYYY-MM-DDThh:mm:ssZ
126127
"""
127128
created: str = field(
128-
default_factory=lambda: datetime.utcnow().isoformat(timespec="seconds") + "Z",
129+
default_factory=lambda: datetime.now(timezone.utc).isoformat(timespec="seconds")
129130
)
130131

131132
def as_dict(self):

scanpipe/tests/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
import os
2424
import uuid
25+
import warnings
2526
from datetime import datetime
27+
from functools import wraps
2628
from unittest import mock
2729

2830
from django.apps import apps
@@ -48,6 +50,24 @@
4850
mocked_now = mock.Mock(now=lambda: datetime(2010, 10, 10, 10, 10, 10))
4951

5052

53+
def filter_warnings(action, category, module=None):
54+
"""Apply a warning filter to a function."""
55+
56+
def decorator(func):
57+
@wraps(func)
58+
def wrapper(*args, **kwargs):
59+
original_filters = warnings.filters[:]
60+
try:
61+
warnings.filterwarnings(action, category=category, module=module)
62+
return func(*args, **kwargs)
63+
finally:
64+
warnings.filters = original_filters
65+
66+
return wrapper
67+
68+
return decorator
69+
70+
5171
def make_string(length):
5272
return str(uuid.uuid4())[:length]
5373

0 commit comments

Comments
 (0)