From 027caac37fae8df63fbab62277ff8aca7da01a04 Mon Sep 17 00:00:00 2001 From: 404-geek Date: Sat, 12 Jul 2025 22:46:04 -0400 Subject: [PATCH 1/3] Update PackageScoreMixin with score date parsing --- CHANGELOG.rst | 5 +++ docs/source/conf.py | 2 +- docs/source/contribute/contrib_doc.rst | 2 +- docs/source/skeleton-usage.rst | 2 +- pyproject.toml | 52 ++++++++++++++++++++++++++ setup.cfg | 2 +- src/README.rst | 2 + src/scorecode/ossf_scorecard.py | 2 +- tests/README.rst | 2 + 9 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 pyproject.toml create mode 100644 src/README.rst create mode 100644 tests/README.rst diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b31ddac..3c001f1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -24,3 +24,8 @@ v0.0.3 - 2025-02-24 -------------------- Patch Release of scorecode to fix checks in scorecard data. + +v0.0.4 - 2025-07-12 +-------------------- + +Added parsing score date functionality to `PackageScoreMixin` diff --git a/docs/source/conf.py b/docs/source/conf.py index 7771ff0..8c88fa2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -43,7 +43,7 @@ # This points to aboutcode.readthedocs.io # In case of "undefined label" ERRORS check docs on intersphinx to troubleshoot -# Link was created at commit - https://github.com/nexB/aboutcode/commit/faea9fcf3248f8f198844fe34d43833224ac4a83 +# Link was created at commit - https://github.com/aboutcode-org/aboutcode/commit/faea9fcf3248f8f198844fe34d43833224ac4a83 intersphinx_mapping = { "aboutcode": ("https://aboutcode.readthedocs.io/en/latest/", None), diff --git a/docs/source/contribute/contrib_doc.rst b/docs/source/contribute/contrib_doc.rst index 13882e1..5640db2 100644 --- a/docs/source/contribute/contrib_doc.rst +++ b/docs/source/contribute/contrib_doc.rst @@ -12,7 +12,7 @@ To get started, create or identify a working directory on your local machine. Open that directory and execute the following command in a terminal session:: - git clone https://github.com/nexB/skeleton.git + git clone https://github.com/aboutcode-org/skeleton.git That will create an ``/skeleton`` directory in your working directory. Now you can install the dependencies in a virtualenv:: diff --git a/docs/source/skeleton-usage.rst b/docs/source/skeleton-usage.rst index cde23dc..6cb4cc5 100644 --- a/docs/source/skeleton-usage.rst +++ b/docs/source/skeleton-usage.rst @@ -118,7 +118,7 @@ corrected. You can check to see if your corrections are valid by running: Once the wheels are collected and the ABOUT files are generated and correct, upload them to thirdparty.aboutcode.org/pypi by placing the wheels and ABOUT files from the thirdparty directory to the pypi directory at -https://github.com/nexB/thirdparty-packages +https://github.com/aboutcode-org/thirdparty-packages Usage after project initialization diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cde7907 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,52 @@ +[build-system] +requires = ["setuptools >= 50", "wheel", "setuptools_scm[toml] >= 6"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +# this is used populated when creating a git archive +# and when there is .git dir and/or there is no git installed +fallback_version = "9999.$Format:%h-%cs$" + +[tool.pytest.ini_options] +norecursedirs = [ + ".git", + "bin", + "dist", + "build", + "_build", + "dist", + "etc", + "local", + "ci", + "docs", + "man", + "share", + "samples", + ".cache", + ".settings", + "Include", + "include", + "Lib", + "lib", + "lib64", + "Lib64", + "Scripts", + "thirdparty", + "tmp", + "venv", + "tests/data", + ".eggs", + "src/*/data", + "tests/*/data" +] + +python_files = "*.py" + +python_classes = "Test" +python_functions = "test" + +addopts = [ + "-rfExXw", + "--strict-markers", + "--doctest-modules" +] diff --git a/setup.cfg b/setup.cfg index ba4fb5b..c7da876 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = scorecode -version = 0.0.3 +version = 0.0.4 license = Apache-2.0 description = A package to fetch data from OpenSSF Scorecard API long_description = file:README.rst diff --git a/src/README.rst b/src/README.rst new file mode 100644 index 0000000..ec651fc --- /dev/null +++ b/src/README.rst @@ -0,0 +1,2 @@ +Put your Python source code (and installable data) in this directory. + diff --git a/src/scorecode/ossf_scorecard.py b/src/scorecode/ossf_scorecard.py index 37e677a..842ad9d 100644 --- a/src/scorecode/ossf_scorecard.py +++ b/src/scorecode/ossf_scorecard.py @@ -47,7 +47,7 @@ def is_available(): return response.ok -def fetch_scorecard_info(package, logger): +def fetch_scorecard_info(package, logger=None): """ Return scorecard info for a list of discovered packages. """ diff --git a/tests/README.rst b/tests/README.rst new file mode 100644 index 0000000..d94783e --- /dev/null +++ b/tests/README.rst @@ -0,0 +1,2 @@ +Put your Python test modules in this directory. + From 93b63d8c34ad1ad7b7522625d0f09fa6d9bd3734 Mon Sep 17 00:00:00 2001 From: 404-geek Date: Sat, 12 Jul 2025 22:58:11 -0400 Subject: [PATCH 2/3] Parse score Date Signed-off-by: 404-geek --- src/scorecode/contrib/django/models.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/scorecode/contrib/django/models.py b/src/scorecode/contrib/django/models.py index d939948..cf62a1a 100644 --- a/src/scorecode/contrib/django/models.py +++ b/src/scorecode/contrib/django/models.py @@ -59,6 +59,30 @@ class ScoringTool(models.TextChoices): help_text=_("Date when the scoring was calculated on the package"), ) + @classmethod + def parse_score_date(cls, date_str, formats=None): + """ + Parse a date string into a timezone-aware datetime object, + or return None if parsing fails. + """ + from datetime import datetime + from django.utils import timezone + + if not formats: + formats = ["%Y-%m-%d", "%Y-%m-%dT%H:%M:%SZ"] + + if date_str: + for fmt in formats: + try: + naive_datetime = datetime.strptime(date_str, fmt) + return timezone.make_aware( + naive_datetime, timezone.get_current_timezone() + ) + except ValueError: + continue + + return None + class Meta: abstract = True From cacea5269ec7160583c981ffb8d56790165af280 Mon Sep 17 00:00:00 2001 From: 404-geek Date: Sat, 12 Jul 2025 23:10:39 -0400 Subject: [PATCH 3/3] sort imports Signed-off-by: 404-geek --- src/scorecode/contrib/django/models.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/scorecode/contrib/django/models.py b/src/scorecode/contrib/django/models.py index cf62a1a..8a9b4b5 100644 --- a/src/scorecode/contrib/django/models.py +++ b/src/scorecode/contrib/django/models.py @@ -6,8 +6,11 @@ # See https://aboutcode.org for more information about nexB OSS projects. # -from django.core.exceptions import ValidationError + +from datetime import datetime + from django.db import models +from django.utils import timezone from django.utils.translation import gettext_lazy as _ @@ -65,8 +68,6 @@ def parse_score_date(cls, date_str, formats=None): Parse a date string into a timezone-aware datetime object, or return None if parsing fails. """ - from datetime import datetime - from django.utils import timezone if not formats: formats = ["%Y-%m-%d", "%Y-%m-%dT%H:%M:%SZ"] @@ -75,9 +76,7 @@ def parse_score_date(cls, date_str, formats=None): for fmt in formats: try: naive_datetime = datetime.strptime(date_str, fmt) - return timezone.make_aware( - naive_datetime, timezone.get_current_timezone() - ) + return timezone.make_aware(naive_datetime, timezone.get_current_timezone()) except ValueError: continue