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 support for exports and exports_sources as methods #6945
add support for exports and exports_sources as methods #6945
Conversation
conans/client/cmd/export.py
Outdated
if callable(conanfile.exports_sources): | ||
conanfile.deps_cpp_info = DepsCppInfo() | ||
conanfile.copy = FileCopier([origin_folder], destination_source_folder) | ||
conanfile.export_sources() |
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.
conanfile.export_sources() | |
conanfile.exports_sources() |
As for #6876 I tested a recipe from CCI, I added the following method def exports_sources(self):
self.copy(pattern="patches/**")
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self.copy._dst_folder) Which worked exactly as intended, certainly makes it much easier to bundle the sources. I need to think about how I can use this as part of a final solution. But it's certainly a welcomed improvement. |
class ExportsMethodTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.server = TestServer() |
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.
You don't need servers for anything, simplify
""" | ||
|
||
|
||
class ExportsMethodTest(unittest.TestCase): |
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.
Do not put new tests in "integration" folder, that is to be removed.
Moved them to "functional/command/export" folder (create the folder, and move other export tests in "funcional/command" there too.
from conans.test.utils.tools import NO_SETTINGS_PACKAGE_ID, TestClient, TestServer | ||
|
||
attribute_conanfile = """ | ||
from conans import ConanFile |
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.
Use GenConanfile()
generator if possible. Minor improvements to ``GenConanfile" can be done if necessary
conans/client/cmd/export.py
Outdated
if conanfile.exports: | ||
tmp.extend(conanfile.exports) # conanfile.exports could be a tuple (immutable) | ||
conanfile.exports = tmp | ||
if os.path.exists(os.path.join(origin_folder, DATA_YML)): |
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 data_yml needs to be exported always. Probably this should be done irrespective of the attribute/method approach
conans/client/cmd/export.py
Outdated
if callable(conanfile.exports_sources): | ||
conanfile.deps_cpp_info = DepsCppInfo() | ||
conanfile.copy = FileCopier([origin_folder], destination_source_folder) | ||
conanfile.export_sources() |
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.
PLease use:
conan_file.output.highlight("Running export_sources()")
with conanfile_exception_formatter(str(conan_file), "export_sources"):
to wrap it and provide better user messages in case of exceptions
Like the idea, and the possibilities it opens to record a snapshot of the sources for packages built with Conan Center, but I'd want to see how a recipe using it would look like: what's the difference between the The example in #6945 (comment) is a bit asymmetric IMO, I see sources going from the recipe folder to the cache and sources arriving from outside to the recipe folder (and then to the cache)... which one is the working directory for this method? I like the idea of running Thanks! |
Indeed, there's a very important open question relating to one of the fundamental goals for "source packaging":
This situation has existed for a long time, but we've never actually had to deal with it because we've never really entertained the idea of supporting any interaction with Probably refer to #6944 to follow that thread. |
Good questions. I've modified the original PR comment to provide the goals and implementation details which hopefully answer your questions. Obviously, will need to be VERY clear in docs. The most important addition is this... I already favor a different implementation from this one.
Of note, we also created a function equivalent of |
Yes, interesting approach too. Even if this was another feature in another PR, I think we need to have an overall strategy defined first. If the new method |
The working directory was the recipe folder! And yes, my goal is very far the intended usage of this feature. You guys are doing some great work ❤️ |
There is a problem with using |
For this reason, and others, I suggest that this feature should be re-implemented based on the current pipeline of the |
Yes, but an implementation based on the source() flow will be way more difficult, most likely involving server-side changes, which typically take at least many months to implement and release. This is why I was looking for something based on the export flow. |
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.
Thinking about Conan v2.0 I wonder if we want to have both attribute and method available at the same time, or we should allow only one implementation (with the same name).
Besides that, please:
- Update the PR description to match the implementation (existing comments can be moved to an issue if needed)
- Waiting for docs
Something to add to docs: if function |
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.
Just a couple of comments, and we need to update the PR description and docs
Changelog: Feature: Add
export()
andexport_sources()
methods, that provide theself.copy()
helper to add files to recipe or sources in the same way as the corresponding attributes.Docs: conan-io/docs#1733
Notice.-
Description in the PR doesn't match actual implementation merged
Note: Waiting to add docs until this feature until implementation has been reviewed.
closes: #6943
close #7102
Also related to others: #6944
Goals:
The gap it intends to fulfill, and how it should/should-not interact with other methods should be clearly explained in future documentation. Here's a summary to start with.
The goal of
exports_sources
is to provide out-of-source recipes a method to cache sources in the same way thatexports_sources
does. This could theoretically replace all uses ofsource()
method. Described another way, it represents a "caching" version ofsource()
method.Implementation
The
exports_sources
method overlaps two existing concepts:source()
methodexports_sources
attributeThe current implementation deserves some explanation as we may decide to change it. The current implementation was the path of least resistance: make two modifications to the call path of
exports_sources
logic today:exports_sources
member, and if its a function, execute itself.copy
method withexport_sources
being the working directoryEverything else about the behavior would be identical to the
exports_sources
attribute. Most importantly, the timings at which it was executed are the same.Alternative Ideas for implementation
self.copy()
available in thesource()
methodsource()
to useexports_sources
directory as the working directoryexports_sources
, further refactoring may be necessarysource_exported()
, identical tosource
, butexports_sources
as workingsource
, no further recipe changes required, it just worksexports_sources
, further refactoring may be necessaryNotes for discussion...
Understand Interactions with
Refer to the issue that supports this Pull Request.
If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
I've read the Contributing guide.
I've followed the PEP8 style guides for Python code.
[] I've opened another PR in the Conan docs repo to the
develop
branch, documenting this one.