Skip to content
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
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Install dependencies
run: |
source $HOME/.poetry/env
poetry install
poetry install -vvv
- name: Test Pure Python
run: |
source $HOME/.poetry/env
Expand All @@ -67,7 +67,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, pypy2, pypy3]
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, pypy3]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
- name: Install dependencies
run: |
source $HOME/.poetry/env
poetry install
poetry install -vvv
- name: Test Pure Python
run: |
source $HOME/.poetry/env
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
- name: Install dependencies
run: |
$env:Path += ";$env:Userprofile\.poetry\bin"
poetry install
poetry install -vvv
- name: Test Pure Python
run: |
$env:Path += ";$env:Userprofile\.poetry\bin"
Expand Down
46 changes: 37 additions & 9 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import shutil
import sys

from distutils.command.build_ext import build_ext
from distutils.core import Distribution
from distutils.core import Extension
from distutils.errors import CCompilerError
from distutils.errors import DistutilsExecError
Expand Down Expand Up @@ -33,27 +35,53 @@ class BuildFailed(Exception):
class ExtBuilder(build_ext):
# This class allows C extension building to fail.

built_extensions = []

def run(self):
try:
build_ext.run(self)
except (DistutilsPlatformError, FileNotFoundError):
print("************************************************************")
print("Cannot compile C accelerator module, use pure python version")
print("************************************************************")
print(
" Unable to build the C extensions, "
"Pendulum will use the pure python code instead."
)

def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except (CCompilerError, DistutilsExecError, DistutilsPlatformError, ValueError):
print("************************************************************")
print("Cannot compile C accelerator module, use pure python version")
print("************************************************************")
print(
' Unable to build the "{}" C extension, '
"Pendulum will use the pure python version of the extension.".format(
ext.name
)
)


def build(setup_kwargs):
"""
This function is mandatory in order to build the extensions.
"""
setup_kwargs.update(
{"ext_modules": extensions, "cmdclass": {"build_ext": ExtBuilder}}
)
distribution = Distribution({"name": "pendulum", "ext_modules": extensions})
distribution.package_dir = "pendulum"

cmd = ExtBuilder(distribution)
cmd.ensure_finalized()
cmd.run()

# Copy built extensions back to the project
for output in cmd.get_outputs():
relative_extension = os.path.relpath(output, cmd.build_lib)
if not os.path.exists(output):
continue

shutil.copyfile(output, relative_extension)
mode = os.stat(relative_extension).st_mode
mode |= (mode & 0o444) >> 2
os.chmod(relative_extension, mode)

return setup_kwargs


if __name__ == "__main__":
build({})
Loading