From 70a2de4e1234372f81b343bd57092d511fff04f1 Mon Sep 17 00:00:00 2001 From: Min RK Date: Thu, 23 Mar 2023 16:00:23 +0100 Subject: [PATCH] @lru_cache requires Python 3.8, use older @lru_cache() --- repo2docker/buildpacks/base.py | 38 +++++++++---------- repo2docker/buildpacks/conda/__init__.py | 18 ++++----- repo2docker/buildpacks/julia/julia_project.py | 10 ++--- repo2docker/buildpacks/julia/julia_require.py | 10 ++--- repo2docker/buildpacks/nix/__init__.py | 12 +++--- repo2docker/buildpacks/pipfile/__init__.py | 6 +-- repo2docker/buildpacks/python/__init__.py | 6 +-- repo2docker/buildpacks/r.py | 24 ++++++------ 8 files changed, 62 insertions(+), 62 deletions(-) diff --git a/repo2docker/buildpacks/base.py b/repo2docker/buildpacks/base.py index 9afabf7e..62f94e87 100644 --- a/repo2docker/buildpacks/base.py +++ b/repo2docker/buildpacks/base.py @@ -232,7 +232,7 @@ class BuildPack: ) self.platform = "" - @lru_cache + @lru_cache() def get_packages(self): """ List of packages that are installed in this BuildPack. @@ -242,7 +242,7 @@ class BuildPack: """ return set() - @lru_cache + @lru_cache() def get_base_packages(self): """ Base set of apt packages that are installed for all images. @@ -259,7 +259,7 @@ class BuildPack: "unzip", } - @lru_cache + @lru_cache() def get_build_env(self): """ Ordered list of environment variables to be set for this image. @@ -275,7 +275,7 @@ class BuildPack: """ return [] - @lru_cache + @lru_cache() def get_env(self): """ Ordered list of environment variables to be set for this image. @@ -290,7 +290,7 @@ class BuildPack: """ return [] - @lru_cache + @lru_cache() def get_path(self): """ Ordered list of file system paths to look for executables in. @@ -300,14 +300,14 @@ class BuildPack: """ return [] - @lru_cache + @lru_cache() def get_labels(self): """ Docker labels to set on the built image. """ return self.labels - @lru_cache + @lru_cache() def get_build_script_files(self): """ Dict of files to be copied to the container image for use in building. @@ -332,7 +332,7 @@ class BuildPack: f"Found a stencila manifest.xml at {root}. Stencila is no longer supported." ) - @lru_cache + @lru_cache() def get_build_scripts(self): """ Ordered list of shell script snippets to build the base image. @@ -354,7 +354,7 @@ class BuildPack: return [] - @lru_cache + @lru_cache() def get_preassemble_script_files(self): """ Dict of files to be copied to the container image for use in preassembly. @@ -368,7 +368,7 @@ class BuildPack: """ return {} - @lru_cache + @lru_cache() def get_preassemble_scripts(self): """ Ordered list of shell snippets to build an image for this repository. @@ -385,7 +385,7 @@ class BuildPack: """ return [] - @lru_cache + @lru_cache() def get_assemble_scripts(self): """ Ordered list of shell script snippets to build the repo into the image. @@ -412,7 +412,7 @@ class BuildPack: """ return [] - @lru_cache + @lru_cache() def get_post_build_scripts(self): """ An ordered list of executable scripts to execute after build. @@ -425,7 +425,7 @@ class BuildPack: """ return [] - @lru_cache + @lru_cache() def get_start_script(self): """ The path to a script to be executed at container start up. @@ -638,14 +638,14 @@ class BuildPack: class BaseImage(BuildPack): - @lru_cache + @lru_cache() def get_build_env(self): """Return env directives required for build""" return [ ("APP_BASE", "/srv"), ] - @lru_cache + @lru_cache() def get_env(self): """Return env directives to be set after build""" return [] @@ -653,7 +653,7 @@ class BaseImage(BuildPack): def detect(self): return True - @lru_cache + @lru_cache() def get_preassemble_scripts(self): scripts = [] try: @@ -693,19 +693,19 @@ class BaseImage(BuildPack): return scripts - @lru_cache + @lru_cache() def get_assemble_scripts(self): """Return directives to run after the entire repository has been added to the image""" return [] - @lru_cache + @lru_cache() def get_post_build_scripts(self): post_build = self.binder_path("postBuild") if os.path.exists(post_build): return [post_build] return [] - @lru_cache + @lru_cache() def get_start_script(self): start = self.binder_path("start") if os.path.exists(start): diff --git a/repo2docker/buildpacks/conda/__init__.py b/repo2docker/buildpacks/conda/__init__.py index 7dc24481..f4791f12 100644 --- a/repo2docker/buildpacks/conda/__init__.py +++ b/repo2docker/buildpacks/conda/__init__.py @@ -46,7 +46,7 @@ class CondaBuildPack(BaseImage): return "linux-aarch64" raise ValueError(f"Unknown platform {self.platform}") - @lru_cache + @lru_cache() def get_build_env(self): """Return environment variables to be set. @@ -90,13 +90,13 @@ class CondaBuildPack(BaseImage): env.append(("KERNEL_PYTHON_PREFIX", "${NB_PYTHON_PREFIX}")) return env - @lru_cache + @lru_cache() def get_env(self): """Make kernel env the default for `conda install`""" env = super().get_env() + [("CONDA_DEFAULT_ENV", "${KERNEL_PYTHON_PREFIX}")] return env - @lru_cache + @lru_cache() def get_path(self): """Return paths (including conda environment path) to be added to the PATH environment variable. @@ -111,7 +111,7 @@ class CondaBuildPack(BaseImage): path.append("${NPM_DIR}/bin") return path - @lru_cache + @lru_cache() def get_build_scripts(self): """ Return series of build-steps common to all Python 3 repositories. @@ -150,7 +150,7 @@ class CondaBuildPack(BaseImage): major_pythons = {"2": "2.7", "3": "3.7"} - @lru_cache + @lru_cache() def get_build_script_files(self): """ Dict of files to be copied to the container image for use in building. @@ -365,7 +365,7 @@ class CondaBuildPack(BaseImage): self.kernel_env_cutoff_version ) - @lru_cache + @lru_cache() def get_preassemble_script_files(self): """preassembly only requires environment.yml @@ -379,7 +379,7 @@ class CondaBuildPack(BaseImage): assemble_files[environment_yml] = environment_yml return assemble_files - @lru_cache + @lru_cache() def get_env_scripts(self): """Return series of build-steps specific to this source repository.""" scripts = [] @@ -446,14 +446,14 @@ class CondaBuildPack(BaseImage): ] return scripts - @lru_cache + @lru_cache() def get_preassemble_scripts(self): scripts = super().get_preassemble_scripts() if self._should_preassemble_env: scripts.extend(self.get_env_scripts()) return scripts - @lru_cache + @lru_cache() def get_assemble_scripts(self): scripts = super().get_assemble_scripts() if not self._should_preassemble_env: diff --git a/repo2docker/buildpacks/julia/julia_project.py b/repo2docker/buildpacks/julia/julia_project.py index c9f72a1e..cce56abf 100644 --- a/repo2docker/buildpacks/julia/julia_project.py +++ b/repo2docker/buildpacks/julia/julia_project.py @@ -68,7 +68,7 @@ class JuliaProjectTomlBuildPack(PythonBuildPack): raise RuntimeError("Failed to find a matching Julia version: {compat}") return match - @lru_cache + @lru_cache() def get_build_env(self): """Get additional environment settings for Julia and Jupyter @@ -111,11 +111,11 @@ class JuliaProjectTomlBuildPack(PythonBuildPack): else: return "${REPO_DIR}" - @lru_cache + @lru_cache() def get_env(self): return super().get_env() + [("JULIA_PROJECT", self.project_dir)] - @lru_cache + @lru_cache() def get_path(self): """Adds path to Julia binaries to user's PATH. @@ -126,7 +126,7 @@ class JuliaProjectTomlBuildPack(PythonBuildPack): """ return super().get_path() + ["${JULIA_PATH}/bin"] - @lru_cache + @lru_cache() def get_build_scripts(self): """ Return series of build-steps common to "ALL" Julia repositories @@ -155,7 +155,7 @@ class JuliaProjectTomlBuildPack(PythonBuildPack): ), ] - @lru_cache + @lru_cache() def get_assemble_scripts(self): """ Return series of build-steps specific to "this" Julia repository diff --git a/repo2docker/buildpacks/julia/julia_require.py b/repo2docker/buildpacks/julia/julia_require.py index 10046800..ab41ffc2 100644 --- a/repo2docker/buildpacks/julia/julia_require.py +++ b/repo2docker/buildpacks/julia/julia_require.py @@ -55,7 +55,7 @@ class JuliaRequireBuildPack(PythonBuildPack): self._julia_version = julia_version return self._julia_version - @lru_cache + @lru_cache() def get_build_env(self): """Get additional environment settings for Julia and Jupyter @@ -104,7 +104,7 @@ class JuliaRequireBuildPack(PythonBuildPack): ("JUPYTER", jupyter), ] - @lru_cache + @lru_cache() def get_path(self): """Adds path to Julia binaries to user's PATH. @@ -115,7 +115,7 @@ class JuliaRequireBuildPack(PythonBuildPack): """ return super().get_path() + ["${JULIA_HOME}"] - @lru_cache + @lru_cache() def get_build_scripts(self): """ Return series of build-steps common to "ALL" Julia repositories @@ -153,7 +153,7 @@ class JuliaRequireBuildPack(PythonBuildPack): ), ] - @lru_cache + @lru_cache() def get_assemble_scripts(self): """ Return series of build-steps specific to "this" Julia repository @@ -181,7 +181,7 @@ class JuliaRequireBuildPack(PythonBuildPack): ) ] - @lru_cache + @lru_cache() def get_build_script_files(self): files = { "julia/install-repo-dependencies.jl": "/tmp/install-repo-dependencies.jl" diff --git a/repo2docker/buildpacks/nix/__init__.py b/repo2docker/buildpacks/nix/__init__.py index 93b6c6fc..94fd7b7c 100644 --- a/repo2docker/buildpacks/nix/__init__.py +++ b/repo2docker/buildpacks/nix/__init__.py @@ -8,12 +8,12 @@ from ..base import BaseImage class NixBuildPack(BaseImage): """A nix Package Manager BuildPack""" - @lru_cache + @lru_cache() def get_path(self): """Return paths to be added to PATH environemnt variable""" return super().get_path() + ["/home/${NB_USER}/.nix-profile/bin"] - @lru_cache + @lru_cache() def get_env(self): """Ordered list of environment variables to be set for this image""" @@ -23,7 +23,7 @@ class NixBuildPack(BaseImage): ("GIT_SSL_CAINFO", "/etc/ssl/certs/ca-certificates.crt"), ] - @lru_cache + @lru_cache() def get_build_scripts(self): """ Return series of build-steps common to all nix repositories. @@ -59,7 +59,7 @@ class NixBuildPack(BaseImage): ), ] - @lru_cache + @lru_cache() def get_build_script_files(self): """Dict of files to be copied to the container image for use in building""" return { @@ -67,7 +67,7 @@ class NixBuildPack(BaseImage): "nix/nix-shell-wrapper": "/usr/local/bin/nix-shell-wrapper", } - @lru_cache + @lru_cache() def get_assemble_scripts(self): """Return series of build-steps specific to this source repository.""" return super().get_assemble_scripts() + [ @@ -81,7 +81,7 @@ class NixBuildPack(BaseImage): ) ] - @lru_cache + @lru_cache() def get_start_script(self): """The path to a script to be executed as ENTRYPOINT""" # the shell wrapper script duplicates the behaviour of other buildpacks diff --git a/repo2docker/buildpacks/pipfile/__init__.py b/repo2docker/buildpacks/pipfile/__init__.py index 29ba6ef3..5a99f49d 100644 --- a/repo2docker/buildpacks/pipfile/__init__.py +++ b/repo2docker/buildpacks/pipfile/__init__.py @@ -76,7 +76,7 @@ class PipfileBuildPack(CondaBuildPack): self._python_version = self.major_pythons["3"] return self._python_version - @lru_cache + @lru_cache() def get_preassemble_script_files(self): """Return files needed for preassembly""" files = super().get_preassemble_script_files() @@ -86,7 +86,7 @@ class PipfileBuildPack(CondaBuildPack): files[path] = path return files - @lru_cache + @lru_cache() def get_preassemble_scripts(self): """scripts to run prior to staging the repo contents""" scripts = super().get_preassemble_scripts() @@ -104,7 +104,7 @@ class PipfileBuildPack(CondaBuildPack): ) return scripts - @lru_cache + @lru_cache() def get_assemble_scripts(self): """Return series of build-steps specific to this repository.""" # If we have either Pipfile.lock, Pipfile, or runtime.txt declare the diff --git a/repo2docker/buildpacks/python/__init__.py b/repo2docker/buildpacks/python/__init__.py index 89a78375..32986cff 100644 --- a/repo2docker/buildpacks/python/__init__.py +++ b/repo2docker/buildpacks/python/__init__.py @@ -94,7 +94,7 @@ class PythonBuildPack(CondaBuildPack): # allow assembly from subset return True - @lru_cache + @lru_cache() def get_preassemble_script_files(self): assemble_files = super().get_preassemble_script_files() for name in ("requirements.txt", "requirements3.txt"): @@ -103,7 +103,7 @@ class PythonBuildPack(CondaBuildPack): assemble_files[requirements_txt] = requirements_txt return assemble_files - @lru_cache + @lru_cache() def get_preassemble_scripts(self): """Return scripts to run before adding the full repository""" scripts = super().get_preassemble_scripts() @@ -111,7 +111,7 @@ class PythonBuildPack(CondaBuildPack): scripts.extend(self._get_pip_scripts()) return scripts - @lru_cache + @lru_cache() def get_assemble_scripts(self): """Return series of build steps that require the full repository""" # If we have a runtime.txt & that's set to python-2.7, diff --git a/repo2docker/buildpacks/r.py b/repo2docker/buildpacks/r.py index a3c8bade..03aa4ae6 100644 --- a/repo2docker/buildpacks/r.py +++ b/repo2docker/buildpacks/r.py @@ -143,7 +143,7 @@ class RBuildPack(PythonBuildPack): self._runtime = f"r-{str(self._checkpoint_date)}" return True - @lru_cache + @lru_cache() def get_env(self): """ Set custom env vars needed for RStudio to load @@ -158,7 +158,7 @@ class RBuildPack(PythonBuildPack): ("LD_LIBRARY_PATH", "${R_HOME}/lib:${LD_LIBRARY_PATH}"), ] - @lru_cache + @lru_cache() def get_path(self): """ Return paths to be added to the PATH environment variable. @@ -168,7 +168,7 @@ class RBuildPack(PythonBuildPack): """ return super().get_path() + ["/usr/lib/rstudio-server/bin/"] - @lru_cache + @lru_cache() def get_build_env(self): """ Return environment variables to be set. @@ -182,7 +182,7 @@ class RBuildPack(PythonBuildPack): ("R_LIBS_USER", "${APP_BASE}/rlibs") ] - @lru_cache + @lru_cache() def get_packages(self): """ Return list of packages to be installed. @@ -200,7 +200,7 @@ class RBuildPack(PythonBuildPack): return super().get_packages().union(packages) - @lru_cache + @lru_cache() def get_rspm_snapshot_url(self, snapshot_date, max_days_prior=7): for i in range(max_days_prior): snapshots = requests.post( @@ -225,7 +225,7 @@ class RBuildPack(PythonBuildPack): ) ) - @lru_cache + @lru_cache() def get_mran_snapshot_url(self, snapshot_date, max_days_prior=7): for i in range(max_days_prior): try_date = snapshot_date - datetime.timedelta(days=i) @@ -240,7 +240,7 @@ class RBuildPack(PythonBuildPack): ) ) - @lru_cache + @lru_cache() def get_cran_mirror_url(self, snapshot_date): # Date after which we will use rspm + binary packages instead of MRAN + source packages rspm_cutoff_date = datetime.date(2022, 1, 1) @@ -250,7 +250,7 @@ class RBuildPack(PythonBuildPack): else: return self.get_mran_snapshot_url(snapshot_date) - @lru_cache + @lru_cache() def get_devtools_snapshot_url(self): """ Return url of snapshot to use for getting devtools install @@ -264,7 +264,7 @@ class RBuildPack(PythonBuildPack): # necessary apt packages. return "https://packagemanager.rstudio.com/all/__linux__/bionic/2022-01-04+Y3JhbiwyOjQ1MjYyMTU7NzlBRkJEMzg" - @lru_cache + @lru_cache() def get_build_scripts(self): """ Return series of build-steps common to all R repositories @@ -359,7 +359,7 @@ class RBuildPack(PythonBuildPack): return super().get_build_scripts() + scripts - @lru_cache + @lru_cache() def get_preassemble_script_files(self): files = super().get_preassemble_script_files() installR_path = self.binder_path("install.R") @@ -368,7 +368,7 @@ class RBuildPack(PythonBuildPack): return files - @lru_cache + @lru_cache() def get_preassemble_scripts(self): """Install contents of install.R @@ -394,7 +394,7 @@ class RBuildPack(PythonBuildPack): return super().get_preassemble_scripts() + scripts - @lru_cache + @lru_cache() def get_assemble_scripts(self): """Install the dependencies of or the repository itself""" assemble_scripts = super().get_assemble_scripts()