Skip to content

Conversation

uilianries
Copy link
Member

@uilianries uilianries commented Aug 25, 2025

When pushing the PR #192 , the following error occurred in the CI:

clean_other/1.0: Package folder /Users/jenkins/workspace/Examples2.0_PR-192/c226/cbe2/.conan/p/b/clean3acc120868975/p

Elapsed time: 0.17 seconds

Running: conan clean --force

ERROR: Traceback (most recent call last):

  File "/Users/jenkins/workspace/Examples2.0_PR-192/c226/conanenv/src/conan/conan/cli/cli.py", line 308, in main

    cli.run(args)

  File "/Users/jenkins/workspace/Examples2.0_PR-192/c226/conanenv/src/conan/conan/cli/cli.py", line 193, in run

    command.run(self._conan_api, args[0][1:])

  File "/Users/jenkins/workspace/Examples2.0_PR-192/c226/conanenv/src/conan/conan/cli/command.py", line 183, in run

    info = self._method(conan_api, parser, *args)

  File "/Users/jenkins/workspace/Examples2.0_PR-192/c226/cbe2/.conan/extensions/commands/cmd_clean.py", line 31, in clean

    recipes = conan_api.search.recipes("*/*", remote=remote)

AttributeError: 'ConanAPI' object has no attribute 'search'

It seems be affected by conan-io/conan#18726

Signed-off-by: Uilian Ries <[email protected]>
@memsharded
Copy link
Member

Yes, it is true that the search API has been removed, thanks for noticing!

I understand that this PR will later update the example to use the list api instead, isn't it?

Signed-off-by: Uilian Ries <[email protected]>
@uilianries
Copy link
Member Author

@memsharded as far as I see, it comes from conan-io/conan#18726

I could import the search package as in the commit 3005ea6 only to unblock other PRs, then, thinking to update it to conan list in a next PR

Signed-off-by: Uilian Ries <[email protected]>
Signed-off-by: Uilian Ries <[email protected]>
Signed-off-by: Uilian Ries <[email protected]>
@uilianries uilianries requested a review from memsharded August 25, 2025 14:28
recipes = conan_api.search.recipes("*/*", remote=remote)
if recipes and not confirmation("Do you want to remove all the recipes revisions and their packages ones, "
# Get all recipes and packages, where recipe revision is not the latest
pkg_list = conan_api.list.select(ListPattern("*/*#!latest:*#*", rrev=None, prev=None), remote=remote)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the whole command implementation sounds a bit too complicated.
For example, it is not necessary to select all binaries and all revisions here with :*#* as later only the recipe will be removed (and it will remove all the associated binaries automatically)

Then, it sounds very inefficient to list twice with the */* pattern. It sounds better to do a recipe revision list only pkg_list = conan_api.list.select(ListPattern("*/*", rrev=None, prev=None), then remove all but the latest revision, and for that latest revision list the specific package revisions to remove (!latest)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I have a learn curve just to write this small piece, needing to understand the API class implementation around this example. Let me update according to your suggestion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, check the commit 48c7135

Signed-off-by: Uilian Ries <[email protected]>
Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't love that the ListPattern is running twice again for returning the whole Conan cache pkg+versions, but good enough for me for a custom command example

@uilianries
Copy link
Member Author

I still don't love that the ListPattern is running twice again for returning the whole Conan cache pkg+versions, but good enough for me for a custom command example

We don't have helpers anymore to filter the latest rrev and later, to filter prev. It looks a bit complex now, but without these methods, my feeling is the code will be harder to understand based on accessing the list index and filtering manually.

# Get all package revisions from the latest recipe revision, except the latest package revision
pkg_list = conan_api.list.select(ListPattern("*/*:*#!latest", rrev=None, prev=None), remote=remote)
for recipe_ref, recipe_bundle in pkg_list.refs().items():
pkg_list = PackagesList.prefs(recipe_ref, recipe_bundle)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Conan we usually would call this static method from the pkg_list object itself, but do note that this is still an undocumented method, maybe we need to take a look into it - I think getting the refs and prefs of a pkglist is a valid operation that users might want access to.

We also need to check if the remove api can be improved

Signed-off-by: Uilian Ries <[email protected]>
@uilianries
Copy link
Member Author

I still don't love that the ListPattern is running twice again for returning the whole Conan cache pkg+versions, but good enough for me for a custom command example

@memsharded Please, check the commit 729e9f7. I'm using a single list now and filtering the latest revision.

I used max() to find the latest revision, but not sure if it's the best way. Probably @AbrilRBS should have a better idea.

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

Successfully merging this pull request may close these issues.

4 participants