From ad7bd02107d2726df590425f1c8d29a67b610ed3 Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Tue, 31 Oct 2023 23:40:40 +0100 Subject: [PATCH 1/6] Switch to upstream ruamel.yaml package Avoid usage of deprecated top-level ruamel.yaml load/dump functions. Those have been removed in ruamel.yaml>=0.18 . Signed-off-by: Marcel Bargull --- anaconda_project/env_spec.py | 9 ++++----- anaconda_project/yaml_file.py | 35 +++++++++++++++++------------------ conda.recipe/meta.yaml | 2 +- environment.yml | 2 +- setup.py | 2 +- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/anaconda_project/env_spec.py b/anaconda_project/env_spec.py index aaff7b8b..f78fdacb 100644 --- a/anaconda_project/env_spec.py +++ b/anaconda_project/env_spec.py @@ -19,7 +19,7 @@ from anaconda_project.internal.py2_compat import is_string from anaconda_project import conda_manager -from anaconda_project.yaml_file import _load_string, _save_file, _YAMLError, ryaml +from anaconda_project.yaml_file import _load_string, _save_file, _YAMLError class EnvSpec(object): @@ -402,12 +402,11 @@ def to_json(self): channels = list(self._channels) platforms = list(self._platforms) - # this is a gross, roundabout hack to get ryaml dicts that + # this is a gross, roundabout hack to get ruamel.yaml dicts that # have ordering... OrderedDict doesn't work because the # yaml saver saves them as some "!!omap" nonsense. Other # than ordering, the formatting isn't even preserved here. - template_json = ryaml.load("something:\n description: null\n" + " packages: []\n" + " channels: []\n", - Loader=ryaml.RoundTripLoader) + template_json = _load_string("something:\n description: null\n" + " packages: []\n" + " channels: []\n") if self._description is not None: template_json['something']['description'] = self._description @@ -474,7 +473,7 @@ def save_environment_yml(self, filename): packages.append(dict(pip=pip_packages)) channels = list(self.channels) - yaml = ryaml.load("name: " "\ndependencies: []\nchannels: []\n", Loader=ryaml.RoundTripLoader) + yaml = _load_string("name: " "\ndependencies: []\nchannels: []\n") assert self.name is not None # the global anonymous spec can't be saved yaml['name'] = self.name diff --git a/anaconda_project/yaml_file.py b/anaconda_project/yaml_file.py index 4736f34a..cb01046d 100644 --- a/anaconda_project/yaml_file.py +++ b/anaconda_project/yaml_file.py @@ -12,22 +12,15 @@ # comments, etc., which is why we use it instead of the usual yaml # module. Remember the project file is intended to go into source # control. -try: - # this is the conda-packaged version of ruamel.yaml which has the - # module renamed - import ruamel_yaml as ryaml - from ruamel_yaml.error import YAMLError - from ruamel_yaml.comments import CommentedMap - from ruamel_yaml.comments import CommentedSeq -except ImportError: # pragma: no cover - # this is the upstream version - import ruamel.yaml as ryaml # pragma: no cover - from ruamel.yaml.error import YAMLError # pragma: no cover - from ruamel.yaml.comments import CommentedMap # pragma: no cover - from ruamel.yaml.comments import CommentedSeq # pragma: no cover +import ruamel.yaml +import ruamel.yaml.constructor +from ruamel.yaml.error import YAMLError # pragma: no cover +from ruamel.yaml.comments import CommentedMap # pragma: no cover +from ruamel.yaml.comments import CommentedSeq # pragma: no cover import codecs import errno +import io import os import sys import uuid @@ -57,20 +50,26 @@ def _atomic_replace(path, contents, encoding='utf-8'): pass +def _get_yaml(): + return ruamel.yaml.YAML(typ="rt") + + def _load_string(contents): if contents.strip() == '': - # ryaml.load below returns None for an empty file, we want + # YAML.load below returns None for an empty file, we want # to return an empty dict instead. return {} else: # using RoundTripLoader incorporates safe_load # (we don't load code) - assert issubclass(ryaml.RoundTripLoader, ryaml.constructor.SafeConstructor) - return ryaml.load(contents, Loader=ryaml.RoundTripLoader) + assert issubclass(ruamel.yaml.RoundTripLoader, ruamel.yaml.constructor.SafeConstructor) + return _get_yaml().load(contents) def _dump_string(yaml): - return ryaml.dump(yaml, Dumper=ryaml.RoundTripDumper) + stream = io.StringIO() + _get_yaml().dump(yaml, stream=stream) + return stream.getvalue() def _save_file(yaml, filename, contents=None): @@ -79,7 +78,7 @@ def _save_file(yaml, filename, contents=None): try: # This is to ensure we don't corrupt the file, even if ruamel.yaml is broken - ryaml.load(contents, Loader=ryaml.RoundTripLoader) + _get_yaml().load(contents) except YAMLError as e: # pragma: no cover (should not happen) print("ruamel.yaml bug; it failed to parse a file that it generated.", file=sys.stderr) print(" the parse error was: " + str(e), file=sys.stderr) diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index ad837bc1..9c7751de 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -26,7 +26,7 @@ requirements: - conda-pack - python - requests - - ruamel_yaml + - ruamel.yaml - tornado >=4.2 - jinja2 - tqdm diff --git a/environment.yml b/environment.yml index 05feb49d..c3447d2d 100644 --- a/environment.yml +++ b/environment.yml @@ -7,7 +7,7 @@ channels: dependencies: - redis - notebook - - ruamel_yaml + - ruamel.yaml - anaconda-client - conda-pack - requests diff --git a/setup.py b/setup.py index a5c7a360..b71c935b 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ "anaconda-client", "conda-pack", "requests", - "ruamel_yaml", + "ruamel.yaml", "tornado>=4.2", "jinja2", "tqdm", From c783f8729e463eea7b760d0941a4962826055d52 Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Fri, 3 Nov 2023 12:43:52 +0100 Subject: [PATCH 2/6] Use an older setup-miniconda action to fix CI ref: https://github.com/conda-incubator/setup-miniconda/issues/261 Signed-off-by: Marcel Bargull --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 946b6da8..143b9ee5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 - - uses: conda-incubator/setup-miniconda@v2 + - uses: conda-incubator/setup-miniconda@v2.1.1 with: auto-update-conda: false miniconda-version: py37_4.10.3 From 8cadf3409efc60bb5fbd6d1af280835746a9eb52 Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Fri, 3 Nov 2023 14:11:29 +0100 Subject: [PATCH 3/6] Fix formatting from yapf lint error Signed-off-by: Marcel Bargull --- anaconda_project/env_spec.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/anaconda_project/env_spec.py b/anaconda_project/env_spec.py index f78fdacb..0ee35b0a 100644 --- a/anaconda_project/env_spec.py +++ b/anaconda_project/env_spec.py @@ -406,7 +406,8 @@ def to_json(self): # have ordering... OrderedDict doesn't work because the # yaml saver saves them as some "!!omap" nonsense. Other # than ordering, the formatting isn't even preserved here. - template_json = _load_string("something:\n description: null\n" + " packages: []\n" + " channels: []\n") + template_json = _load_string("something:\n description: null\n" + " packages: []\n" + + " channels: []\n") if self._description is not None: template_json['something']['description'] = self._description From e73312022e55c9fa37667f7e4ba6d5dbca65eb0e Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Mon, 20 Nov 2023 19:55:13 +0100 Subject: [PATCH 4/6] Use latest Miniconda for CI setup Signed-off-by: Marcel Bargull --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 143b9ee5..d6ad4845 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,10 +16,9 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 - - uses: conda-incubator/setup-miniconda@v2.1.1 + - uses: conda-incubator/setup-miniconda@v2 with: auto-update-conda: false - miniconda-version: py37_4.10.3 auto-activate-base: true activate-environment: "" - name: Install build dependencies From 0096f7aab1d28b2d6caf744fb7f65db3290c95ee Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Tue, 21 Nov 2023 00:47:20 +0100 Subject: [PATCH 5/6] Fix unrelated lint reported by flake8 Signed-off-by: Marcel Bargull --- anaconda_project/internal/test/test_streaming_popen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anaconda_project/internal/test/test_streaming_popen.py b/anaconda_project/internal/test/test_streaming_popen.py index 0ad26d67..57e4492f 100644 --- a/anaconda_project/internal/test/test_streaming_popen.py +++ b/anaconda_project/internal/test/test_streaming_popen.py @@ -25,7 +25,7 @@ def detect_linesep(lines): def add_lineseps(lines, sep=None): sep = sep or os.linesep - return list(map(lambda l: l + sep, lines)) + return [line + sep for line in lines] def test_streaming(): From 912ce499537bd49c302a7bb1fc5f5b558ade7b62 Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Tue, 21 Nov 2023 15:52:17 +0100 Subject: [PATCH 6/6] Update Miniconda path for artifact upload Signed-off-by: Marcel Bargull --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d6ad4845..de0db998 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,7 +52,7 @@ jobs: uses: actions/upload-artifact@v2 with: name: package-${{ github.sha }} - path: /usr/share/miniconda3/conda-bld + path: /usr/share/miniconda/conda-bld tests: defaults: run: