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

Tools files rm: Exclude pattern to avoid removing everything #16350

Merged
merged 4 commits into from
May 28, 2024

Conversation

uilianries
Copy link
Member

@uilianries uilianries commented May 28, 2024

Greetings!

Added the new parameter excludes, same used by tools.files.copy. This new parameter avoids removing the pattern listed that's also listed by removing pattern. For instance:

def package(self):
    ...
    # Exclude everything from bin folder, except for any .dll file.
    tools.file.rm(self, "*", os.path.join(self.package_folder, "bin"), excludes="*.dll")

Changelog: Feature: Add excludes parameter to tools.files.rm to void removing pattern.
Docs: conan-io/docs#3743

closes #16343

  • 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.

"""
Utility functions to remove files matching a ``pattern`` in a ``folder``.

:param conanfile: The current recipe object. Always use ``self``.
:param pattern: Pattern that the files to be removed have to match (fnmatch).
:param folder: Folder to search/remove the files.
:param recursive: If ``recursive`` is specified it will search in the subfolders.
:param excludes: Pattern to not be removed when matched with the pattern.
Copy link
Member

Choose a reason for hiding this comment

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

In copy() this is:

:param excludes: (Optional, defaulted to None) A tuple/list of fnmatch patterns or even a
single one to be excluded from the copy.

I think it would be good to use the same logic, and use a list/tuple here for exclusions, not just 1 single value.

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.

Better to align with copy() using a list as argument

@uilianries
Copy link
Member Author

@memsharded Updated to use tuple or list as parameter. In case passing string, it will be converted to tuple. Same behavior as running in copy().

Signed-off-by: Uilian Ries <[email protected]>
@memsharded memsharded added this to the 2.4.0 milestone May 28, 2024
Copy link
Member

@AbrilRBS AbrilRBS left a comment

Choose a reason for hiding this comment

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

:)

@czoido czoido merged commit 7771c1b into conan-io:develop2 May 28, 2024
2 checks passed
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.

[feature] Adding support to exclude pattern when removing files with Conan tools
4 participants