Skip to content

Commit

Permalink
fix: advise setting 'CRC32C_PURE_PYTHON' after build failure (#84)
Browse files Browse the repository at this point in the history
Set 'CRC32C_PURE_PYTHON=0' during CI.

Toward #83.
  • Loading branch information
tseaver committed Sep 1, 2021
1 parent db70646 commit 6aa1cd6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/presubmit.yml
Expand Up @@ -44,6 +44,7 @@ jobs:
- name: Build
env:
BUILD_PYTHON: ${{ matrix.python }}
CRC32C_PURE_PYTHON: "0"
run: |
./scripts/manylinux/build.sh
- name: Test Import
Expand Down Expand Up @@ -78,6 +79,8 @@ jobs:
run: |
python -m pip install --upgrade setuptools pip wheel
- name: Build
env:
CRC32C_PURE_PYTHON: "0"
run: |
./scripts/osx/build_gh_action.sh
- name: Test Import
Expand Down Expand Up @@ -117,6 +120,8 @@ jobs:
run: |
python -m pip install --upgrade setuptools pip wheel
- name: Build
env:
CRC32C_PURE_PYTHON: "0"
run: |
where python
./scripts/windows/build.bat ${{ matrix.python }}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/python-publish.yml
Expand Up @@ -37,6 +37,7 @@ jobs:
- name: Build
env:
BUILD_PYTHON: ${{ matrix.python }}
CRC32C_PURE_PYTHON: "0"
run: |
./scripts/manylinux/build.sh
- name: Test Import
Expand Down Expand Up @@ -68,6 +69,8 @@ jobs:
python -m pip install --upgrade pip
pip install setuptools wheel
- name: Build
env:
CRC32C_PURE_PYTHON: "0"
run: |
./scripts/osx/build_gh_action.sh
- name: Test Import
Expand Down Expand Up @@ -104,6 +107,8 @@ jobs:
python -m pip install --upgrade pip
pip install setuptools wheel
- name: Build
env:
CRC32C_PURE_PYTHON: "0"
run: |
where python
./scripts/windows/build.bat ${{ matrix.python }}
Expand Down
41 changes: 29 additions & 12 deletions setup.py
Expand Up @@ -12,15 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
import shutil
import setuptools
import setuptools.command.build_ext
import warnings

_EXTRA_DLL = "extra-dll"
_DLL_FILENAME = "crc32c.dll"
CRC32C_PURE_PYTHON = os.getenv("CRC32C_PURE_PYTHON") is not None

# Explicit environment variable disables pure-Python fallback
CRC32C_PURE_PYTHON_EXPLICIT = "CRC32C_PURE_PYTHON" in os.environ
_FALSE_OPTIONS = ("0", "false", "no", "False", "No", None)
CRC32C_PURE_PYTHON = os.getenv("CRC32C_PURE_PYTHON") not in _FALSE_OPTIONS


def copy_dll(build_lib):
Expand Down Expand Up @@ -54,14 +58,27 @@ def run(self):


if CRC32C_PURE_PYTHON:
ext_modules = []
setuptools.setup(
packages=["google_crc32c"],
package_dir={"": "src"},
ext_modules=[],
)
else:
ext_modules = [module]


setuptools.setup(
packages=["google_crc32c"],
package_dir={"": "src"},
ext_modules=ext_modules,
cmdclass={"build_ext": BuildExtWithDLL},
)
try:
setuptools.setup(
packages=["google_crc32c"],
package_dir={"": "src"},
ext_modules=[module],
cmdclass={"build_ext": BuildExtWithDLL},
)
except SystemExit:
if "CRC32C_PURE_PYTHON" not in os.environ:
# If build / install fails, it is likely a compilation error with
# the C extension: advise user how to enable the pure-Python
# build.
logging.error(
"Compiling the C Extension for the crc32c library failed. "
"To enable building / installing a pure-Python-only version, "
"set 'CRC32C_PURE_PYTHON=1' in the environment."
)
raise

0 comments on commit 6aa1cd6

Please sign in to comment.