Skip to content

Commit

Permalink
feat: first version. Involved LastSeconds, modified to pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
Kin-Zhang committed Oct 23, 2023
1 parent 74c3017 commit 09a945f
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 106 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/Pip.yml
Original file line number Diff line number Diff line change
@@ -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
68 changes: 68 additions & 0 deletions .github/workflows/Wheels.yml
Original file line number Diff line number Diff line change
@@ -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
100 changes: 0 additions & 100 deletions .github/workflows/pypi.yml

This file was deleted.

15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
dztimer
---
<!-- <a href="https://github.com/KTH-RPL/dztimer"><img src="https://img.shields.io/github/v/release/KTH-RPL/dztimer?label=version" /> <a href="https://github.com/KTH-RPL/dztimer/blob/master/LICENSE"><img src="https://img.shields.io/github/license/KTH-RPL/dztimer" /> -->
<img src="https://img.shields.io/badge/Linux-FCC624?logo=linux&logoColor=black" />
<img src="https://img.shields.io/badge/Windows-0078D6?st&logo=windows&logoColor=white" />
<img src="https://img.shields.io/badge/mac%20os-000000?&logo=apple&logoColor=white" />
<img src="https://img.shields.io/badge/Linux-FCC624?logo=linux&logoColor=black" /> <img src="https://img.shields.io/badge/Windows-0078D6?st&logo=windows&logoColor=white" /> <img src="https://img.shields.io/badge/mac%20os-000000?&logo=apple&logoColor=white" />
<!-- <img src="https://img.shields.io/pypi/pyversions/dztimer.svg" /></a> -->

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:
Expand All @@ -38,6 +37,14 @@ timer.print(random_colors=True, bold=True)

<!-- Tutorial on nanobind and pypi release in [Chinese blog](TODO) -->

### 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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/dztimer_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
NB_MODULE(dztimer_ext, m) {
nanobind::class_<Timer>(m, "Timer")
.def("start", static_cast<void (Timer::*)()>(&Timer::start))
.def("stop", &Timer::stop);
.def("stop", &Timer::stop)
.def("lastSeconds", &Timer::lastSeconds);

nanobind::class_<Timing, Timer>(m, "Timing")
.def(nanobind::init<>())
Expand Down
1 change: 1 addition & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit 09a945f

Please sign in to comment.