-
Notifications
You must be signed in to change notification settings - Fork 946
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
Feature add an option to only copy files if they are different #9389
Conversation
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 feature is not completely clear.
In the case this will progress, it would need some tests, to be added in the PR before merging.
conans/client/file_copier.py
Outdated
@@ -51,7 +52,7 @@ def report(self, output): | |||
return report_copied_files(self._copied, output) | |||
|
|||
def __call__(self, pattern, dst="", src="", keep_path=True, links=False, symlinks=None, | |||
excludes=None, ignore_case=True): | |||
excludes=None, ignore_case=True, if_different=True): |
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.
It is not clear in which scenarios it will be copying a file and the target already exists. The idea is that the self.copy()
copies to an empty package folder, so this shouldn't be an issue.
Why is this being added? Performance?
In any case, it is extremely recommended to not change the current default, as the likelihood of breaking is much much higher. In this case the default should be if_different=False
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 made this draft PR to start a discussion, that is why there are no tests so far.
My understanding is that this function is being used in the conan imports method as well.
Use case:
When doing local development, it is very common to reuse the same build directory. Adding this new param if_different
will optimize copying files to local build directory, specially when:
- large files needs to be copied to the build directory
- Some files in the build directory are already used by another process (currently the import fail, even there is no need to re import this file as it already exist)
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.
Understood, thanks, yes, it makes sense.
Some hints about the future though:
- We will make explicit the
self.copy()
, so maybe this could be added to the imports case only - In Conan 2.0 we will probably reduce or integrate the
imports
case with thedeploy
case. The general idea is that copying files over and over is indeed inefficient, and with virtualenvs it is not needed in most cases, specially development cases. It will only be needed for final extraction of files for final deployment, but not for regular development.
@@ -237,6 +239,7 @@ def _copy_files(files, src, dst, keep_path, symlinks): | |||
pass | |||
os.symlink(linkto, abs_dst_name) # @UndefinedVariable | |||
else: | |||
shutil.copy2(abs_src_name, abs_dst_name) | |||
if not if_different or not os.path.exists(abs_dst_name) or not filecmp.cmp(abs_src_name, abs_dst_name): |
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.
If the reason is performance, some data/benchmark about the savings would be great.
I've use this benchmarking class
and I got these results
|
@memsharded could you re-review this PR |
I am afraid that this PR being red was buried in our notifications and never got reviewed properly. |
Changelog: added new param to self.copy function to only copy files if they are different. Similar to the cmake function
copy_if_different
Mainly for performance purpose to speedup imports when reusing the same build directory.
Docs: conan-io/docs#2186
develop
branch, documenting this one.Note: By default this PR will skip the slower tests and will use a limited set of python versions. Check here how to increase the testing level by writing some tags in the current PR body text.