question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature] Provide a hook for transparently overriding source downloads

See original GitHub issue

Please provide hooks for conans.tools.get, conans.tools.download, and corresponding Conan 2 functions, so that the download handling and caching can be overridden by custom logic.

The inputs to the custom download hook would be the URL and checksum of the source archive. The hook would return a path to a local read-only file or write content to a given target path. Checksum verification and unzipping should be handled by conan. Error handling could be done by raising an exception (abort operation) or a special return code to fallback to the default download handling.

Motivation is to allow offline builds in isolated environments using a “custom local repository” for the source code archives. One requirement is that the recipes and conandata.yml are not modified and can point to the original online resources. This should not affect the reproducibility when using the recommended SHA256 checksum.

Below is an example use case of my current setup:

  • Recipes are located in a local git repository. Most of the recipes have been manually downloaded from Conan Center Index and contain no or only minor modifications. Specifically, all recipes use conans.tools.get with URL and SHA256 specified in conandata.yml.
  • Source code has been downloaded manually into a local folder from the URLs in the conandata.yml.
  • A custom download hook has been implemented by monkey patching the conans.tools.get inside a pre_source hook. The custom download hook finds a local source file path based on the given sha256sum.
  • Packages in the local .conan cache are built from source with conan create using the recipes in the local git repository, and the download hook unzips source files directly from the local download folder, so there is no network activity.

Future ideas: (not needed for my current use case)

  • Provide similar hooks for scm / git clone.
  • Provide hooks for replacing parts of the conan server API to allow more offline use-cases without conan_server.

The feature request is somewhat related to: #6876, #6944, #11243, and other issues about offline builds and source code caching.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
goodtunecommented, Aug 25, 2022

I have a slightly different use case to mention, and would consider it a powerful addition for corporate use.

Our company policy disallows the retrieval of source code directly from external sites, however we do have an Artifactory instance that provides the VCS Repository, that allows us to retrieve tags or branches from hosted Git services, such as Github.

As an example, the opentelemetry-cpp recipe from conan-io/conan-center-index has the following conandata.yml:

sources:
  "1.4.1":
    url: "https://github.com/open-telemetry/opentelemetry-cpp/archive/v1.4.1.tar.gz"
    sha256: "301b1ab74a664723560f46c29f228360aff1e2d63e930b963755ea077ae67524"

patches:
  "1.4.1":
    - patch_file: "patches/1.4.0-0001-fix-cmake.patch"
      base_path: "source_subfolder"

We aren’t allowed to use an HTTP proxy like Squid, but I could rewrite the URL to fetch the archive - for example "https://github.com/open-telemetry/opentelemetry-cpp/archive/v1.4.1.tar.gz" would become "https://artifactory.corp.local/artifactory/api/vcs/downloadTag/github/open-telemetry/opentelemetry-cpp/v1.4.1?ext=tar.gz". This would benefit subsequent users on our network as Artifactory can cache it forever.

The HTTP headers from this download (important ones selectively shown below) show that we’ve maintained the sha256 value.

HTTP/1.1 200 OK
Content-Type: application/x-gzip
X-Checksum-Sha256: 301b1ab74a664723560f46c29f228360aff1e2d63e930b963755ea077ae67524
X-Artifactory-Filename: opentelemetry-cpp-v1.4.1.tar.gz

I’ve just started my search for related tickets, if this has been discussed elsewhere, I can add my comments there.

0reactions
memshardedcommented, Nov 18, 2022

Our intent is to get 2.0 out before EOY, but it is a bit tight, and it also depends on the migration efforts in ConanCenter. But definitely soon. The best way to contribute atm is to test the released beta.5 and give feedback.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pre-commit
A framework for managing and maintaining multi-language pre-commit hooks. Build Status · Azure DevOps Coverage · pre-commit.ci status · Star9,364 ...
Read more >
FeatureLayer | API Reference - ArcGIS Developers
Server -side and client-side feature tile caching allow features to load ... Setting a fine-grained API key on a specific class overrides the...
Read more >
PEP 517 – A build-system independent format for source trees
The actual building is done by each source tree's build backend. ... SHOULD provide some mechanism for users to override the above defaults....
Read more >
OpenSeadragon
An open-source, web-based viewer for high-resolution zoomable images, implemented in pure JavaScript, for desktop and mobile.
Read more >
Writing and Organizing Tests - Cypress Documentation
Any files downloaded while testing an application's file download feature will be stored in the ... Cypress also provides hooks (borrowed from Mocha)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found