Skip to content

Commit

Permalink
🎉 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
peinan committed May 10, 2019
1 parent 549236a commit 8039c01
Show file tree
Hide file tree
Showing 8 changed files with 550 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .circleci/config.yml
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]+)*/
11 changes: 11 additions & 0 deletions .gitignore
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
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# swpy: A simple, yet useful stopwatch library for python

[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/swpy.svg?style=flat-square)](https://pypi.org/project/swpy/)
[![PyPI](https://img.shields.io/pypi/v/swpy.svg?style=flat-square)](https://pypi.org/project/swpy/)
[![CircleCI](https://img.shields.io/circleci/project/github/peinan/swpy/master.svg?color=brightgreen&style=flat-square)](https://circleci.com/gh/peinan/swpy/tree/master)
[![codecov](https://codecov.io/gh/peinan/swpy/branch/master/graph/badge.svg?token=ztxEI8QioI)](https://codecov.io/gh/peinan/swpy)
[![license](https://img.shields.io/pypi/l/swpy.svg?color=brightgreen&style=flat-square)](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
223 changes: 223 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions pyproject.toml
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"
Loading

0 comments on commit 8039c01

Please sign in to comment.