diff --git a/swh/lister/opam/lister.py b/swh/lister/opam/lister.py --- a/swh/lister/opam/lister.py +++ b/swh/lister/opam/lister.py @@ -7,7 +7,6 @@ import logging import os from subprocess import PIPE, Popen, call -import tempfile from typing import Iterator, Optional from swh.lister.pattern import StatelessLister @@ -46,6 +45,7 @@ url: str, instance: Optional[str] = None, credentials: CredentialsType = None, + opam_root: str = "/tmp/opam/", ): super().__init__( scheduler=scheduler, credentials=credentials, url=url, instance=instance, @@ -53,7 +53,7 @@ self.env = os.environ.copy() # Opam root folder is initialized in the :meth:`get_ pages` method as no # side-effect should happen in the constructor to ease instantiation - self.opamroot = tempfile.mkdtemp(prefix="swh_opam_lister") + self.opamroot = os.path.join(opam_root, self.instance) def get_pages(self) -> Iterator[PageType]: # Initialize the opam root directory with the opam instance data to list. diff --git a/swh/lister/opam/tests/test_lister.py b/swh/lister/opam/tests/test_lister.py --- a/swh/lister/opam/tests/test_lister.py +++ b/swh/lister/opam/tests/test_lister.py @@ -4,6 +4,7 @@ # See top-level LICENSE file for more information import io +from tempfile import mkdtemp from unittest.mock import MagicMock import pytest @@ -33,8 +34,9 @@ netloc = "opam.ocaml.org" instance_url = f"https://{netloc}" - lister = OpamLister(swh_scheduler, url=instance_url) + lister = OpamLister(swh_scheduler, url=instance_url,) assert lister.instance == netloc + assert lister.opamroot.endswith(lister.instance) def test_urls(swh_scheduler, mock_opam): @@ -42,7 +44,12 @@ instance_url = "https://opam.ocaml.org" - lister = OpamLister(swh_scheduler, url=instance_url, instance="opam") + lister = OpamLister( + swh_scheduler, + url=instance_url, + instance="opam", + opam_root=mkdtemp(prefix="swh_opam_lister"), + ) assert lister.instance == "opam" # call the lister and get all listed origins urls @@ -70,7 +77,12 @@ def test_opam_binary(datadir, swh_scheduler): instance_url = f"file://{datadir}/fake_opam_repo" - lister = OpamLister(swh_scheduler, url=instance_url, instance="fake") + lister = OpamLister( + swh_scheduler, + url=instance_url, + instance="fake", + opam_root=mkdtemp(prefix="swh_opam_lister"), + ) stats = lister.run()