Skip to content

Commit

Permalink
Update build tools (#5)
Browse files Browse the repository at this point in the history
* update build tools

* try to fix docs

* fix regex

* fetch tags for setuptools-scm
  • Loading branch information
zariiii9003 authored Oct 9, 2024
1 parent 2ca859d commit a3e1586
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 66 deletions.
29 changes: 14 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,37 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch tags for setuptools-scm
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --pre tox
allow-prereleases: true
- name: Test with tox
run: |
tox -e py
pipx run tox -e py
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch tags for setuptools-scm

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r doc/doc-requirements.txt
pipx run build --sdist
- name: Build documentation
run: |
python -m sphinx -W -an doc build
- uses: actions/upload-artifact@v3
with:
name: sphinx-out
path: ./build/
retention-days: 5
52 changes: 28 additions & 24 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,61 +12,65 @@ env:

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest]

name: Build wheels
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch tags for setuptools-scm

# Used to host cibuildwheel
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install cibuildwheel
run: python -m pip install cibuildwheel
python-version: "3.12"

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
run: pipx run cibuildwheel --output-dir wheelhouse

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-windows-latest
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch tags for setuptools-scm

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"

- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: dist/*.tar.gz

upload_pypi:
name: Create release
needs: [ build_wheels, build_sdist ]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/win-precise-time
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
contents: write # for action-gh-release

# upload to PyPI only on release
if: github.event.release && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: artifact
pattern: cibw-*
path: dist
merge-multiple: true

- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,5 @@ dmypy.json
# IDEs
/.idea/
/.vscode/

/src/win_precise_time/_version.py
5 changes: 4 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.10"
python: "3.12"
jobs:
post_install:
- python -m build --sdist

# Build documentation in the docs/ directory with Sphinx
sphinx:
Expand Down
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.15...3.26)
project(${SKBUILD_PROJECT_NAME} LANGUAGES C)

find_package(Python
REQUIRED
COMPONENTS
Interpreter
Development.Module
${SKBUILD_SABI_COMPONENT})

python_add_library(_t
MODULE
${CMAKE_SOURCE_DIR}/src/win_precise_time/_t.c
WITH_SOABI)

install(TARGETS _t LIBRARY DESTINATION win_precise_time)
6 changes: 4 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
copyright = "2022, Artur Drogunow"
author = "Artur Drogunow"

with open("../src/win_precise_time/__init__.py", "r", encoding="utf-8") as f:
with open("../src/win_precise_time/_version.py", "r", encoding="utf-8") as f:
__version__ = re.search(
r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE
r'^__version__\s*=(?:\s*version\s*=)?\s*[\'"]([^\'"]*)[\'"]',
f.read(),
re.MULTILINE,
).group(1)

version = __version__.split("-", maxsplit=1)[0]
Expand Down
1 change: 1 addition & 0 deletions doc/doc-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
sphinx>=5.2.3
furo
build
13 changes: 9 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
build-backend = 'setuptools.build_meta'
requires = ["setuptools >= 62.0"]
requires = ["scikit-build-core"]
build-backend = "scikit_build_core.build"

[project]
name = "win-precise-time"
Expand Down Expand Up @@ -34,8 +34,13 @@ Issues = "https://github.com/zariiii9003/win-precise-time/issues"
Source = "https://github.com/zariiii9003/win-precise-time"
Homepage = "https://github.com/zariiii9003/win-precise-time"

[tool.setuptools.dynamic]
version = {attr = "win_precise_time.__version__"}
[tool.scikit-build]
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
sdist.include = ["src/win_precise_time/_version.py"]
wheel.packages = ["src/win_precise_time"]

[tool.setuptools_scm] # Section required
write_to = "src/win_precise_time/_version.py"

[tool.cibuildwheel]
test-requires = "pytest"
Expand Down
17 changes: 0 additions & 17 deletions setup.py

This file was deleted.

3 changes: 1 addition & 2 deletions src/win_precise_time/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#
# SPDX-License-Identifier: MIT

__version__ = "1.4.2"

from win_precise_time._t import (
time as time,
time_ns as time_ns,
Expand All @@ -12,3 +10,4 @@
sleep_until_ns as sleep_until_ns,
hotloop_until_ns as hotloop_until_ns,
)
from win_precise_time._version import __version__
2 changes: 1 addition & 1 deletion src/win_precise_time/_t.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static ULONGLONG _wpt_time_ns()
}


// helper function to check wether remaining sleep duration is below threshold
// helper function to check whether remaining sleep duration is below threshold
static BOOL _sleep_time_is_below_threshold(LONGLONG due_time, LONGLONG thr)
{
if (due_time < 0)
Expand Down
1 change: 1 addition & 0 deletions tests/test_precise_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def test_module_import():


def test_function_import():
from win_precise_time import __version__
from win_precise_time import time
from win_precise_time import time_ns
from win_precise_time import sleep
Expand Down

0 comments on commit a3e1586

Please sign in to comment.