-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
550 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
version: 2 | ||
|
||
jobs: | ||
build-and-test: | ||
working_directory: ~/circleci-swpy | ||
docker: | ||
- image: circleci/python:3.6.8 | ||
steps: | ||
- checkout | ||
- restore_cache: | ||
keys: | ||
- deps-{{ checksum "poetry.lock" }} | ||
- run: | ||
name: Install Dependencies | ||
command: | | ||
sudo pip install poetry | ||
poetry install | ||
- save_cache: | ||
key: deps-{{ checksum "poetry.lock" }} | ||
paths: | ||
- ~/.cache/pypoetry/virtualenvs | ||
- run: | ||
name: Run Tests, Report Coverage | ||
command: | | ||
poetry run tox | ||
poetry run codecov -t ${CODECOV_TOKEN} | ||
deploy: | ||
working_directory: ~/circleci-swpy | ||
docker: | ||
- image: circleci/python:3.6.8 | ||
steps: | ||
- checkout | ||
- run: | ||
name: Deploy to PyPI | ||
command: | | ||
poetry publish --build -u ${PYPI_U} -p ${PYPI_P} | ||
workflows: | ||
version: 2 | ||
build-and-test-workflow: | ||
jobs: | ||
- build-and-test | ||
deploy-workflow: | ||
jobs: | ||
- build-and-test: | ||
filters: | ||
branches: | ||
only: master | ||
- hold: | ||
type: approval | ||
requires: | ||
- build-and-test | ||
- deploy: | ||
requires: | ||
- hold | ||
filters: | ||
tags: | ||
only: /v[0-9]+(\.[0-9]+)*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.swp | ||
*.swo | ||
|
||
.tox | ||
dist | ||
*.egg-info | ||
__pycache__ | ||
.pytest_cache | ||
|
||
.coverage | ||
coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# swpy: A simple, yet useful stopwatch library for python | ||
|
||
[](https://pypi.org/project/swpy/) | ||
[](https://pypi.org/project/swpy/) | ||
[](https://circleci.com/gh/peinan/swpy/tree/master) | ||
[](https://codecov.io/gh/peinan/swpy) | ||
[](https://github.com/peinan/swpy/blob/master/LICENSE) | ||
|
||
## Requirements | ||
|
||
- Python 3.6+ | ||
|
||
## Install | ||
|
||
```bash | ||
$ pip install swpy | ||
``` | ||
|
||
## Usage | ||
|
||
```python | ||
>>> from swpy import Timer | ||
>>> import time | ||
|
||
|
||
# the simplest use | ||
>>> with Timer(): | ||
... time.sleep(1) | ||
|
||
[timer-1557406243.3309178] started. | ||
[timer-1557406243.3309178] finish time: 1.00 sec. | ||
|
||
|
||
# name the timer for visibility | ||
>>> with Timer(name='test timer'): | ||
... time.sleep(1) | ||
|
||
[test timer] started. | ||
[test timer] finish time: 1.00 sec. | ||
|
||
|
||
# use your own logger | ||
>>> from logzero import logger | ||
>>> import logging | ||
>>> with Timer(name='test timer', logger=logger, level=logging.DEBUG): | ||
... time.sleep(1) | ||
|
||
[D 190510 14:41:59 swpy:15] [test timer] started. | ||
[D 190510 14:42:00 swpy:15] [test timer] finish time: 1.01 sec. | ||
|
||
|
||
# process the timer result with your own function with callback | ||
## define a slack notification function | ||
>>> import requests, json | ||
>>> def send_slack(msg): | ||
... requests.post(SLACK_URL, json.dumps({'text': msg})) | ||
|
||
## just specify the callback argument | ||
>>> with Timer(name='experiment-1', logger=logger, level=logging.DEBUG, callback=send_slack): | ||
... time.sleep(1) | ||
[D 190510 14:48:17 swpy:15] [experiment-1] started. | ||
[D 190510 14:48:18 swpy:15] [experiment-1] finish time: 1.01 sec. | ||
``` | ||
|
||
## License | ||
|
||
MIT |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[tool.poetry] | ||
name = "swpy" | ||
version = "0.1.0" | ||
description = "A simple, yet useful stopwatch library." | ||
authors = ["Peinan ZHANG <[email protected]>"] | ||
license = "MIT" | ||
readme = "README.md" | ||
homepage = "https://github.com/peinan/swpy" | ||
repository = "https://github.com/peinan/swpy" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.6" | ||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = "^4.0" | ||
tox = "^3.9" | ||
pytest-cov = "^2.7" | ||
codecov = "^2.0" | ||
|
||
[build-system] | ||
requires = ["poetry>=0.12"] | ||
build-backend = "poetry.masonry.api" |
Oops, something went wrong.