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

Sketch to show that populating download cache on conan upload is possible #15223

Draft
wants to merge 4 commits into
base: release/2.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions conan/cli/commands/upload.py
@@ -1,3 +1,5 @@
import os

from conan.api.conan_api import ConanAPI
from conan.api.model import ListPattern, MultiPackagesList
from conan.api.output import ConanOutput
Expand Down
1 change: 1 addition & 0 deletions conan/internal/conan_app.py
Expand Up @@ -38,6 +38,7 @@ def __init__(self, requester, cmd_wrapper, global_conf, cache):

class ConanApp(object):
def __init__(self, cache_folder, global_conf):
self.global_conf = global_conf

self.cache_folder = cache_folder
self.cache = ClientCache(self.cache_folder, global_conf)
Expand Down
13 changes: 13 additions & 0 deletions conans/client/cmd/uploader.py
Expand Up @@ -4,6 +4,7 @@

from conan.internal.conan_app import ConanApp
from conan.api.output import ConanOutput
from conans.client.downloaders.download_cache import DownloadCache
from conans.client.source import retrieve_exports_sources
from conans.errors import ConanException, NotFoundException
from conans.paths import (CONAN_MANIFEST, CONANFILE, EXPORT_SOURCES_TGZ_NAME,
Expand Down Expand Up @@ -244,6 +245,18 @@ def upload_package(self, pref, prev_bundle, remote):
self._app.remote_manager.upload_package(pref, cache_files, remote)
duration = time.time() - t1
self._output.debug(f"Upload {pref} in {duration} time")
for cache_file in cache_files:
self._local_cache_file(pref, cache_file, remote)

def _local_cache_file(self, pref, cache_file, remote):
approved_files = ["conaninfo.txt", "conan_package.tgz", "conanmanifest.txt"]
RubenRBS marked this conversation as resolved.
Show resolved Hide resolved
if cache_file not in approved_files:
return
_download_cache = self._app.global_conf.get("core.download:download_cache")
if _download_cache and os.path.isabs(_download_cache):
url = self._app.remote_manager._auth_manager._get_rest_client(remote)._get_api().router.package_file(pref, cache_file)
RubenRBS marked this conversation as resolved.
Show resolved Hide resolved
cached_path = DownloadCache(_download_cache).cached_path(url)
RubenRBS marked this conversation as resolved.
Show resolved Hide resolved
self._output.info(f"Caching {cache_file} to local cache '{cached_path}' - was uploaded to {url}")


def compress_files(files, name, dest_dir, compresslevel=None, ref=None):
Expand Down
5 changes: 5 additions & 0 deletions conans/test/integration/command/upload/upload_test.py
Expand Up @@ -15,6 +15,7 @@
from conans.test.utils.tools import NO_SETTINGS_PACKAGE_ID, TestClient, TestServer, \
TurboTestClient, GenConanfile, TestRequester, TestingResponse
from conans.util.files import gzopen_without_timestamps, is_dirty, save, set_dirty
from utils.test_files import temp_folder

conanfile = """from conan import ConanFile
from conan.tools.files import copy
Expand Down Expand Up @@ -231,10 +232,14 @@ def test_upload_unmodified_package(self):

client.save({"conanfile.py": conanfile,
"hello.cpp": ""})
download_cache = temp_folder()
client.save_home({"global.conf": f"core.download:download_cache={download_cache}"})
ref = RecipeReference.loads("hello0/1.2.1@frodo/stable")
client.run("create . --user=frodo --channel=stable")
client.run("upload hello0/1.2.1@frodo/stable -r default")

assert "Caching conan_package.tgz to local cache" in client.out

client2 = TestClient(servers=client.servers, inputs=["admin", "password"])
client2.save({"conanfile.py": conanfile,
"hello.cpp": ""})
Expand Down