Skip to content

Fix #46: Add __version__ #119

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

Merged
merged 1 commit into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 11 additions & 9 deletions src/snappy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from __future__ import absolute_import

from .snappy import (
compress,
decompress,
uncompress,
stream_compress,
stream_decompress,
StreamCompressor,
StreamDecompressor,
UncompressError,
isValidCompressed,
compress,
decompress,
uncompress,
stream_compress,
stream_decompress,
StreamCompressor,
StreamDecompressor,
UncompressError,
isValidCompressed,
)

from .hadoop_snappy import (
stream_compress as hadoop_stream_compress,
stream_decompress as hadoop_stream_decompress,
)

__version__ = '0.6.1'
5 changes: 0 additions & 5 deletions src/snappy/snappymodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <snappy-c.h>
#include "crc32c.h"

#define MODULE_VERSION "0.4.1"
Copy link
Member

Choose a reason for hiding this comment

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

Note: this incorrect string is currently available as snappy._snappy.__version__

#define RESIZE_TOLERATION 0.75

struct module_state {
Expand Down Expand Up @@ -306,10 +305,6 @@ init_snappy(void)
SnappyInvalidCompressedInputError);
PyModule_AddObject(m, "CompressedLengthError", SnappyCompressedLengthError);

/* Version = MODULE_VERSION */
if (PyModule_AddStringConstant(m, "__version__", MODULE_VERSION))
INITERROR;

#if PY_MAJOR_VERSION >= 3
return m;
#endif
Expand Down
9 changes: 9 additions & 0 deletions test_snappy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
from unittest import TestCase


class SnappyModuleTest(TestCase):
def test_version(self):
assert tuple(map(int, snappy.__version__.split("."))) >= (0, 6, 1)
# Make sure that __version__ is identical to the version defined in setup.py
Copy link
Member

Choose a reason for hiding this comment

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

It is good to test that it is the same, as it should be. Some projects use external tools like versioneer or poetry to keep these in sync. Here, it would be manual.

with open(os.path.join(os.path.dirname(__file__), "setup.py")) as f:
version_line, = (l for l in f.read().splitlines() if l.startswith("version"))
assert version_line.split("=")[1].strip(" '\"") == snappy.__version__


class SnappyCompressionTest(TestCase):
def test_simple_compress(self):
text = "hello world!".encode('utf-8')
Expand Down