Skip to content

Commit 1d79831

Browse files
committed
Add build_meta_as_zip function. Fixes #26.
1 parent 8793a46 commit 1d79831

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pep517/build_meta.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import argparse
44
import logging
55
import os
6+
import io
67
import contextlib
78
import pytoml
89
import shutil
910
import errno
1011
import tempfile
12+
import zipfile
1113

1214
from .envbuild import BuildEnvironment
1315
from .wrappers import Pep517HookCaller
@@ -68,6 +70,26 @@ def build_meta(source_dir, dest=None):
6870
_prep_meta(hooks, env, dest)
6971

7072

73+
def dir_to_zipfile(root):
74+
buffer = io.BytesIO()
75+
zip_file = zipfile.ZipFile(buffer, 'w')
76+
for root, dirs, files in os.walk(root):
77+
for path in dirs:
78+
fs_path = os.path.join(root, path)
79+
rel_path = os.path.relpath(fs_path, root)
80+
zip_file.writestr(rel_path + '/', '')
81+
for path in files:
82+
fs_path = os.path.join(root, path)
83+
rel_path = os.path.relpath(fs_path, root)
84+
zip_file.write(fs_path, rel_path)
85+
86+
87+
def build_meta_as_zip(source_dir='.'):
88+
with tempdir() as out_dir:
89+
build_meta(source_dir, out_dir)
90+
return dir_to_zipfile(out_dir)
91+
92+
7193
parser = argparse.ArgumentParser()
7294
parser.add_argument(
7395
'source_dir',

0 commit comments

Comments
 (0)