From b50f43e7bc40d91ccdade9ccc577a93c0ed05f3a Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 7 Aug 2020 16:02:46 -0400 Subject: [PATCH] breaking: add 'google_' prefix to import name (#30) Avoid conflict with ICRAR version. Closes: #29 --- .gitmodules | 2 +- MANIFEST.in | 2 +- README.md | 18 ++++----- crc32c => google_crc32c | 0 noxfile.py | 2 +- scripts/check_cffi_crc32c.py | 2 +- scripts/dev-requirements.txt | 3 +- scripts/local-linux/build_libcrc32c.sh | 7 ++-- scripts/manylinux/build_on_centos.sh | 4 +- scripts/manylinux/check.sh | 5 +-- scripts/osx/build_c_lib.sh | 4 +- scripts/windows/build.bat | 8 ++-- setup.py | 8 ++-- src/{crc32c => google_crc32c}/__config__.py | 2 +- src/{crc32c => google_crc32c}/__init__.py | 6 +-- src/{crc32c => google_crc32c}/_checksum.py | 0 src/{crc32c => google_crc32c}/cffi.py | 10 ++--- src/{crc32c => google_crc32c}/python.py | 2 +- ...crc32c_build.py => google_crc32c_build.py} | 2 +- tests/test___init__.py | 38 +++++++++---------- 20 files changed, 61 insertions(+), 64 deletions(-) rename crc32c => google_crc32c (100%) rename src/{crc32c => google_crc32c}/__config__.py (91%) rename src/{crc32c => google_crc32c}/__init__.py (88%) rename src/{crc32c => google_crc32c}/_checksum.py (100%) rename src/{crc32c => google_crc32c}/cffi.py (88%) rename src/{crc32c => google_crc32c}/python.py (99%) rename src/{crc32c_build.py => google_crc32c_build.py} (98%) diff --git a/.gitmodules b/.gitmodules index 2d3b474a..e7a3a8fb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "crc32c"] - path = crc32c + path = google_crc32c url = https://github.com/google/crc32c diff --git a/MANIFEST.in b/MANIFEST.in index e32c9679..c09d3a53 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -include src/crc32c_build.py \ No newline at end of file +include src/google_crc32c_build.py diff --git a/README.md b/README.md index b63e4055..123d654d 100644 --- a/README.md +++ b/README.md @@ -84,17 +84,17 @@ On OS X: $ ./scripts/osx/check.sh ... + venv37/bin/python .../python-crc32c/check_cffi_crc32c.py -_crc32c_cffi: -_crc32c_cffi.lib: +_crc32c_cffi: +_crc32c_cffi.lib: dir(_crc32c_cffi.lib): ['crc32c_extend', 'crc32c_value'] + /Library/Frameworks/Python.framework/Versions/3.7/bin/delocate-listdeps --all --depending .../python-crc32c/wheels/google_crc32c-0.0.1-cp37-cp37m-macosx_10_6_intel.whl /usr/lib/libSystem.B.dylib: - crc32c/_crc32c_cffi.abi3.so - crc32c/.dylibs/libcrc32c.dylib + google_crc32c/_crc32c_cffi.abi3.so + google_crc32c/.dylibs/libcrc32c.dylib /usr/lib/libc++.1.dylib: - crc32c/.dylibs/libcrc32c.dylib + google_crc32c/.dylibs/libcrc32c.dylib @loader_path/.dylibs/libcrc32c.dylib: - crc32c/_crc32c_cffi.abi3.so + google_crc32c/_crc32c_cffi.abi3.so ... ``` @@ -111,13 +111,13 @@ library using `cmake` / `make`: ```bash $ cd python-crc32c $ git submodule update --init --recursive -$ python -m virtualenv venv +$ python -m venv venv $ venv/bin/pip install --upgrade setuptools pip wheel $ venv/bin/pip install cmake $ mkdir usr $ export CRC32C_INSTALL_PREFIX=$(pwd)/usr -$ mkdir crc32c/build -$ cd crc32c/build +$ mkdir google_crc32c/build +$ cd google_crc32c/build $ ../../venv/bin/cmake \ > -DCRC32C_BUILD_TESTS=no \ > -DCRC32C_BUILD_BENCHMARKS=no \ diff --git a/crc32c b/google_crc32c similarity index 100% rename from crc32c rename to google_crc32c diff --git a/noxfile.py b/noxfile.py index 2342db78..ac82bb7e 100644 --- a/noxfile.py +++ b/noxfile.py @@ -26,7 +26,7 @@ def build_libcrc32c(session): if platform.startswith("win"): session.run("cmd", "-c", "scripts\\windows\\build.bat") elif platform == "linux": - session.run("bash", "scripts/local-linux/build.sh") + session.run("bash", "scripts/local-linux/build_libcrc32c.sh") elif platform == "darwin": session.run("bash", "scripts/osx/build.sh") else: diff --git a/scripts/check_cffi_crc32c.py b/scripts/check_cffi_crc32c.py index da7496d6..a8f59277 100644 --- a/scripts/check_cffi_crc32c.py +++ b/scripts/check_cffi_crc32c.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from crc32c import _crc32c_cffi +from google_crc32c import _crc32c_cffi def main(): diff --git a/scripts/dev-requirements.txt b/scripts/dev-requirements.txt index d12855b2..b58f1c24 100644 --- a/scripts/dev-requirements.txt +++ b/scripts/dev-requirements.txt @@ -2,6 +2,5 @@ auditwheel >= 2.1.1; sys_platform == 'linux' or sys_platform == 'linux2' cffi >= 1.13.2 delocate >= 0.8.0; sys_platform == 'darwin' setuptools >= 42.0.2 -virtualenv >= 16.7. # See: https://github.com/pypa/auditwheel/issues/102 -wheel < 0.32.0, >= 0.31.1 +wheel >= 0.34 diff --git a/scripts/local-linux/build_libcrc32c.sh b/scripts/local-linux/build_libcrc32c.sh index a95cdf1c..63508433 100644 --- a/scripts/local-linux/build_libcrc32c.sh +++ b/scripts/local-linux/build_libcrc32c.sh @@ -26,12 +26,11 @@ CRC32C_INSTALL_PREFIX=${REPO_ROOT}/usr # NOTE: This assumes the local install has an up-to-date `pip`. # Create a virtualenv where we can install `cmake`. -${PY_BIN} -m pip install --upgrade virtualenv VENV=${REPO_ROOT}/venv -${PY_BIN} -m virtualenv ${VENV} +${PY_BIN} -m venv ${VENV} ${VENV}/bin/python -m pip install "cmake >= 3.12.0" # Build `libcrc32c` -cd ${REPO_ROOT}/crc32c +cd ${REPO_ROOT}/google_crc32c mkdir build cd build/ ${VENV}/bin/cmake \ @@ -44,5 +43,5 @@ ${VENV}/bin/cmake \ make all install # Clean up. -rm -fr ${REPO_ROOT}/crc32c/build +rm -fr ${REPO_ROOT}/google_crc32c/build rm -fr ${VENV} diff --git a/scripts/manylinux/build_on_centos.sh b/scripts/manylinux/build_on_centos.sh index cee0cadf..3c94d17a 100755 --- a/scripts/manylinux/build_on_centos.sh +++ b/scripts/manylinux/build_on_centos.sh @@ -26,7 +26,7 @@ ${MAIN_PYTHON_BIN}/python -m pip install \ --requirement /var/code/python-crc32c/scripts/dev-requirements.txt # Build and install `crc32c` -cd /var/code/python-crc32c/crc32c/ +cd /var/code/python-crc32c/google_crc32c/ mkdir build cd build/ ${MAIN_PYTHON_BIN}/cmake \ @@ -73,5 +73,5 @@ for whl in dist_wheels/google_crc32c*.whl; do done # Clean up. -rm -fr /var/code/python-crc32c/crc32c/build/ +rm -fr /var/code/python-crc32c/google_crc32c/build/ rm -fr /var/code/python-crc32c/dist_wheels/ diff --git a/scripts/manylinux/check.sh b/scripts/manylinux/check.sh index a67f8eab..339deb9a 100755 --- a/scripts/manylinux/check.sh +++ b/scripts/manylinux/check.sh @@ -28,11 +28,10 @@ PYTHON=python3.6 pyenv local 3.6.1 # Make sure we can create a virtual environment. -${PYTHON} -m pip install --upgrade pip -${PYTHON} -m pip install --upgrade virtualenv wheel +${PYTHON} -m pip install --upgrade setuptools pip wheel # Create a virtual environment. -${PYTHON} -m virtualenv venv +${PYTHON} -m venv venv # Install the wheel. venv/bin/pip install ${WHEEL_FILE} diff --git a/scripts/osx/build_c_lib.sh b/scripts/osx/build_c_lib.sh index f31a644d..1ad725af 100755 --- a/scripts/osx/build_c_lib.sh +++ b/scripts/osx/build_c_lib.sh @@ -52,7 +52,7 @@ ${VENV}/bin/python -m pip install --upgrade pip ${VENV}/bin/python -m pip install "cmake >= 3.12.0" # Build `libcrc32c` -cd ${REPO_ROOT}/crc32c +cd ${REPO_ROOT}/google_crc32c mkdir -p build ls @@ -71,5 +71,5 @@ ${VENV}/bin/cmake \ make all install # Clean up. -rm -fr ${REPO_ROOT}/crc32c/build +rm -fr ${REPO_ROOT}/google_crc32c/build rm -fr ${VENV} diff --git a/scripts/windows/build.bat b/scripts/windows/build.bat index b8ed4b4a..3801c0c6 100644 --- a/scripts/windows/build.bat +++ b/scripts/windows/build.bat @@ -32,7 +32,7 @@ set CRC32C_INSTALL_PREFIX=%KOKORO_ARTIFACTS_DIR%\bin_win64\ echo %CRC32C_INSTALL_PREFIX% -pushd crc32c +pushd google_crc32c git submodule update --init --recursive mkdir build @@ -46,7 +46,7 @@ C:\Python37\Scripts\cmake --build . --config RelWithDebInfo --target install dir %CRC32C_INSTALL_PREFIX% /b /s popd -copy %CRC32C_INSTALL_PREFIX%bin\crc32c.dll . +copy %CRC32C_INSTALL_PREFIX%bin\google_crc32c.dll . @rem update python deps and build wheels (requires CRC32C_INSTALL_PREFIX is set) FOR %%V IN (3.5-64,3.6-64,3.7-64) DO ( @@ -59,7 +59,7 @@ FOR %%V IN (3.5-64,3.6-64,3.7-64) DO ( @REM removed -DCRC32C_BUILD_TESTS=no set CMAKE_GENERATOR="Visual Studio 15 2017" -pushd crc32c +pushd google_crc32c @rem reset hard to cleanup any changes done by 64-bit build. git reset --hard @@ -74,7 +74,7 @@ C:\Python37\Scripts\cmake --build . --config RelWithDebInfo --target install dir %CRC32C_INSTALL_PREFIX% /b /s popd -copy %CRC32C_INSTALL_PREFIX%bin\crc32c.dll . +copy %CRC32C_INSTALL_PREFIX%bin\google_crc32c.dll . @rem update python deps and build wheels (requires CRC32C_INSTALL_PREFIX is set) FOR %%V IN (3.5-32,3.6-32,3.7-32) DO ( diff --git a/setup.py b/setup.py index 3230a163..e2496fac 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ def copy_dll(build_lib): return installed_dll = os.path.join(install_prefix, "bin", _DLL_FILENAME) - lib_dlls = os.path.join(build_lib, "crc32c", _EXTRA_DLL) + lib_dlls = os.path.join(build_lib, "google_crc32c", _EXTRA_DLL) os.makedirs(lib_dlls) relocated_dll = os.path.join(lib_dlls, _DLL_FILENAME) shutil.copyfile(installed_dll, relocated_dll) @@ -47,14 +47,14 @@ def run(self): def main(build_cffi=True): - build_path = os.path.join("src", "crc32c_build.py") + build_path = os.path.join("src", "google_crc32c_build.py") builder = "{}:FFIBUILDER".format(build_path) cffi_dep = "cffi >= 1.0.0" setuptools.setup( - packages=["crc32c"], + packages=["google_crc32c"], package_dir={"": "src"}, - package_data={"crc32c": [os.path.join(_EXTRA_DLL, _DLL_FILENAME)]}, + package_data={"google_crc32c": [os.path.join(_EXTRA_DLL, _DLL_FILENAME)]}, setup_requires=[cffi_dep] if build_cffi else [], cffi_modules=[builder] if build_cffi else [], install_requires=[cffi_dep] if build_cffi else [], diff --git a/src/crc32c/__config__.py b/src/google_crc32c/__config__.py similarity index 91% rename from src/crc32c/__config__.py rename to src/google_crc32c/__config__.py index 5912bbea..7a3642e7 100644 --- a/src/crc32c/__config__.py +++ b/src/google_crc32c/__config__.py @@ -28,7 +28,7 @@ def modify_path(): return try: - extra_dll_dir = pkg_resources.resource_filename("crc32c", "extra-dll") + extra_dll_dir = pkg_resources.resource_filename("google_crc32c", "extra-dll") if os.path.isdir(extra_dll_dir): os.environ["PATH"] = path + os.pathsep + extra_dll_dir except ImportError: diff --git a/src/crc32c/__init__.py b/src/google_crc32c/__init__.py similarity index 88% rename from src/crc32c/__init__.py rename to src/google_crc32c/__init__.py index b44591c9..1e1c0649 100644 --- a/src/crc32c/__init__.py +++ b/src/google_crc32c/__init__.py @@ -22,11 +22,11 @@ # If available, default to CFFI Implementation, otherwise, use pure python. try: - from crc32c import cffi as _crc32c + from google_crc32c import cffi as _crc32c implementation = "cffi" except ImportError: - from crc32c import python as _crc32c - warnings.warn(RuntimeWarning, "_SLOW_CRC32C_WARNING",) + from google_crc32c import python as _crc32c + warnings.warn(_SLOW_CRC32C_WARNING, RuntimeWarning) implementation = "python" extend = _crc32c.extend diff --git a/src/crc32c/_checksum.py b/src/google_crc32c/_checksum.py similarity index 100% rename from src/crc32c/_checksum.py rename to src/google_crc32c/_checksum.py diff --git a/src/crc32c/cffi.py b/src/google_crc32c/cffi.py similarity index 88% rename from src/crc32c/cffi.py rename to src/google_crc32c/cffi.py index a2899f15..2de1dc39 100644 --- a/src/crc32c/cffi.py +++ b/src/google_crc32c/cffi.py @@ -16,9 +16,9 @@ # NOTE: ``__config__`` **must** be the first import because it (may) # modify the search path used to locate shared libraries. -import crc32c.__config__ -import crc32c._crc32c_cffi -from crc32c._checksum import CommonChecksum +import google_crc32c.__config__ +import google_crc32c._crc32c_cffi +from google_crc32c._checksum import CommonChecksum def extend(crc, chunk): @@ -33,7 +33,7 @@ def extend(crc, chunk): int: New CRC checksum computed by extending existing CRC with ``chunk``. """ - return crc32c._crc32c_cffi.lib.crc32c_extend(crc, chunk, len(chunk)) + return google_crc32c._crc32c_cffi.lib.crc32c_extend(crc, chunk, len(chunk)) def value(chunk): @@ -46,7 +46,7 @@ def value(chunk): Returns int: New CRC checksum computed for ``chunk``. """ - return crc32c._crc32c_cffi.lib.crc32c_value(chunk, len(chunk)) + return google_crc32c._crc32c_cffi.lib.crc32c_value(chunk, len(chunk)) class Checksum(CommonChecksum): diff --git a/src/crc32c/python.py b/src/google_crc32c/python.py similarity index 99% rename from src/crc32c/python.py rename to src/google_crc32c/python.py index 9746b694..0ab5f353 100644 --- a/src/crc32c/python.py +++ b/src/google_crc32c/python.py @@ -15,7 +15,7 @@ import array import struct -from crc32c._checksum import CommonChecksum +from google_crc32c._checksum import CommonChecksum def extend(crc, chunk): diff --git a/src/crc32c_build.py b/src/google_crc32c_build.py similarity index 98% rename from src/crc32c_build.py rename to src/google_crc32c_build.py index 059463ee..77796cfb 100644 --- a/src/crc32c_build.py +++ b/src/google_crc32c_build.py @@ -47,7 +47,7 @@ def get_kwargs(): FFIBUILDER = cffi.FFI() FFIBUILDER.cdef(_HEADER) FFIBUILDER.set_source( - "crc32c._crc32c_cffi", + "google_crc32c._crc32c_cffi", '#include "crc32c/crc32c.h"', libraries=["crc32c"], **get_kwargs() diff --git a/tests/test___init__.py b/tests/test___init__.py index b71791c0..8df1a8c0 100644 --- a/tests/test___init__.py +++ b/tests/test___init__.py @@ -17,7 +17,7 @@ import pytest -import crc32c +import google_crc32c EMPTY = b"" EMPTY_CRC = 0x00000000 @@ -171,25 +171,25 @@ def iscsi_chunks(chunksize): def test_extend_w_empty_chunk(): crc = 123 - assert crc32c.extend(crc, b"") == crc + assert google_crc32c.extend(crc, b"") == crc def test_extend_w_multiple_chunks(): crc = 0 for chunk in iscsi_chunks(7): - crc = crc32c.extend(crc, chunk) + crc = google_crc32c.extend(crc, chunk) assert crc == ISCSI_CRC def test_extend_w_reduce(): - assert functools.reduce(crc32c.extend, iscsi_chunks(3), 0) == ISCSI_CRC + assert functools.reduce(google_crc32c.extend, iscsi_chunks(3), 0) == ISCSI_CRC @pytest.mark.parametrize("chunk, expected", _EXPECTED) def test_value(chunk, expected): - assert crc32c.value(chunk) == expected + assert google_crc32c.value(chunk) == expected def pytest_generate_tests(metafunc): @@ -199,10 +199,10 @@ def pytest_generate_tests(metafunc): @pytest.fixture def _crc32c(request): if request.param == "python": - from crc32c import python + from google_crc32c import python return python elif request.param == "cffi": - from crc32c import cffi + from google_crc32c import cffi return cffi else: raise ValueError("invalid internal test config") @@ -211,25 +211,25 @@ def _crc32c(request): class TestChecksum(object): @staticmethod def test_ctor_defaults(_crc32c): - helper = crc32c.Checksum() + helper = google_crc32c.Checksum() assert helper._crc == 0 @staticmethod def test_ctor_explicit(_crc32c): chunk = b"DEADBEEF" - helper = crc32c.Checksum(chunk) - assert helper._crc == crc32c.value(chunk) + helper = google_crc32c.Checksum(chunk) + assert helper._crc == google_crc32c.value(chunk) @staticmethod def test_update(_crc32c): chunk = b"DEADBEEF" - helper = crc32c.Checksum() + helper = google_crc32c.Checksum() helper.update(chunk) - assert helper._crc == crc32c.value(chunk) + assert helper._crc == google_crc32c.value(chunk) @staticmethod def test_update_w_multiple_chunks(_crc32c): - helper = crc32c.Checksum() + helper = google_crc32c.Checksum() for index in itertools.islice(range(ISCSI_LENGTH), 0, None, 7): chunk = ISCSI_SCSI_READ_10_COMMAND_PDU[index : index + 7] @@ -239,30 +239,30 @@ def test_update_w_multiple_chunks(_crc32c): @staticmethod def test_digest_zero(_crc32c): - helper = crc32c.Checksum() + helper = google_crc32c.Checksum() assert helper.digest() == b"\x00" * 4 @staticmethod def test_digest_nonzero(_crc32c): - helper = crc32c.Checksum() + helper = google_crc32c.Checksum() helper._crc = 0x01020304 assert helper.digest() == b"\x01\x02\x03\x04" @staticmethod def test_hexdigest_zero(_crc32c): - helper = crc32c.Checksum() + helper = google_crc32c.Checksum() assert helper.hexdigest() == b"00" * 4 @staticmethod def test_hexdigest_nonzero(_crc32c): - helper = crc32c.Checksum() + helper = google_crc32c.Checksum() helper._crc = 0x091A3B2C assert helper.hexdigest() == b"091a3b2c" @staticmethod def test_copy(_crc32c): chunk = b"DEADBEEF" - helper = crc32c.Checksum(chunk) + helper = google_crc32c.Checksum(chunk) clone = helper.copy() before = helper._crc helper.update(b"FACEDACE") @@ -271,7 +271,7 @@ def test_copy(_crc32c): @staticmethod @pytest.mark.parametrize("chunksize", [1, 3, 5, 7, 11, 13, ISCSI_LENGTH]) def test_consume_stream(_crc32c, chunksize): - helper = crc32c.Checksum() + helper = google_crc32c.Checksum() expected = list(iscsi_chunks(chunksize)) stream = mock.Mock(spec=["read"]) stream.read.side_effect = expected + [b""]