Skip to content

Commit db3c4dd

Browse files
authored
Merge pull request #54 from kronosapiens/master
Reorganize lib to fit distribution conventions.
2 parents 6963505 + 755cf76 commit db3c4dd

12 files changed

Lines changed: 71 additions & 61 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
build
33
dist
44
MANIFEST
5+
__pycache__
56

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include *.py AUTHORS README.rst *.h MANIFEST.in LICENSE
1+
include *.py AUTHORS README.rst snappy/*.h MANIFEST.in LICENSE

setup.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@
3434
"""
3535

3636

37-
snappymodule = Extension('_snappy',
37+
snappymodule = Extension('snappy._snappy',
3838
libraries=['snappy'],
39-
sources=['snappymodule.cc', 'crc32c.c'])
39+
sources=['snappy/snappymodule.cc', 'snappy/crc32c.c'])
4040

4141
ext_modules = [snappymodule]
4242
packages = ['snappy']
43-
package_dir = {'snappy': ''}
4443
install_requires = []
4544

4645
if 'PyPy' in sys.version:
@@ -76,6 +75,5 @@
7675
],
7776
ext_modules = ext_modules,
7877
packages = packages,
79-
package_dir = package_dir,
8078
install_requires = install_requires
8179
)

snappy/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from snappy import (
2+
compress,
3+
decompress,
4+
uncompress,
5+
stream_compress,
6+
stream_decompress,
7+
StreamCompressor,
8+
StreamDecompressor,
9+
UncompressError,
10+
isValidCompressed,
11+
)

snappy/__main__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from snappy import stream_compress, stream_decompress
2+
3+
def cmdline_main():
4+
"""This method is what is run when invoking snappy via the commandline.
5+
Try python -m snappy --help
6+
"""
7+
import sys
8+
if (len(sys.argv) < 2 or len(sys.argv) > 4 or "--help" in sys.argv or
9+
"-h" in sys.argv or sys.argv[1] not in ("-c", "-d")):
10+
print("Usage: python -m snappy <-c/-d> [src [dst]]")
11+
print(" -c compress")
12+
print(" -d decompress")
13+
print("output is stdout if dst is omitted or '-'")
14+
print("input is stdin if src and dst are omitted or src is '-'.")
15+
sys.exit(1)
16+
17+
if len(sys.argv) >= 4 and sys.argv[3] != "-":
18+
dst = open(sys.argv[3], "wb")
19+
elif hasattr(sys.stdout, 'buffer'):
20+
dst = sys.stdout.buffer
21+
else:
22+
dst = sys.stdout
23+
24+
if len(sys.argv) >= 3 and sys.argv[2] != "-":
25+
src = open(sys.argv[2], "rb")
26+
elif hasattr(sys.stdin, "buffer"):
27+
src = sys.stdin.buffer
28+
else:
29+
src = sys.stdin
30+
31+
if sys.argv[1] == "-c":
32+
method = stream_compress
33+
else:
34+
method = stream_decompress
35+
36+
method(src, dst)
37+
38+
39+
if __name__ == "__main__":
40+
cmdline_main()
File renamed without changes.
File renamed without changes.

snappy.py renamed to snappy/snappy.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -287,43 +287,3 @@ def stream_decompress(src, dst, blocksize=_STREAM_TO_STREAM_BLOCK_SIZE):
287287
buf = decompressor.decompress(buf)
288288
if buf: dst.write(buf)
289289
decompressor.flush() # makes sure the stream ended well
290-
291-
292-
def cmdline_main():
293-
"""This method is what is run when invoking snappy via the commandline.
294-
Try python -m snappy --help
295-
"""
296-
import sys
297-
if (len(sys.argv) < 2 or len(sys.argv) > 4 or "--help" in sys.argv or
298-
"-h" in sys.argv or sys.argv[1] not in ("-c", "-d")):
299-
print("Usage: python -m snappy <-c/-d> [src [dst]]")
300-
print(" -c compress")
301-
print(" -d decompress")
302-
print("output is stdout if dst is omitted or '-'")
303-
print("input is stdin if src and dst are omitted or src is '-'.")
304-
sys.exit(1)
305-
306-
if len(sys.argv) >= 4 and sys.argv[3] != "-":
307-
dst = open(sys.argv[3], "wb")
308-
elif hasattr(sys.stdout, 'buffer'):
309-
dst = sys.stdout.buffer
310-
else:
311-
dst = sys.stdout
312-
313-
if len(sys.argv) >= 3 and sys.argv[2] != "-":
314-
src = open(sys.argv[2], "rb")
315-
elif hasattr(sys.stdin, "buffer"):
316-
src = sys.stdin.buffer
317-
else:
318-
src = sys.stdin
319-
320-
if sys.argv[1] == "-c":
321-
method = stream_compress
322-
else:
323-
method = stream_decompress
324-
325-
method(src, dst)
326-
327-
328-
if __name__ == "__main__":
329-
cmdline_main()
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)