Skip to content

Commit

Permalink
Merge pull request #163 from datalad/gh-162
Browse files Browse the repository at this point in the history
dpkg-based methods now raise MethodNotSupportedError when called on non-dpkg systems without `--install-dir`
  • Loading branch information
yarikoptic authored May 16, 2023
2 parents 74ff6a0 + d308dd1 commit 55d823c
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions src/datalad_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ def install(self, component: str, **kwargs: Any) -> List[InstalledCommand]:
not support installing the given component. Returns a list of
(command, Path) pairs for each installed program.
"""
self.assert_supported_system()
self.assert_supported_system(**kwargs)
try:
package, commands = self.PACKAGES[component]
except KeyError:
Expand All @@ -1401,7 +1401,7 @@ def install_package(self, package: str, **kwargs: Any) -> Path:
...

@abstractmethod
def assert_supported_system(self) -> None:
def assert_supported_system(self, **kwargs: Any) -> None:
"""
If the installation method is not supported by the current system,
raises `MethodNotSupportedError`; otherwise, does nothing.
Expand Down Expand Up @@ -1472,7 +1472,7 @@ def install_package(
log.debug("Installed program directory: /usr/bin")
return Path("/usr/bin")

def assert_supported_system(self) -> None:
def assert_supported_system(self, **_kwargs: Any) -> None:
if shutil.which("apt-get") is None:
raise MethodNotSupportedError("apt-get command not found")

Expand Down Expand Up @@ -1530,7 +1530,7 @@ def install_package(
log.debug("Installed program directory: /usr/local/bin")
return Path("/usr/local/bin")

def assert_supported_system(self) -> None:
def assert_supported_system(self, **_kwargs: Any) -> None:
if shutil.which("brew") is None:
raise MethodNotSupportedError("brew command not found")

Expand Down Expand Up @@ -1632,7 +1632,7 @@ def install_package(
log.debug("Installed program directory: %s", binpath)
return binpath

def assert_supported_system(self) -> None:
def assert_supported_system(self, **_kwargs: Any) -> None:
### TODO: Detect whether pip is installed in the current Python,
### preferably without importing it
pass
Expand All @@ -1648,8 +1648,8 @@ class NeurodebianInstaller(AptInstaller):
"git-annex": ("git-annex-standalone", [GIT_ANNEX_CMD]),
}

def assert_supported_system(self) -> None:
super().assert_supported_system()
def assert_supported_system(self, **kwargs: Any) -> None:
super().assert_supported_system(**kwargs)
if "l=NeuroDebian" not in readcmd("apt-cache", "policy"):
raise MethodNotSupportedError("Neurodebian not configured")

Expand Down Expand Up @@ -1723,9 +1723,11 @@ def install_package(
log.debug("Installed program directory: %s", binpath)
return binpath

def assert_supported_system(self) -> None:
if shutil.which("dpkg") is None:
raise MethodNotSupportedError("dpkg command not found")
def assert_supported_system(self, **kwargs: Any) -> None:
if kwargs.get("install_dir") is None and shutil.which("dpkg") is None:
raise MethodNotSupportedError(
"Non-dpkg-based systems not supported unless --install-dir is given"
)


class AutobuildSnapshotInstaller(Installer):
Expand Down Expand Up @@ -1758,7 +1760,7 @@ def _install_macos(self, path: str) -> Path:
)
return install_git_annex_dmg(dmgpath, self.manager)

def assert_supported_system(self) -> None:
def assert_supported_system(self, **_kwargs: Any) -> None:
if not ON_POSIX:
raise MethodNotSupportedError(f"{SYSTEM} OS not supported")

Expand Down Expand Up @@ -1888,7 +1890,7 @@ def install_package(
log.debug("Installed program directory: %s", binpath)
return binpath

def assert_supported_system(self) -> None:
def assert_supported_system(self, **_kwargs: Any) -> None:
if not self.manager.conda_stack and shutil.which("conda") is None:
raise MethodNotSupportedError("Conda installation not found")

Expand Down Expand Up @@ -1970,9 +1972,17 @@ def install_package(
log.debug("Installed program directory: %s", binpath)
return binpath

def assert_supported_system(self) -> None:
def assert_supported_system(self, **kwargs: Any) -> None:
if not (ON_LINUX or ON_MACOS or ON_WINDOWS):
raise MethodNotSupportedError(f"{SYSTEM} OS not supported")
elif (
ON_LINUX
and kwargs.get("install_dir") is None
and shutil.which("dpkg") is None
):
raise MethodNotSupportedError(
"Non-dpkg-based systems not supported unless --install-dir is given"
)

@staticmethod
def download(
Expand Down Expand Up @@ -2118,8 +2128,17 @@ def install_package(
log.debug("Installed program directory: %s", binpath)
return binpath

def assert_supported_system(self) -> None:
pass
def assert_supported_system(self, **kwargs: Any) -> None:
if not (ON_LINUX or ON_MACOS or ON_WINDOWS):
raise MethodNotSupportedError(f"{SYSTEM} OS not supported")
elif (
ON_LINUX
and kwargs.get("install_dir") is None
and shutil.which("dpkg") is None
):
raise MethodNotSupportedError(
"Non-dpkg-based systems not supported unless --install-dir is given"
)


@GitAnnexComponent.register_installer
Expand Down Expand Up @@ -2157,7 +2176,7 @@ def install_package(
log.debug("Installed program directory: %s", binpath)
return binpath

def assert_supported_system(self) -> None:
def assert_supported_system(self, **_kwargs: Any) -> None:
if not ON_MACOS:
raise MethodNotSupportedError(f"{SYSTEM} OS not supported")

Expand Down Expand Up @@ -2217,7 +2236,7 @@ def install_package(
log.debug("Installed program directory: %s", bin_dir)
return bin_dir

def assert_supported_system(self) -> None:
def assert_supported_system(self, **_kwargs: Any) -> None:
if not ON_POSIX:
raise MethodNotSupportedError(f"{SYSTEM} OS not supported")

Expand Down Expand Up @@ -2317,7 +2336,7 @@ def install_package(
self.manager.addpath(bin_dir)
return bin_dir

def assert_supported_system(self) -> None:
def assert_supported_system(self, **_kwargs: Any) -> None:
pass


Expand Down

0 comments on commit 55d823c

Please sign in to comment.