Skip to content

Commit

Permalink
breaking: add 'google_' prefix to import name (#30)
Browse files Browse the repository at this point in the history
Avoid conflict with ICRAR version.

Closes: #29
  • Loading branch information
tseaver committed Aug 7, 2020
1 parent df14cec commit b50f43e
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
@@ -1,3 +1,3 @@
[submodule "crc32c"]
path = crc32c
path = google_crc32c
url = https://github.com/google/crc32c
2 changes: 1 addition & 1 deletion MANIFEST.in
@@ -1 +1 @@
include src/crc32c_build.py
include src/google_crc32c_build.py
18 changes: 9 additions & 9 deletions README.md
Expand Up @@ -84,17 +84,17 @@ On OS X:
$ ./scripts/osx/check.sh
...
+ venv37/bin/python .../python-crc32c/check_cffi_crc32c.py
_crc32c_cffi: <module 'crc32c._crc32c_cffi' from '.../python-crc32c/venv37/lib/python3.7/site-packages/crc32c/_crc32c_cffi.abi3.so'>
_crc32c_cffi.lib: <Lib object for 'crc32c._crc32c_cffi'>
_crc32c_cffi: <module 'google_crc32c._crc32c_cffi' from '.../python-crc32c/venv37/lib/python3.7/site-packages/google_crc32c/_crc32c_cffi.abi3.so'>
_crc32c_cffi.lib: <Lib object for 'google_crc32c._crc32c_cffi'>
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
...
```

Expand All @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_cffi_crc32c.py
Expand Up @@ -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():
Expand Down
3 changes: 1 addition & 2 deletions scripts/dev-requirements.txt
Expand Up @@ -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
7 changes: 3 additions & 4 deletions scripts/local-linux/build_libcrc32c.sh
Expand Up @@ -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 \
Expand All @@ -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}
4 changes: 2 additions & 2 deletions scripts/manylinux/build_on_centos.sh
Expand Up @@ -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 \
Expand Down Expand Up @@ -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/
5 changes: 2 additions & 3 deletions scripts/manylinux/check.sh
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions scripts/osx/build_c_lib.sh
Expand Up @@ -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

Expand All @@ -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}
8 changes: 4 additions & 4 deletions scripts/windows/build.bat
Expand Up @@ -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

Expand All @@ -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 (
Expand All @@ -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

Expand All @@ -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 (
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Expand Up @@ -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)
Expand All @@ -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 [],
Expand Down
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/crc32c/__init__.py → src/google_crc32c/__init__.py
Expand Up @@ -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
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions src/crc32c/cffi.py → src/google_crc32c/cffi.py
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/crc32c/python.py → src/google_crc32c/python.py
Expand Up @@ -15,7 +15,7 @@
import array
import struct

from crc32c._checksum import CommonChecksum
from google_crc32c._checksum import CommonChecksum


def extend(crc, chunk):
Expand Down
2 changes: 1 addition & 1 deletion src/crc32c_build.py → src/google_crc32c_build.py
Expand Up @@ -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()
Expand Down

0 comments on commit b50f43e

Please sign in to comment.