From 2ce7dd6098273191bccf2bf6c79981ff57778d92 Mon Sep 17 00:00:00 2001
From: cortadocodes <cortado.codes@protonmail.com>
Date: Mon, 16 May 2022 10:57:40 +0100
Subject: [PATCH] REF: Remove deprecated code

BREAKING CHANGE: This removes the deprecated code allowing datasets
to still be provided as lists in manifests and manifest schemas.
---
 setup.py                       |  2 +-
 tests/test_manifest_strands.py | 49 ----------------------------------
 tests/test_twine.py            | 37 +------------------------
 twined/migrations/__init__.py  |  3 +++
 twined/migrations/manifest.py  | 23 ----------------
 twined/migrations/twine.py     | 22 ---------------
 twined/twine.py                | 12 ---------
 7 files changed, 5 insertions(+), 143 deletions(-)
 delete mode 100644 twined/migrations/manifest.py
 delete mode 100644 twined/migrations/twine.py

diff --git a/setup.py b/setup.py
index 866a997..932cb85 100644
--- a/setup.py
+++ b/setup.py
@@ -16,7 +16,7 @@
 
 setup(
     name="twined",
-    version="0.4.1",
+    version="0.5.0",
     py_modules=[],
     install_requires=["jsonschema ~= 4.4.0", "python-dotenv"],
     url="https://www.github.com/octue/twined",
diff --git a/tests/test_manifest_strands.py b/tests/test_manifest_strands.py
index 63a3568..b43da93 100644
--- a/tests/test_manifest_strands.py
+++ b/tests/test_manifest_strands.py
@@ -349,52 +349,3 @@ def test_error_raised_if_multiple_datasets_have_same_name(self):
 
         with self.assertRaises(KeyError):
             twine.validate_input_manifest(source=input_manifest)
-
-    def test_deprecation_warning_issued_and_datasets_format_translated_if_datasets_given_as_list(self):
-        """Test that, if datasets are given as a list (the old format), a deprecation warning is issued and the list
-        is translated to a dictionary (the new format).
-        """
-        twine = """
-            {
-                "input_manifest": {
-                    "datasets": {
-                        "met_mast_data": {
-                            "purpose": "A dataset containing meteorological mast data"
-                        }
-                    }
-                }
-            }
-        """
-
-        input_manifest = """
-            {
-                "id": "8ead7669-8162-4f64-8cd5-4abe92509e17",
-                "datasets": [
-                    {
-                        "id": "7ead7669-8162-4f64-8cd5-4abe92509e19",
-                        "name": "met_mast_data",
-                        "tags": {},
-                        "labels": [],
-                        "files": []
-                    }
-                ]
-            }
-        """
-
-        twine = Twine(source=twine)
-
-        with self.assertWarns(DeprecationWarning):
-            manifest = twine.validate_input_manifest(source=input_manifest)
-
-        self.assertEqual(
-            manifest["datasets"],
-            {
-                "met_mast_data": {
-                    "id": "7ead7669-8162-4f64-8cd5-4abe92509e19",
-                    "name": "met_mast_data",
-                    "tags": {},
-                    "labels": [],
-                    "files": [],
-                }
-            },
-        )
diff --git a/tests/test_twine.py b/tests/test_twine.py
index a347db9..46b147c 100644
--- a/tests/test_twine.py
+++ b/tests/test_twine.py
@@ -1,6 +1,6 @@
 import os
 
-from twined import MANIFEST_STRANDS, Twine, exceptions
+from twined import Twine, exceptions
 from .base import BaseTestCase
 
 
@@ -123,38 +123,3 @@ def test_available_strands_properties(self):
         )
 
         self.assertEqual(twine.available_manifest_strands, {"output_manifest"})
-
-    def test_deprecation_warning_issued_if_datasets_not_given_as_dictionary_in_manifest_strands(self):
-        """Test that, if datasets are given as a list in the manifest strands, a deprecation warning is issued and the
-        list (the old form) is converted to a dictionary (the new form).
-        """
-        for manifest_strand in MANIFEST_STRANDS:
-            with self.subTest(manifest_strand=manifest_strand):
-                invalid_twine = (
-                    """
-                {
-                    "%s": {
-                        "datasets": [
-                            {
-                                "key": "met_mast_data",
-                                "purpose": "A dataset containing meteorological mast data"
-                            }
-                        ]
-                    }
-                }
-                """
-                    % manifest_strand
-                )
-
-                with self.assertWarns(DeprecationWarning):
-                    twine = Twine(source=invalid_twine)
-
-                self.assertEqual(
-                    getattr(twine, manifest_strand)["datasets"],
-                    {
-                        "met_mast_data": {
-                            "key": "met_mast_data",
-                            "purpose": "A dataset containing meteorological mast data",
-                        }
-                    },
-                )
diff --git a/twined/migrations/__init__.py b/twined/migrations/__init__.py
index e69de29..f626db9 100644
--- a/twined/migrations/__init__.py
+++ b/twined/migrations/__init__.py
@@ -0,0 +1,3 @@
+"""A subpackage containing any translations from deprecated code to new code for deprecations that haven't been phased
+out yet. See https://github.com/octue/twined/issues/102.
+"""
diff --git a/twined/migrations/manifest.py b/twined/migrations/manifest.py
deleted file mode 100644
index 5722c01..0000000
--- a/twined/migrations/manifest.py
+++ /dev/null
@@ -1,23 +0,0 @@
-import warnings
-
-
-def convert_dataset_list_to_dictionary(datasets):
-    """Convert a list of datasets into a dictionary of datasets.
-
-    :param list datasets:
-    :return dict:
-    """
-    converted_datasets = {}
-
-    for i, dataset in enumerate(datasets):
-        converted_datasets[dataset.get("name", f"dataset_{i}")] = dataset
-
-    warnings.warn(
-        message=(
-            "Datasets belonging to a manifest should be provided as a dictionary mapping their name to "
-            "themselves. Support for providing a list of datasets will be phased out soon."
-        ),
-        category=DeprecationWarning,
-    )
-
-    return converted_datasets
diff --git a/twined/migrations/twine.py b/twined/migrations/twine.py
deleted file mode 100644
index 912c536..0000000
--- a/twined/migrations/twine.py
+++ /dev/null
@@ -1,22 +0,0 @@
-import warnings
-
-
-def convert_manifest_datasets_from_list_to_dictionary(datasets, strand):
-    """Convert the list of datasets in a manifest strand into a dictionary.
-
-    :param list datasets:
-    :param str strand:
-    :return dict:
-    """
-    datasets = {dataset["key"]: dataset for dataset in datasets}
-
-    warnings.warn(
-        message=(
-            f"Datasets in the {strand!r} strand of the `twine.json` file should be provided as a "
-            "dictionary mapping their name to themselves. Support for providing a list of datasets will be "
-            "phased out soon."
-        ),
-        category=DeprecationWarning,
-    )
-
-    return datasets
diff --git a/twined/twine.py b/twined/twine.py
index be4d143..ae0236c 100644
--- a/twined/twine.py
+++ b/twined/twine.py
@@ -5,8 +5,6 @@
 from dotenv import load_dotenv
 from jsonschema import ValidationError, validate as jsonschema_validate
 
-import twined.migrations.manifest as manifest_migrations
-import twined.migrations.twine as twine_migrations
 from . import exceptions
 from .utils import load_json, trim_suffix
 
@@ -60,13 +58,6 @@ def _load_twine(self, source=None):
         else:
             raw_twine = self._load_json("twine", source, allowed_kinds=("file-like", "filename", "string", "object"))
 
-        for strand in set(MANIFEST_STRANDS) & raw_twine.keys():
-            if isinstance(raw_twine[strand]["datasets"], list):
-                raw_twine[strand]["datasets"] = twine_migrations.convert_manifest_datasets_from_list_to_dictionary(
-                    datasets=raw_twine[strand]["datasets"],
-                    strand=strand,
-                )
-
         self._validate_against_schema("twine", raw_twine)
         self._validate_twine_version(twine_file_twined_version=raw_twine.get("twined_version", None))
         return raw_twine
@@ -179,9 +170,6 @@ def _validate_manifest(self, kind, source, cls=None, **kwargs):
             inbound = False
             data = data.to_primitive()
 
-        if isinstance(data["datasets"], list):
-            data["datasets"] = manifest_migrations.convert_dataset_list_to_dictionary(data["datasets"])
-
         self._validate_against_schema(kind, data)
         self._validate_all_expected_datasets_are_present_in_manifest(manifest_kind=kind, manifest=data)