X Tutup
The Wayback Machine - https://web.archive.org/web/20250624173943/https://github.com/python/cpython/pull/19879
Skip to content

bpo-40481: Add include and exclude filters to zipapp cli #19879

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

Closed
wants to merge 2 commits into from

Conversation

jwygoda
Copy link

@jwygoda jwygoda commented May 3, 2020

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@jwygoda

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

Copy link
Member

@pfmoore pfmoore left a comment

Choose a reason for hiding this comment

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

A few comments on the general approach here. The code looks fine, I just have some design concerns. Also, this change would need documentation.

Lib/zipapp.py Outdated
def create_archive(source, target=None, interpreter=None, main=None,
filter=None, compressed=False):
filter=None, compressed=False, **filter_kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

I'm concerned about file arguments for the filter being "anything that doesn't already have a meaning". What if we want to add another argument to the create_archive function? This functionality seems a bit too niche to "steal" all of the remaining potential argument names.

I'd prefer the filter_kwargs argument to be a normal argument that takes a dictionary. Or maybe even just pass a single argument to the filter - let the filter decide how to interpret it.

@@ -138,7 +154,7 @@ def create_archive(source, target=None, interpreter=None, main=None,
with zipfile.ZipFile(fd, 'w', compression=compression) as z:
for child in source.rglob('*'):
arcname = child.relative_to(source)
if filter is None or filter(arcname):
if filter is None or filter(arcname, **filter_kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Note that for backward compatibility, if you change filter_kwargs to be a single argument as I suggest above, you'll need to still allow for filters with no arguments. The current code handles this case, but as mentioned, I don't like the current approach.

)
parser.add_argument("--exclude", "-e", default=[], nargs="*",
help="A glob-style sequence of paths to exclude.",
)
Copy link
Member

Choose a reason for hiding this comment

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

What are the use cases for these defaults? They seem reasonable, but personally I've never needed this functionality, so I have no easy way to judge whether this would be more useful than (for example) the ability to exclude a list of named subdirectories.

I'd expect the command line API to handle basic cases, but for more complex uses I'd assume people would write a custom build script that used the create_archive function directly. So I'd like to see some evidence that this particular form of filter is sufficiently common to warrant being a feature of the command line version - otherwise it could become a precedent for more and more complexity in the CLI, which is something I think we should avoid.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@idomic
Copy link
Contributor

idomic commented May 10, 2020

@pfmoore Don't forget to add a news update since you've changed code, add it manually or by using this app: https://blurb-it.herokuapp.com/add_blurb

@csabella
Copy link
Contributor

@jwygoda, please address the code reviews. Thank you!

@jwygoda
Copy link
Author

jwygoda commented May 30, 2020

@csabella Thanks for the ping, I missed this review.

@pfmoore
Thanks for the review. I've made filter_kwargs to take a dictionary.

This feature is usefull for packaging .pyc only distributions and excluding files with some extensions (e.g. images). I'm deploying packages to aws lambda where there's a limit to package size.

These defaults were inspired by find_packages from setuptools. Include and exclude filters are quite usefull for fine graining package content.
https://github.com/pypa/setuptools/blob/v46.1.3/setuptools/__init__.py#L52
https://setuptools.readthedocs.io/en/latest/setuptools.html?highlight=find_packages#using-find-packages
Exclude argument is also used in packages deploying python code into lambda.
zappa:
https://github.com/Miserlou/Zappa#advanced-settings
chalice:
https://github.com/aws/chalice/blob/81edd71f4eed6a608d418292b49e9b27a4e9f146/docs/source/conf.py#L84

@taleinat
Copy link
Contributor

Ping, @pfmoore?

@jwygoda jwygoda closed this Apr 19, 2022
@pfmoore
Copy link
Member

pfmoore commented Apr 19, 2022

@jwygoda Apologies, this dropped off my radar. Are you still interested in working on this? If you are, I'm now happy with the filter_kwargs argument, but I'd like to see a little more discussion around the command line interface you've added. If nothing else, it needs docs.

I'd be looking for examples of workflows where you'd build a zipapp using these options - it feels to me as if you'd be better excluding files when you are preparing the directory for zipping, rather than using filters, so I'd like to see examples that demonstrate when that's not practical.

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

Successfully merging this pull request may close these issues.

8 participants
X Tutup