Skip to content

Commit 9c85903

Browse files
committed
feat: implement strip mode
Strips all `.py{c,o}`, `RECORD`, `direct_url.json`, and `__pycache__` files to ensure reproducible builds.
1 parent c5613ab commit 9c85903

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

package_python_function/packager.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
class Packager:
1515
AWS_LAMBDA_MAX_UNZIP_SIZE = 262_144_000
16+
DIRS_TO_EXCLUDE= ["__pycache__"]
17+
EXTENSIONS_TO_EXCLUDE= [".pyc", ".pyo"]
18+
FILENAMES_TO_EXCLUDE= ["RECORD", "direct_url.json"]
1619

1720
def __init__(self, venv_path: Path, project_path: Path, output_dir: Path, output_file: Path | None):
1821
self.project = PythonProject(project_path)
@@ -45,10 +48,17 @@ def zip_all_dependencies(self, target_path: Path) -> None:
4548
def zip_dir(path: Path) -> None:
4649
for item in path.iterdir():
4750
if item.is_dir():
48-
zip_dir(item)
51+
if item.name not in self.DIRS_TO_EXCLUDE:
52+
zip_dir(item)
4953
else:
50-
self._uncompressed_bytes += item.stat().st_size
51-
zip_file.write_reproducibly(item, item.relative_to(self.input_path))
54+
if (
55+
item.name not in self.FILENAMES_TO_EXCLUDE
56+
and item.suffix not in self.EXTENSIONS_TO_EXCLUDE
57+
):
58+
self._uncompressed_bytes += item.stat().st_size
59+
zip_file.write_reproducibly(
60+
item, item.relative_to(self.input_path)
61+
)
5262

5363
zip_dir(self.input_path)
5464

0 commit comments

Comments
 (0)