-
Notifications
You must be signed in to change notification settings - Fork 360
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
Add custom deployer for metadata example #3589
Open
AbrilRBS
wants to merge
2
commits into
conan-io:release/2.1
Choose a base branch
from
AbrilRBS:rr/metadata-deployer-example
base: release/2.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ Custom deployers | |
|
||
|
||
sources/custom_deployer_sources | ||
metadata/custom_deployer_metadata |
96 changes: 96 additions & 0 deletions
96
examples/extensions/deployers/metadata/custom_deployer_metadata.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
.. _examples_extensions_deployers_metadata: | ||
|
||
Copy metadata from all your dependencies | ||
======================================== | ||
|
||
Please, first clone the sources to recreate this project. You can find them in the | ||
`examples2.0 repository <https://github.com/conan-io/examples2>`_ in GitHub: | ||
|
||
.. code-block:: bash | ||
|
||
$ git clone https://github.com/conan-io/examples2.git | ||
$ cd examples2/examples/extensions/deployers/metadata | ||
|
||
|
||
In this example we are going to see how to create and use a custom deployer. | ||
This deployer copies all the metadata files from your dependencies and puts them into a specific output folder. | ||
|
||
.. note:: | ||
|
||
To better understand this example, it is highly recommended to have previously read the :ref:`Deployers <reference_extensions_deployer_direct_deploy>` reference | ||
and the :ref:`metadata <devops_metadata>` feature. | ||
|
||
|
||
Locate the deployer | ||
------------------- | ||
|
||
In this case, the deployer is located in the same directory as our example conanfile, | ||
but as shown in :ref:`Deployers <reference_extensions_deployer_direct_deploy>` reference, | ||
Conan will look for the specified deployer in a few extra places in order, namely: | ||
|
||
#. Absolute paths | ||
#. Relative to cwd | ||
#. In the ``[CONAN_HOME]/extensions/deployers`` folder | ||
#. Built-in deployers | ||
|
||
|
||
Run it | ||
------ | ||
|
||
For our example, we have 3 simple recipes: | ||
|
||
.. graphviz:: | ||
|
||
digraph { | ||
rankdir=LR; | ||
app -> pkg1 -> pkg2; | ||
} | ||
|
||
We first run the first | ||
|
||
.. code-block:: bash | ||
|
||
$ conan create pkg2 | ||
$ conan create pkg1 | ||
$ conan install . --deployer=metadata_deploy | ||
|
||
|
||
Inspecting the resulting files we can see that it copied the metadata of our direct dependency ``pkg1``, | ||
and also of the transitive ``pkg2`` dependency, to a ``dependencies_metadata`` folder. | ||
With this code in mind, extra processing could be done to accomplish more specific needs. | ||
|
||
Note that you can pass the ``--deployer-folder`` argument to change the base folder output path for the deployer. | ||
|
||
Code tour | ||
--------- | ||
|
||
The **metadata_deploy.py** file has the following code: | ||
|
||
.. code-block:: python | ||
:caption: **metadata_deploy.py** | ||
|
||
import os | ||
import shutil | ||
|
||
def deploy(graph, output_folder, **kwargs): | ||
# Note the kwargs argument is mandatory to be robust against future changes. | ||
conanfile = graph.root.conanfile | ||
for name, dep in conanfile.dependencies.items(): | ||
shutil.copytree(dep.package_metadata_folder, | ||
os.path.join(output_folder, "dependencies_metadata", "packages", dep.ref.name, dep.pref.package_id)) | ||
shutil.copytree(dep.recipe_metadata_folder, | ||
os.path.join(output_folder, "dependencies_metadata", "recipes", dep.ref.name)) | ||
|
||
|
||
deploy() | ||
++++++++ | ||
|
||
The ``deploy()`` method is called by Conan, and gets both a dependency graph and an output folder path as arguments. | ||
It iterates all the dependencies of our recipe and copies every recipe and package metadata folder to their respective folders | ||
under ``dependencies_metadata`` using ``shutil.copytree``. | ||
|
||
|
||
.. note:: | ||
|
||
If your custom deployer needs access to the full dependency graph, including those libraries that might be skipped, | ||
use the ``tools.graph:skip_binaries=False`` conf. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The challenge with this example is that there will be issues with users expectations:
conan install
will install dependencies, but it will not install metadata from the serversThe solution is that the metadata has to be downloaded from the server with
conan download --metadata
explicitly first, then collected.