Skip to content
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] Have trim_conandata not throw when there's no conandata.yml #15672

Closed
1 task done
AbrilRBS opened this issue Feb 14, 2024 · 3 comments · Fixed by #15829
Closed
1 task done

[feature] Have trim_conandata not throw when there's no conandata.yml #15672

AbrilRBS opened this issue Feb 14, 2024 · 3 comments · Fixed by #15829
Assignees
Milestone

Comments

@AbrilRBS
Copy link
Member

AbrilRBS commented Feb 14, 2024

What is your suggestion?

trim_conandata can be used inside a post_export hook instead of the export() method in recipes, but then we have no control over wether a recipe has an associated conandata.yml.

The fix is easy, just try: ... catch: it, but feels a bit dirty.
Ideally that could be skipped, but it's true that when used in the export method, it might be desirable to have it raise, so we need to give it a thought

Reproducing this is easy: Have a simple recipe without a conandata.yml and a post_export hook that simply calls trim_conandata. That is, this test should pass, which currently does not:

def test_trim_conandata_as_hook_without_conandata():
    c = TestClient()
    c.save_home({"extensions/hooks/hook_trim.py": textwrap.dedent("""
    from conan.tools.files import trim_conandata

    def post_export(conanfile):
        trim_conandata(conanfile)
    """)})

    c.save({"conanfile.py": GenConanfile("pkg")})
    c.run("export . --version=1.0")
    assert c.exported_recipe_revision() == "a9ec2e5fbb166568d4670a9cd1ef4b26"

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@AbrilRBS AbrilRBS added this to the 2.2 milestone Feb 14, 2024
AbrilRBS added a commit to AbrilRBS/conan that referenced this issue Feb 14, 2024
AbrilRBS added a commit that referenced this issue Feb 14, 2024
* Add trim_conandata() as hook - For #15672

* Fix test
@AbrilRBS
Copy link
Member Author

AbrilRBS commented Mar 7, 2024

Ideally, I'd like the trim_conandata function to raise when it's not executing on a hook context, but keep raising if it was call elsewhere, as that is something the user will have control over on a recipe basis

/cc @memsharded wdyt?

@jcar87
Copy link
Contributor

jcar87 commented Mar 7, 2024

My suggestion is def trim_conandata(conanfile, raise_if_missing=True) (a True default value to behave exactly as it does now)

  • And implement the hook as:
    def post_export(conanfile, raise_if_missing=False):
        trim_conandata(conanfile)

If called from a recipe, these have control over: the argument passed, and whether conandata.yml exists.

@memsharded
Copy link
Member

Ideally, I'd like the trim_conandata function to raise when it's not executing on a hook context,

Not sure what you mean. I think recipes should call this explicitly, to be self-contained and not depend on a hook to do the right thing. Being a multi-version recipe is something that is specific to the recipe, so I'd like it to be part of the recipe by default. The hook approach is necessary because it will take a lot of time to get there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants