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 @@ -13,6 +13,7 @@ from rest_framework import status from swh.core import tarball +from swh.deposit.api import __version__ from swh.deposit.utils import normalize_date from swh.model import identifiers @@ -106,7 +107,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.config import EDIT_SE_IRI, PRIVATE_GET_DEPOSIT_METADATA, SWH_PERSON from swh.deposit.models import Deposit @@ -83,7 +84,7 @@ "tool": { "configuration": {"sword_version": "2"}, "name": "swh-deposit", - "version": "0.0.1", + "version": __version__, }, }, "deposit": { @@ -159,7 +160,7 @@ "tool": { "configuration": {"sword_version": "2"}, "name": "swh-deposit", - "version": "0.0.1", + "version": __version__, }, }, "deposit": { @@ -272,7 +273,7 @@ "tool": { "configuration": {"sword_version": "2"}, "name": "swh-deposit", - "version": "0.0.1", + "version": __version__, }, }, "deposit": { @@ -373,7 +374,7 @@ "tool": { "configuration": {"sword_version": "2"}, "name": "swh-deposit", - "version": "0.0.1", + "version": __version__, }, } @@ -499,7 +500,7 @@ "tool": { "configuration": {"sword_version": "2"}, "name": "swh-deposit", - "version": "0.0.1", + "version": __version__, }, } diff --git a/swh/deposit/tests/test_init.py b/swh/deposit/tests/test_init.py new file mode 100644 --- /dev/null +++ b/swh/deposit/tests/test_init.py @@ -0,0 +1,10 @@ +# 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 + + +def test_version(): + from swh.deposit.api import __version__ + + assert __version__ is not None