From 09a945f1209d4dec8a1dc6ef6d55e1a1c21872ba Mon Sep 17 00:00:00 2001 From: Kin Date: Mon, 23 Oct 2023 16:40:46 +0200 Subject: [PATCH] feat: first version. Involved LastSeconds, modified to pypi --- .github/workflows/Pip.yml | 35 ++++++++++++ .github/workflows/Wheels.yml | 68 ++++++++++++++++++++++++ .github/workflows/pypi.yml | 100 ----------------------------------- README.md | 15 ++++-- pyproject.toml | 2 +- src/dztimer_ext.cpp | 3 +- tests/test_basic.py | 1 + 7 files changed, 118 insertions(+), 106 deletions(-) create mode 100644 .github/workflows/Pip.yml create mode 100644 .github/workflows/Wheels.yml delete mode 100644 .github/workflows/pypi.yml diff --git a/.github/workflows/Pip.yml b/.github/workflows/Pip.yml new file mode 100644 index 0000000..dc14331 --- /dev/null +++ b/.github/workflows/Pip.yml @@ -0,0 +1,35 @@ +name: Pip + +on: + workflow_dispatch: + pull_request: + push: + branches: + - master + release: + types: + - published + +jobs: + Testing_Local: + runs-on: ${{ matrix.platform }} + strategy: + fail-fast: false + matrix: + platform: [windows-latest, macos-latest, ubuntu-latest] + python-version: ["3.8", "3.11"] + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies and package + run: | + python -m pip install pytest + pip install --verbose . + + - name: Run tests + run: python -m pytest \ No newline at end of file diff --git a/.github/workflows/Wheels.yml b/.github/workflows/Wheels.yml new file mode 100644 index 0000000..bb47aa2 --- /dev/null +++ b/.github/workflows/Wheels.yml @@ -0,0 +1,68 @@ +name: Wheels + +on: + workflow_dispatch: + pull_request: + push: + branches: + - master + release: + types: + - published + +jobs: + Build_Wheels: + name: Wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + if: github.event_name == 'release' && github.event.action == 'published' + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - uses: pypa/cibuildwheel@v2.13.0 + env: + # Cross-compile on macOS + CIBW_ARCHS_MACOS: x86_64 arm64 + + # Temporary: use pre-release Python 3.12 for stable ABI builds + CIBW_PRERELEASE_PYTHONS: True + + - name: Verify clean directory + run: git diff --exit-code + shell: bash + + - name: Upload wheels + uses: actions/upload-artifact@v3 + with: + path: wheelhouse/*.whl + + upload_all: + name: Upload if release + needs: [Build_Wheels] + runs-on: ubuntu-latest + if: github.event_name == 'release' && github.event.action == 'published' + + steps: + - uses: actions/setup-python@v4 + + - name: Download Wheels artifact + uses: actions/download-artifact@v3 + with: + name: artifact + path: wheelhouse + + # - uses: pypa/gh-action-pypi-publish@release/v1 + # with: + # password: ${{ secrets.TEST_PYPI_API_TOKEN }} + # repository-url: https://test.pypi.org/legacy/ + + - uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} + packages_dir: wheelhouse \ No newline at end of file diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml deleted file mode 100644 index d188fce..0000000 --- a/.github/workflows/pypi.yml +++ /dev/null @@ -1,100 +0,0 @@ -name: Build, Test & Publish - -on: - workflow_dispatch: - push: - branches: - - master - -jobs: - - # Job 1: Build & Test with Pip - testing: - runs-on: ${{ matrix.platform }} - strategy: - fail-fast: false - matrix: - platform: [windows-latest, macos-latest, ubuntu-latest] - python-version: ["3.8", "3.11"] - - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies and package - run: | - python -m pip install pytest - pip install --verbose . - - - name: Run tests - run: python -m pytest - - build_sdist: - name: Build SDist - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - name: Build SDist - run: pipx run build --sdist - - - name: Check metadata - run: pipx run twine check dist/* - - - uses: actions/upload-artifact@v3 - with: - path: dist/*.tar.gz - - build_wheels: - name: Wheels on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - - uses: pypa/cibuildwheel@v2.13.0 - env: - # Cross-compile on macOS - CIBW_ARCHS_MACOS: x86_64 arm64 - - # Temporary: use pre-release Python 3.12 for stable ABI builds - CIBW_PRERELEASE_PYTHONS: True - - - name: Verify clean directory - run: git diff --exit-code - shell: bash - - - name: Upload wheels - uses: actions/upload-artifact@v3 - with: - path: wheelhouse/*.whl - - upload_all: - name: Upload if release - needs: [build_wheels, build_sdist] - runs-on: ubuntu-latest - # if: github.event_name == 'release' && github.event.action == 'published' - - steps: - - uses: actions/setup-python@v4 - - - uses: actions/download-artifact@v3 - with: - name: artifact - path: dist - - - uses: pypa/gh-action-pypi-publish@release/v1 - with: - password: ${{ secrets.TEST_PYPI_API_TOKEN }} - repository-url: https://test.pypi.org/legacy/ \ No newline at end of file diff --git a/README.md b/README.md index 9a1a11c..cabc94e 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,17 @@ dztimer --- - - - + A beautiful timer from ufomap by [Daniel Duberg](https://www.kth.se/profile/dduberg), nanobind by [Qingwen Zhang](https://kin-zhang.github.io/). -Running on macOS, Windows and Linux. +Running on macOS, Windows and Linux, with Python Version >= 3.8. TestDemo: ```bash pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ dztimer +python3 -c 'import dztimer' ``` Quick Demo: @@ -38,6 +37,14 @@ timer.print(random_colors=True, bold=True) +### Build from source + +```bash +git clone https://github.com/KTH-RPL/dztimer +cd dztimer +pip install . +python3 -c 'import dztimer' +``` ### Issue I met when write this package diff --git a/pyproject.toml b/pyproject.toml index 446f606..f4d85b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build" [project] name = "dztimer" -version = "0.0.5" +version = "1.0.0" description = "A beautiful timer from ufomap by Daniel Duberg, nanobind by Qingwen Zhang" readme = "README.md" requires-python = ">=3.8" diff --git a/src/dztimer_ext.cpp b/src/dztimer_ext.cpp index c22fb65..54d42d6 100644 --- a/src/dztimer_ext.cpp +++ b/src/dztimer_ext.cpp @@ -45,7 +45,8 @@ NB_MODULE(dztimer_ext, m) { nanobind::class_(m, "Timer") .def("start", static_cast(&Timer::start)) - .def("stop", &Timer::stop); + .def("stop", &Timer::stop) + .def("lastSeconds", &Timer::lastSeconds); nanobind::class_(m, "Timing") .def(nanobind::init<>()) diff --git a/tests/test_basic.py b/tests/test_basic.py index cdf5089..259ce2b 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -13,6 +13,7 @@ def test_dztimer(): timer[1].start("Second Scan Cost") sleep(0.08 + i * 0.01) timer[1].stop() + print(f"The timing last record: {timer[1].lastSeconds():.2f} s") timer.print(random_colors=True, bold=True) if __name__ == "__main__":