Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: advise setting 'CRC32C_PURE_PYTHON' after build failure #84

Merged
merged 4 commits into from
Sep 1, 2021
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
5 changes: 5 additions & 0 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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