Skip to content
Open
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9dd3619
gh-117829 : start of something new
VietThan Jun 15, 2024
b887165
gh-117829 : logic implementation
VietThan Jun 15, 2024
23785b2
gh-117829 : remove whitespace pre-commit was complaining about
VietThan Jun 15, 2024
3286657
gh-117829: testing out manually exclude-pattern
VietThan Jun 25, 2024
c28771f
gh-117829: add example to --exclude-pattern
VietThan Jun 26, 2024
935a1a5
📜🤖 Added by blurb_it.
blurb-it[bot] Jun 26, 2024
60a9aef
gh-117829: added News with blurb_it
VietThan Jun 26, 2024
ee2b185
gh-117829 : adding to documentation
VietThan Jun 26, 2024
aaed611
gh-117829: failed test on Docs
VietThan Jun 26, 2024
1abe95c
Merge branch 'main' into implement-issue-117829
VietThan Jun 26, 2024
ac29c0e
gh-117829: failed tests on Docs
VietThan Jun 27, 2024
6d0ca9a
Merge remote-tracking branch 'refs/remotes/origin/implement-issue-117…
VietThan Jun 27, 2024
408dd71
gh-117829: linting complains
VietThan Jun 27, 2024
fdcd64f
gh-117829: linting complains
VietThan Jun 27, 2024
da75715
gh-117829 : gotta be careful with rst formatting
VietThan Jun 27, 2024
c4b7cd1
Merge branch 'main' into implement-issue-117829
VietThan Jun 27, 2024
ab215b7
gh-117829 : adding tests for zipapp module
VietThan Aug 17, 2024
a85989c
Merge remote-tracking branch 'refs/remotes/origin/implement-issue-117…
VietThan Aug 17, 2024
e2e6b35
gh-117829 : stop lint problems
VietThan Aug 17, 2024
62dc347
gh-117829 : adding cmdline tests
VietThan Aug 17, 2024
bff0a07
gh-117829 : prevent linting
VietThan Aug 17, 2024
a2bc0bf
Merge branch 'main' into implement-issue-117829
VietThan Aug 17, 2024
36ac9b0
gh-117829 : fix the refex
VietThan Aug 23, 2024
0f077eb
Merge remote-tracking branch 'refs/remotes/origin/implement-issue-117…
VietThan Aug 23, 2024
d5ffee3
Merge remote-tracking branch 'upstream/main' into implement-issue-117829
VietThan Sep 27, 2025
59e2089
gh-117829 : addressed comments, purely CLI flags of glob patterns pas…
VietThan Sep 27, 2025
2e17bbf
gh-117829 : added tests
VietThan Sep 27, 2025
9ec1cf5
gh-117829 : ran pre-commit
VietThan Sep 27, 2025
28c425d
gh-117829 : simplify logic, patterns are standard glob patterns, as i…
VietThan Sep 27, 2025
3265a5a
gh-117829 : updated docs based on feedback
VietThan Sep 27, 2025
c67b6b1
gh-117829 : updated docs for options based on feedback
VietThan Sep 27, 2025
617cf18
gh-117829 : updated docs for options based on feedback
VietThan Sep 28, 2025
e08e765
gh-117829 : small changes based on feedback
VietThan Sep 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gh-117829 : logic implementation
  • Loading branch information
VietThan committed Jun 15, 2024
commit b887165ce27e2f5a36557f9a644fe83c8c460e13
15 changes: 13 additions & 2 deletions Lib/zipapp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextlib
import os
import pathlib
import re
import shutil
import stat
import sys
Expand Down Expand Up @@ -74,7 +75,8 @@ def _copy_archive(archive, new_archive, interpreter=None):


def create_archive(source, target=None, interpreter=None, main=None,
filter=None, compressed=False, include=None, exclude=None):
filter=None, compressed=False, include_regex=None,
exclude_regex=None):
"""Create an application archive from SOURCE.

The SOURCE can be the name of a directory, or a filename or a file-like
Expand Down Expand Up @@ -131,12 +133,20 @@ def create_archive(source, target=None, interpreter=None, main=None,
elif not hasattr(target, 'write'):
target = pathlib.Path(target)

include_pattern = re.compile(include_regex) if include_regex else None
exclude_pattern = re.compile(exclude_regex) if exclude_regex else None

with _maybe_open(target, 'wb') as fd:
_write_file_prefix(fd, interpreter)
compression = (zipfile.ZIP_DEFLATED if compressed else
zipfile.ZIP_STORED)
with zipfile.ZipFile(fd, 'w', compression=compression) as z:
for child in sorted(source.rglob('*')):
child_path = str(child)
if include_pattern and not include_pattern.search(child_path):
continue
if exclude_pattern and exclude_pattern.search(child_path):
continue
arcname = child.relative_to(source)
if filter is None or filter(arcname) and child.resolve() != arcname.resolve():
z.write(child, arcname.as_posix())
Expand Down Expand Up @@ -211,7 +221,8 @@ def main(args=None):

create_archive(args.source, args.output,
interpreter=args.python, main=args.main,
compressed=args.compress)
compressed=args.compress, include_regex=args.include,
exclude_regex=args.exclude)


if __name__ == '__main__':
Expand Down