-
Notifications
You must be signed in to change notification settings - Fork 27
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
Simplify license deployer, support nested folders #162
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,29 @@ | ||
import os | ||
import zipfile | ||
from conan.api.output import ConanOutput | ||
from conan.tools.files import copy, rmdir | ||
|
||
|
||
# USE **KWARGS to be robust against changes | ||
def deploy(graph, output_folder, **kwargs): | ||
out = ConanOutput("deployer(licenses)") | ||
conanfile = graph.root.conanfile | ||
files = [] | ||
|
||
# Cleanup before we start :) | ||
tmp_dir = os.path.join(output_folder, "licenses") | ||
if os.path.exists(tmp_dir): | ||
rmdir(conanfile, tmp_dir) | ||
|
||
# For each dep | ||
for r, d in conanfile.dependencies.items(): | ||
if d.package_folder is None: | ||
continue | ||
|
||
# Look for a licenses folder | ||
search_dir = os.path.join(d.package_folder, "licenses") # This is the CCI convention | ||
if not os.path.isdir(search_dir): | ||
continue | ||
with zipfile.ZipFile(os.path.join(output_folder, 'licenses.zip'), 'w') as licenses_zip: | ||
for r, d in conanfile.dependencies.items(): | ||
if d.package_folder is None: | ||
continue | ||
|
||
# Grab all the files and copy them to a temp dir (this is what we will zip) | ||
for f in os.listdir(search_dir): | ||
src = os.path.join(search_dir) | ||
# Let's kep the name and version so we know which belongs to whats | ||
dst = os.path.join(tmp_dir, str(d.ref.name), str(d.ref.version)) | ||
out.debug(src) | ||
out.debug(dst) | ||
copy(conanfile, f, src, dst) # Using the conan help because it make's parent folders | ||
files.append(os.path.join(str(d.ref.name), str(d.ref.version), f)) | ||
# Look for a licenses folder | ||
search_dir = os.path.join(d.package_folder, "licenses") # This is the CCI convention | ||
if not os.path.isdir(search_dir): | ||
continue | ||
|
||
out.trace(files) | ||
with zipfile.ZipFile(os.path.join(output_folder, 'licenses.zip'), 'w') as licenses_zip: | ||
for f in files: | ||
file = os.path.join(tmp_dir, f) | ||
licenses_zip.write(file, arcname=f, compress_type=zipfile.ZIP_DEFLATED) | ||
os.remove(file) # Delete all the files we copied! This is so the source control stays clean | ||
# Grab all the files and write them in the zipfile | ||
for root, _, files in os.walk(search_dir): | ||
# Let's keep the name and version so we know which belongs to what | ||
for file in files: | ||
src = os.path.join(root, file) | ||
dst = os.path.join(str(d.ref.name), str(d.ref.version), os.path.relpath(root, search_dir), file) | ||
out.debug(f"Copying {src} to {dst}") | ||
licenses_zip.write(src, arcname=dst, compress_type=zipfile.ZIP_DEFLATED) |
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
Oops, something went wrong.
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.
I like somehow that the deployer has separated the recollection and the zipping, so users that don't want the final
zip
, they can just remove those lines from their fork of this deployer.But I think it is also good as this proposes, not a big deal, clear enough ,and it handles the nested folder, so already an improvement over the existing one, good for me.