diff --git a/requirements-server.txt b/requirements-server.txt --- a/requirements-server.txt +++ b/requirements-server.txt @@ -1,2 +1,3 @@ Django < 3 djangorestframework +setuptools diff --git a/swh/deposit/api/__init__.py b/swh/deposit/api/__init__.py --- a/swh/deposit/api/__init__.py +++ b/swh/deposit/api/__init__.py @@ -0,0 +1,11 @@ +# Copyright (C) 2020 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import pkg_resources + +try: + __version__ = pkg_resources.get_distribution("swh.deposit").version +except pkg_resources.DistributionNotFound: + __version__ = "devel" diff --git a/swh/deposit/api/private/deposit_read.py b/swh/deposit/api/private/deposit_read.py --- a/swh/deposit/api/private/deposit_read.py +++ b/swh/deposit/api/private/deposit_read.py @@ -16,6 +16,8 @@ from swh.model import identifiers from swh.deposit.utils import normalize_date +from swh.deposit.api import __version__ + from . import DepositReadMixin, APIPrivateView from ...config import SWH_PERSON, ARCHIVE_TYPE from ..common import APIGet @@ -106,7 +108,11 @@ def __init__(self): super().__init__() self.provider = self.config["provider"] - self.tool = self.config["tool"] + self.tool = { + "name": "swh-deposit", + "version": __version__, + "configuration": {"sword_version": "2"}, + } def _normalize_dates(self, deposit, metadata): """Normalize the date to use as a tuple of author date, committer date diff --git a/swh/deposit/tests/api/test_deposit_private_read_metadata.py b/swh/deposit/tests/api/test_deposit_private_read_metadata.py --- a/swh/deposit/tests/api/test_deposit_private_read_metadata.py +++ b/swh/deposit/tests/api/test_deposit_private_read_metadata.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2019 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -6,6 +6,7 @@ from django.urls import reverse from rest_framework import status +from swh.deposit.api import __version__ from swh.deposit.models import Deposit from swh.deposit.config import PRIVATE_GET_DEPOSIT_METADATA, SWH_PERSON, EDIT_SE_IRI @@ -84,7 +85,7 @@ "tool": { "configuration": {"sword_version": "2"}, "name": "swh-deposit", - "version": "0.0.1", + "version": __version__, }, }, "deposit": { @@ -160,7 +161,7 @@ "tool": { "configuration": {"sword_version": "2"}, "name": "swh-deposit", - "version": "0.0.1", + "version": __version__, }, }, "deposit": { @@ -273,7 +274,7 @@ "tool": { "configuration": {"sword_version": "2"}, "name": "swh-deposit", - "version": "0.0.1", + "version": __version__, }, }, "deposit": { @@ -374,7 +375,7 @@ "tool": { "configuration": {"sword_version": "2"}, "name": "swh-deposit", - "version": "0.0.1", + "version": __version__, }, } @@ -500,7 +501,7 @@ "tool": { "configuration": {"sword_version": "2"}, "name": "swh-deposit", - "version": "0.0.1", + "version": __version__, }, }