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
144 changes: 47 additions & 97 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,123 +7,73 @@ on:

jobs:

Linux:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Get tag
id: tag
run: |
echo ::set-output name=tag::${GITHUB_REF#refs/tags/}
- name: Building release
run: |
make linux_release
- name: Upload distributions artifacts
uses: actions/upload-artifact@v2
with:
name: pendulum-dist
path: dist/wheelhouse

MacOS:
runs-on: macos-latest
build:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10"]
os: [ ubuntu, windows, macos ]

steps:
- uses: actions/checkout@v2
- name: Get tag
id: tag
run: |
echo ::set-output name=tag::${GITHUB_REF#refs/tags/}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install and set up Poetry
run: |
curl -fsS https://install.python-poetry.org | python - --preview -y
- name: Build distributions
run: |
source $HOME/.poetry/env
poetry build -vvv
- name: Upload distribution artifacts
uses: actions/upload-artifact@v2
with:
name: pendulum-dist
path: dist

Windows:
runs-on: windows-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10"]
- uses: actions/checkout@v3

steps:
- uses: actions/checkout@v2
- name: Get tag
id: tag
shell: bash
run: |
echo ::set-output name=tag::${GITHUB_REF#refs/tags/}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install and setup Poetry
run: |
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python - --preview -y
- name: Build distributions
run: |
$env:Path += ";$env:Userprofile\.poetry\bin"
poetry build -vvv
- name: Upload distribution artifact
uses: actions/upload-artifact@v2
with:
name: pendulum-dist
path: dist
- name: Build wheels
uses: pypa/cibuildwheel@v2.10.1
env:
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.7"
with:
package-dir: .
output-dir: dist

- uses: actions/upload-artifact@v3
with:
name: dist
path: ./dist/*

Release:
needs: [Linux, MacOS, Windows]
needs: [ build-wheel ]
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get tag
id: tag
run: |
echo ::set-output name=tag::${GITHUB_REF#refs/tags/}
- name: Download distribution artifact
uses: actions/download-artifact@master

- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: pendulum-dist
name: dist
path: dist
- name: Install and set up Poetry

- name: Install Poetry
run: |
curl -fsS https://install.python-poetry.org | python - --preview -y
- name: Set up cache
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
curl -fsS https://install.python-poetry.org | python - -y

- name: Update PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Build sdist
run: poetry build --format sdist

- name: Check distributions
run: |
ls -la dist

- name: Check Version
id: check-version
run: |
[[ "${GITHUB_REF#refs/tags/}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] \
|| echo ::set-output name=prerelease::true

- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: "dist/*"
token: ${{ secrets.GITHUB_TOKEN }}
draft: false
prerelease: steps.check-version.outputs.prerelease == 'true'

- name: Publish to PyPI
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
run: |
source $HOME/.poetry/env
poetry publish
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
with:
tag_name: ${{ steps.tag.outputs.tag }}
release_name: ${{ steps.tag.outputs.tag }}
draft: false
prerelease: false
86 changes: 17 additions & 69 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,32 @@
import os
import shutil
import sys
import subprocess

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
from distutils.errors import DistutilsPlatformError
from pathlib import Path


# C Extensions
with_extensions = os.getenv("PENDULUM_EXTENSIONS", None)
def meson(*args):
subprocess.call(["meson"] + list(args))

if with_extensions == "1" or with_extensions is None:
with_extensions = True

if with_extensions == "0" or hasattr(sys, "pypy_version_info"):
with_extensions = False
def _build():
build_dir = Path(__file__).parent.joinpath("build")
build_dir.mkdir(parents=True, exist_ok=True)

extensions = []
if with_extensions:
extensions = [
Extension("pendulum._extensions._helpers", ["pendulum/_extensions/_helpers.c"]),
Extension("pendulum.parsing._iso8601", ["pendulum/parsing/_iso8601.c"]),
]


class BuildFailed(Exception):

pass


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(
" 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(
f' Unable to build the "{ext.name}" C extension, '
"Pendulum will use the pure python version of the extension."
)
meson("setup", build_dir.as_posix())
meson("compile", "-C", build_dir.as_posix())
meson("install", "-C", build_dir.as_posix())


def build(setup_kwargs):
"""
This function is mandatory in order to build the extensions.
"""
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
try:
_build()
except Exception:
print(
" Unable to build C extensions, "
"Pendulum will use the pure python version of the extensions."
)


if __name__ == "__main__":
Expand Down
20 changes: 20 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
project('pendulum C extensions', 'c')

py_mod = import('python')
py = py_mod.find_installation()
py_dep = py.dependency()

extensions = [
['_helpers', 'pendulum/_extensions/_helpers.c', meson.source_root() / 'pendulum/_extensions/'],
['_iso8601', 'pendulum/parsing/_iso8601.c', meson.source_root() / 'pendulum/parsing/'],
]

foreach extension : extensions
py.extension_module(
extension[0],
extension[1],
dependencies : py_dep,
install : true,
install_dir: extension[2]
)
endforeach
6 changes: 0 additions & 6 deletions pendulum/parsing/_iso8601.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ Parsed* _parse_iso8601_datetime(char *str, Parsed *parsed) {
int leap = 0;
int separators = 0;
int time = 0;
int has_hour = 0;
int i;
int j;

Expand Down Expand Up @@ -773,7 +772,6 @@ Parsed* _parse_iso8601_datetime(char *str, Parsed *parsed) {
}

parsed->hour = time;
has_hour = 1;
break;
case 4:
// Hours and minutes
Expand All @@ -786,7 +784,6 @@ Parsed* _parse_iso8601_datetime(char *str, Parsed *parsed) {

parsed->hour = time / 100;
parsed->minute = time % 100;
has_hour = 1;
break;
case 6:
// Hours, minutes and seconds
Expand All @@ -800,7 +797,6 @@ Parsed* _parse_iso8601_datetime(char *str, Parsed *parsed) {
parsed->hour = time / 10000;
parsed->minute = time / 100 % 100;
parsed->second = time % 100;
has_hour = 1;
break;
default:
// Any other case is wrong
Expand Down Expand Up @@ -942,7 +938,6 @@ Parsed* _parse_iso8601_duration(char *str, Parsed *parsed) {
int fraction = 0;
int has_ymd = 0;
int has_week = 0;
int has_year = 0;
int has_month = 0;
int has_day = 0;
int has_hour = 0;
Expand Down Expand Up @@ -979,7 +974,6 @@ Parsed* _parse_iso8601_duration(char *str, Parsed *parsed) {
fraction = 0;
in_fraction = 0;
has_ymd = 1;
has_year = 1;

break;
case 'M':
Expand Down
Loading