Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to poetry and unittest #32

Merged
merged 7 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,11 @@ on:

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- uses: actions/checkout@v3
- name: Build and publish to pypi
uses: JRubics/[email protected]
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}
71 changes: 34 additions & 37 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,52 @@ name: Test

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- '3.5'
- '3.6'
- '3.7'
- '3.8'
# udatetime doesn't compile with 3.9
# - '3.9'
- 'pypy-3.6'
- 'pypy-3.7'
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "pypy-3.9"
- "pypy-3.10"

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r test-requirements.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 pycron --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings
flake8 pycron --count --exit-zero --max-complexity=20 --max-line-length=120 --statistics
- name: Test with nose
run: |
nosetests -q --with-coverage --cover-package=pycron
- name: Coveralls
uses: AndreMiras/coveralls-python-action@develop
with:
parallel: true
flag-name: run-${{ matrix.test_number }}
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --with test
- name: Lint
run: |
poetry run flake8 pycron --max-line-length=88
poetry run pylint pycron
- name: Run tests
run: |
poetry run coverage run -m unittest discover -b
- name: Coveralls
uses: AndreMiras/coveralls-python-action@develop
with:
parallel: true
flag-name: run-${{ matrix.test_number }}

finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: AndreMiras/coveralls-python-action@develop
with:
parallel-finished: true
- name: Coveralls Finished
uses: AndreMiras/coveralls-python-action@develop
with:
parallel-finished: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ venv
*.pyc
dist
*.egg-info
.python-version
.coverage
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# pycron
![Test Status](https://github.com/kipe/pycron/workflows/Test/badge.svg?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/kipe/pycron/badge.svg?branch=master)](https://coveralls.io/github/kipe/pycron?branch=master)

![Test Status](https://github.com/kipe/pycron/workflows/python-test.yml/badge.svg?branch=main)
[![Coverage Status](https://coveralls.io/repos/github/kipe/pycron/badge.svg?branch=main)](https://coveralls.io/github/kipe/pycron?branch=main)

Simple cron-like parser for Python, which determines if current datetime matches conditions.

## Installation

`pip install pycron`

## Usage

```python
import pycron
pycron.is_now('*/5 * * * *') # True every 5 minutes
pycron.is_now('0 * * * *') # True every hour, on minute 0
```

## Help

The formats currently supported are

- `*/5` (for "every X" function),
- `4-10` (for time ranges),
- `6,8,23` (for a list of values),
Expand All @@ -37,22 +42,24 @@ There are couple of helpers available, mainly for use with Django.
They give out list of tuples, as required by Django field choices.

The available helpers are

- `pycron.MINUTE_CHOICES`,
- `pycron.HOUR_CHOICES`,
- `pycron.DOM_CHOICES`, for day of month
- `pycron.MONTH_CHOICES`, for month names
- `pycron.DOW_CHOICES`, for day names


## Support for alternative datetime -libraries

Currently supported "alternative" datetime libraries are:

- [Arrow](http://arrow.readthedocs.io/en/latest/)
- [Delorean](http://delorean.readthedocs.io/en/latest/)
- [Pendulum](https://pendulum.eustace.io/)
- [udatetime](https://github.com/freach/udatetime)


#### Notes

This was done, as I personally needed something like this to implement proper timers for my Django-project and
every available library felt too complicated for my use-case. Also, this was a good coding exercise...

Expand Down
Loading