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

chore: update python #20

Merged
merged 5 commits into from
Nov 22, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -24,10 +24,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.12"
- name: Install poetry
uses: snok/install-poetry@v1.3.3
- name: install dependencies
Expand Down
1,245 changes: 582 additions & 663 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions py_loop/looper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import importlib.metadata
import subprocess
import time
from typing import Any, List

import cli_ui as ui
import pkg_resources


class InvalidCommand(Exception):
Expand Down Expand Up @@ -72,6 +72,8 @@ def _print_summary(self) -> None:
length = len(self.run_durations)
if length == 1:
med_time = self.run_durations[0]
elif length == 2:
med_time = (self.run_durations[0] + self.run_durations[1]) / 2
else:
med_time = self.run_durations[length // 2 + 1]
if length % 2 == 0:
Expand Down Expand Up @@ -102,4 +104,4 @@ def loop(self) -> None:

@classmethod
def version(cls) -> str:
return pkg_resources.require("py-loop")[0].version
return importlib.metadata.version("py-loop")
5 changes: 3 additions & 2 deletions py_loop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ArgsList = Optional[List[str]]


def main(args: ArgsList = None) -> None:
def main(args: ArgsList = None) -> Optional[Looper]:
parser = argparse.ArgumentParser()
parser.add_argument(
"cmd",
Expand Down Expand Up @@ -46,7 +46,7 @@ def main(args: ArgsList = None) -> None:
args_ns = parser.parse_args(args=args)
if args_ns.version:
ui.info_1(Looper.version())
return
return None
if not args_ns.cmd or not args_ns.cmd[0]:
ui.error("no command provided")
sys.exit(1)
Expand All @@ -59,3 +59,4 @@ def main(args: ArgsList = None) -> None:
total_time=args_ns.total_time,
)
looper.loop()
return looper
17 changes: 7 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ authors = ["jerem <jeremy.tellaa@tanker.io>"]
python = ">=3.8.1,<4.0"
cli-ui = "^0.17.2"

[tool.poetry.dev-dependencies]
black = "23.3.0"
codecov = "^2.01.13"
flake8 = "6.0.0"
mypy = "1.2.0"
pytest = "^7.3.1"
pytest-cov = "^4.0.0"
types-setuptools = "^67.6.0.8"
isort = "^5.12.0"

[tool.poetry.group.dev.dependencies]
twine = "^4.0.2"
black = "23.11.0"
codecov = "^2.1.13"
flake8 = "6.1.0"
mypy = "1.7.0"
pytest = "^7.4.3"
pytest-cov = "^4.01.0"
isort = "^5.12.0"

[build-system]
requires = ["poetry>=0.12"]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_looper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import py_loop as looper


@pytest.mark.parametrize("max_tries", [1, 10, 100])
@pytest.mark.parametrize("max_tries", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
def test_max_success(max_tries: int) -> None:
cmd_looper = looper.Looper(
cmd=["ls"],
Expand All @@ -20,7 +20,7 @@ def test_max_success(max_tries: int) -> None:
assert cmd_looper.fails == 0


@pytest.mark.parametrize("max_tries", [1, 10, 100])
@pytest.mark.parametrize("max_tries", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
def test_max_fails(max_tries: int) -> None:
cmd_looper = looper.Looper(
cmd=["ls", "/plop"],
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_total_delay() -> None:
assert cmd_looper.runs == max_tries
diff = cmd_looper.duration - (max_tries - 1) * delay
assert diff > 0
assert diff < 0.1
assert diff < 0.2


def test_total_time_even() -> None:
Expand Down
7 changes: 4 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_no_cmd() -> None:
assert e.value.code == 1


def test_cmd() -> None:
looper_main.main(["ls", "--max-tries", "1"])
looper_main.main(["--max-tries", "1", "ls"])
def test_parsing() -> None:
looper = looper_main.main(["--max-tries", "7", "ls"])
assert looper is not None
assert looper.max_tries == 7