Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[r-apt] "installBspm": true is not working on Debian #173

Closed
eitsupi opened this issue Aug 9, 2023 · 12 comments
Closed

[r-apt] "installBspm": true is not working on Debian #173

eitsupi opened this issue Aug 9, 2023 · 12 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@eitsupi
Copy link
Member

eitsupi commented Aug 9, 2023

I have confirmed that install.packages("curl") fails on R started by a non-root user (vscode) on an image built from devcontainer.json as shown below.

{
	"image": "mcr.microsoft.com/devcontainers/base:debian",
	"features": {
		"ghcr.io/rocker-org/devcontainer-features/r-apt:0": {
			"installBspm": true
		}
	}
}

image

This setup corresponds to the following script run with INSTALLBSPM=true.
https://github.com/rocker-org/devcontainer-features/blob/583387a2831c181905c571b306f3a976affbe5cb/src/r-apt/install.sh

Perhaps the script contains improper settings somewhere?

Originally posted by @eitsupi in #169 (comment)

@Enchufa2
Copy link

Enchufa2 commented Aug 9, 2023

Not sure what happens here... I see:

$ sudo /usr/local/lib/R/site-library/bspm/service/bspm.py discover
Traceback (most recent call last):
  File "/usr/local/lib/R/site-library/bspm/service/bspm.py", line 150, in <module>
    read_conf()
  File "/usr/local/lib/R/site-library/bspm/service/bspm.py", line 16, in read_conf
    conf = backend.discover()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/R/site-library/bspm/service/backend/apt.py", line 14, in discover
    cache = apt.Cache()
            ^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/apt/cache.py", line 170, in __init__
    self.open(progress)
  File "/usr/lib/python3/dist-packages/apt/cache.py", line 232, in open
    self._cache = apt_pkg.Cache(progress)
                  ^^^^^^^^^^^^^^^^^^^^^^^
apt_pkg.Error: E:The value 'testing' is invalid for APT::Default-Release as such a release is not available in the sources

But then, after running sudo apt-get update manually, everything works fine.

@eitsupi
Copy link
Member Author

eitsupi commented Aug 10, 2023

Thanks for looking at this.
Is there a problem with setting testing...?

echo "Set up Debian testing..."
echo "deb http://http.debian.net/debian testing main" >/etc/apt/sources.list.d/debian-testing.list
echo "deb http://http.debian.net/debian unstable main" >/etc/apt/sources.list.d/debian-unstable.list
echo 'APT::Default-Release "testing";' >/etc/apt/apt.conf.d/default

Do you think bspm should automatically run apt update?

@Enchufa2
Copy link

It does update the cache here:

https://github.com/Enchufa2/bspm/blob/4d3c8ce500c0c4f7b30ca322fdf51d9c26b23d9d/inst/service/backend/apt.py#L15

But note that the error is raised one line before that, when we are just instantiating the Cache object. So I suppose that apt update does something else on top of that, maybe to fix inconsistent states?

bspm runs just fine with debian:testing, but the base image you are using here is a stable one, right? Then I'd say it's your responsibility to ensure that the cache is in a consistent state after switching to testing.

@Enchufa2
Copy link

Enchufa2 commented Aug 10, 2023

[Removing my previous comment since I forgot to add the repos. My last comment still holds].

@Enchufa2
Copy link

Enchufa2 commented Aug 10, 2023

Here's a minimal reprex:

$ docker run --rm -it mcr.microsoft.com/devcontainers/base:debian
$ echo "deb http://http.debian.net/debian testing main" >/etc/apt/sources.list.d/debian-testing.list 
$ echo 'APT::Default-Release "testing";' >/etc/apt/apt.conf.d/default 
$ apt-get -y update && apt-get -y install python3-apt
$ rm -rf /var/lib/apt/lists/*
$ python3 -c "import apt; apt.Cache()"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/apt/cache.py", line 170, in __init__
    self.open(progress)
  File "/usr/lib/python3/dist-packages/apt/cache.py", line 232, in open
    self._cache = apt_pkg.Cache(progress)
                  ^^^^^^^^^^^^^^^^^^^^^^^
apt_pkg.Error: E:The value 'testing' is invalid for APT::Default-Release as such a release is not available in the sources

I.e. bspm cannot run apt.Cache().update() if apt.Cache() cannot be instantiated in the first place.

@eitsupi
Copy link
Member Author

eitsupi commented Aug 12, 2023

Thanks,

Interestingly, a search on that error message turned up previous issues of the Rocker project. (rocker-org/rocker#167)

@Enchufa2
Copy link

It's strange, because, according to the docs,

import apt

# First of all, open the cache
cache = apt.Cache()
# Now, lets update the package list
cache.update()

should be equivalent to apt-get update, which succeeds. But opening the cache fails in the first place. Maybe this is a bug in the Python API?

@Enchufa2
Copy link

Another question is: do you really need to set APT::Default-Release "testing"; in the first place? If I spawn a debian:stable container and add the testing repo, package installations come from testing, and this bug is no more.

@eitsupi
Copy link
Member Author

eitsupi commented Aug 14, 2023

Thanks for taking a closer look at this.

Maybe this is a bug in the Python API?

This certainly looks like a bug in python-apt.

Another question is: do you really need to set APT::Default-Release "testing"; in the first place?

I simply wanted to provide a way to install the latest R. I don't know if this is the best way to do it.

@Enchufa2
Copy link

All package managers install the latest package versions by default, and APT is no exception. So if you just add the testing repositories, the latest R will be pulled.

From what I've seen, the typical use of APT::Default-Release would be the other way around: to pin packages by default to an older release when you add repos from a newer one. I.e. I want r-base from testing, but I don't want the rest of the packages to be automatically upgraded to testing, so I add the testing repos but set APT::Default-Release to stable.

TL;DR, unless I'm missing something (please @eddelbuettel correct me if I'm wrong), I think you can just drop that line and everything will work as intended here.

@eddelbuettel
Copy link
Member

Good call by @Enchufa2

I usually just work with 'testing' and may at times select into 'unstable' -- this iss what Rocker's r-base and derived containers do. I have the suspicion that forcing 'stable' may be the issue but I just don't know. There are scary many options to apt and I cannot claim to have explored all of them. But simply not impossing 'stable' may work.

FWIW I just fired up rocker/r-bspm:testing and asked it to install.r RcppArmadillo. With (default) options(bspm.version.check=TRUE) it noticed the newer source (0.12.6.1.0) and attempted to compiled it. When I ctrl-c'ed out and set options(bspm.version.check=FALSE) it picked the testing binary 0.12.4.1.0 just fine. (With direct use of apt I can override this on the fly too. )

This setup has APT::Default-Release "testing"; in /etc/apt/apt.conf.d/default.

@eitsupi eitsupi added bug Something isn't working help wanted Extra attention is needed labels Sep 3, 2023
eitsupi added a commit that referenced this issue Oct 8, 2023
This PR also tweaks installation on Debian. (Related to
#173 (comment))
@eitsupi
Copy link
Member Author

eitsupi commented Oct 8, 2023

After #204 merging, it seems working now.
As @Enchufa2 pointed out, it seems that APT::Default-Release "testing"; was the cause. thank you!

@eitsupi eitsupi closed this as completed Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants