Skip to content

Commit

Permalink
chore: update ci workflows and add support for python3.10 👷 (#10)
Browse files Browse the repository at this point in the history
* chore: update ci workflows and add support for python3.10 👷

* quote the python version numbers

* increase the coverage

* add `py` to the matrix values
  • Loading branch information
meysam81 authored Oct 17, 2022
1 parent 3c3ad29 commit 3660f15
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 101 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: linter

on:
pull_request:
push:
branches:
- main

jobs:
linter:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Prepare
run: |
pip install -U pip pre-commit
- name: Run linter
run: |
pre-commit run -a
- if: failure()
name: Commit linting changes
uses: EndBug/add-and-commit@v9
with:
message: "chore: lint 🚨"
new_branch: ${{ github.head_ref || github.ref_name }}
46 changes: 0 additions & 46 deletions .github/workflows/main.yml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: publish-pypi

on:
release:
types:
- published

jobs:
publish-pypi:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Prepare
run: |
pip install -U pip wheel
- env:
PACKAGE_VERSION: ${{ github.head_ref || github.ref_name }}
name: Build package
run: |
python setup.py sdist bdist_wheel
- name: Publish PyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: tests

on:
pull_request:
push:
branches:
- main

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Prepare
run: |
pip install -U pip tox
- name: Run tests ${{ matrix.python-version }}
run: |
tox -e ${{ matrix.python-version }}
- name: Coverage Report
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
verbose: true
strategy:
matrix:
python-version:
- py3.6
- py3.7
- py3.8
- py3.9
- py3.10
88 changes: 81 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,84 @@
*$py.class
build
build/
.cache
celerybeat.pid
celerybeat-schedule
*.cover
cover/
.coverage
.tox
.vscode
htmlcov
**/*.egg-info
.coverage.*
coverage.xml
test/__pycache__ timeframe/__pycache__
**/*.py[cod]
cython_debug/
db.sqlite3
db.sqlite3-journal
develop-eggs/
dist
build
dist/
.dmypy.json
dmypy.json
docs/_build/
downloads/
*.egg
**/*.egg-info
*.egg-info/
.eggs/
eggs/
.env
env/
ENV/
env.bak/
htmlcov
htmlcov/
.hypothesis/
.installed.cfg
instance/
.ipynb_checkpoints
ipython_config.py
lib/
lib64/
local_settings.py
*.log
*.manifest
MANIFEST
*.mo
.mypy_cache/
nosetests.xml
.nox/
parts/
.pdm.toml
pip-delete-this-directory.txt
pip-log.txt
*.pot
profile_default/
.pybuilder/
__pycache__/
**/*.py[cod]
*.py[cod]
*.py,cover
__pypackages__/
.pyre/
.pytest_cache/
.Python
.pytype/
.ropeproject
*.sage.py
.scrapy
sdist/
share/python-wheels/
/site
*.so
*.spec
.spyderproject
.spyproject
target/
test/__pycache__ timeframe/__pycache__
.tox
.tox/
var/
.venv
venv/
venv.bak/
.vscode
.webassets-cache
wheels/
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
stages: [commit]
args: ["--profile", "black"]

- repo: https://github.com/PyCQA/autoflake
rev: v1.5.3
hooks:
- id: autoflake
stages: [commit]
args:
[
"-ri",
"--remove-all-unused-imports",
"--remove-duplicate-keys",
"--ignore-init-module-imports",
"--remove-unused-variables",
]

- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black
stages: [commit]
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import os

import setuptools

import timeframe

with open("README.md", "r", encoding="utf-8") as f:
long_description = f.read()

PACKAGES = setuptools.find_packages(include=("timeframe",))
PACKAGE_VERSION = os.getenv(
"PACKAGE_VERSION", getattr(timeframe, "__version__", "0.0.0")
)

setuptools.setup(
name=timeframe.__name__,
version=timeframe.__version__,
version=PACKAGE_VERSION,
author=timeframe.__author__,
author_email=timeframe.__author_email__,
description="Calculation of time frames using the built-in datetime module",
Expand All @@ -25,6 +31,7 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
python_requires=">=3.6",
python_requires=">=3.6,<3.11",
)
25 changes: 25 additions & 0 deletions test/test_batch_timeframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,28 @@ def test_batch_timeframe_equality_with_non_batch_timeframe_raises_type_error():

with pytest.raises(TypeError):
btf == [1, 1.0, "dummy", True]


# ======================= Repr ============================
def test_batch_timeframe_single_timeframe_repr():
btf = BatchTimeFrame(
[TimeFrame(datetime(2022, 10, 18, 10), datetime(2022, 10, 18, 11))]
)

assert repr(btf) == "2022-10-18T10:00:00#2022-10-18T11:00:00"


def test_batch_timeframe_multiple_timeframes_repr():
btf = BatchTimeFrame(
[
TimeFrame(datetime(2022, 10, 18, 10), datetime(2022, 10, 18, 11)),
TimeFrame(datetime(2022, 10, 18, 12), datetime(2022, 10, 18, 14)),
TimeFrame(datetime(2022, 10, 18, 18), datetime(2022, 10, 18, 20)),
]
)

assert repr(
btf
) == "2022-10-18T10:00:00#2022-10-18T11:00:00,2022-10-18T12:00:00#2022-10-18T14:00:00,2022-10-18T18:00:00#2022-10-18T20:00:00".replace(
",", "\n"
)
7 changes: 7 additions & 0 deletions test/test_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ def test_empty_timeframe_doesnt_include_anything():
assert not (tf1 * tf3).includes(tf3)
assert not (tf1 * tf3).includes(tf4)
assert not (tf1 * tf2).includes(tf5)


def test_empty_timeframe_repr():
tf1 = TimeFrame(datetime(2022, 10, 15), datetime(2022, 10, 16))
tf2 = TimeFrame(datetime(2022, 10, 17), datetime(2022, 10, 18))

assert repr(tf1 * tf2) == "Empty TimeFrame"
5 changes: 2 additions & 3 deletions timeframe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from .timeframe import BatchTimeFrame, TimeFrame

__all__ = (
BatchTimeFrame,
TimeFrame,
"BatchTimeFrame",
"TimeFrame",
)

__name__ = "timeframe"
__version__ = "0.1.5"
__author__ = "Meysam Azad"
__author_email__ = "[email protected]"
Loading

0 comments on commit 3660f15

Please sign in to comment.