Skip to content

Commit

Permalink
Merge pull request #65 from alphatwirl/dev
Browse files Browse the repository at this point in the history
Format code with `ruff`
  • Loading branch information
TaiSakuma authored Oct 5, 2024
2 parents 7e57b02 + bd19aa2 commit f015a4c
Show file tree
Hide file tree
Showing 24 changed files with 31 additions and 51 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
},
"prettier.printWidth": 79,
"rewrap.wrappingColumn": 79,
"python.testing.pytestArgs": ["tests"],
"python.testing.pytestArgs": ["atpbar", "tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"isort.check": true,
"markdownlint.config": {
"MD033": false,
"MD036": false,
Expand Down
2 changes: 0 additions & 2 deletions atpbar/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class CallbackImp:

def __init__(self) -> None:
self.reporter: ProgressReporter | None = None
self._machine: StateMachine # to be set by the StateMachine
Expand Down Expand Up @@ -56,7 +55,6 @@ def shutdown_in_active(self) -> None:

@contextmanager
def fetch_reporter_in_yielded(self) -> Iterator[ProgressReporter | None]:

if not in_main_thread():
self.to_restart_pickup = False
yield self.reporter
Expand Down
1 change: 0 additions & 1 deletion atpbar/presentation/barjupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def _update_widgets(self) -> None:
self.widget_dict.clear()

def _update_widget(self, report: Report) -> None:

percent = float(report['done']) / report['total'] if report['total'] > 0 else 1
percent = round(percent * 100, 2)
percent_fmt = '{:6.2f}%'.format(percent)
Expand Down
1 change: 0 additions & 1 deletion atpbar/presentation/bartty.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def _compose_bar_from_task_id(self, task_id: UUID) -> str:
return self._compose_bar_from_report(report)

def _compose_bar_from_report(self, report: Report) -> str:

percent = float(report['done']) / report['total'] if report['total'] > 0 else 1
# e.g., 0.7143369818769065

Expand Down
3 changes: 0 additions & 3 deletions atpbar/presentation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Presentation(ABC):
stdout_stderr_redirection = False

def __init__(self) -> None:

self.out = sys.stdout
self.err = sys.stderr

Expand Down Expand Up @@ -52,7 +51,6 @@ def _present(self, report: Report) -> None:
pass

def _register_report(self, report: Report) -> bool:

task_id = report['task_id']

if task_id in self._complete_task_ids:
Expand Down Expand Up @@ -95,7 +93,6 @@ def _update_registry(self) -> None:
del self._finishing_task_ids[:]

def _need_to_present(self) -> bool:

if self._new_task_ids:
return True

Expand Down
2 changes: 0 additions & 2 deletions atpbar/presentation/txtprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def __repr__(self) -> str:
return '{}()'.format(self.__class__.__name__)

def present(self, report: Report) -> None:

if not self._register_report(report):
return

Expand All @@ -41,7 +40,6 @@ def _present(self, report: Report) -> None:
self.out.flush()

def _need_to_present_(self, report: Report) -> bool:

if report['first']:
return True

Expand Down
1 change: 0 additions & 1 deletion atpbar/progress_report/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def report(self, report: Report) -> None:
self.last_time[report['task_id']] = time.time()

def _need_to_report(self, report: Report) -> bool:

if report['first']:
return True

Expand Down
1 change: 1 addition & 0 deletions atpbar/stream/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
else:
from typing_extensions import TypeAlias


class FD(Enum):
STDOUT = 1
STDERR = 2
Expand Down
38 changes: 27 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"typing_extensions>=4.12; python_version < '3.10'",
]
dependencies = ["typing_extensions>=4.12; python_version < '3.10'"]
[project.optional-dependencies]
jupyter = ["ipywidgets>=8.1"]
tests = [
Expand Down Expand Up @@ -55,6 +53,32 @@ addopts = """
# doctest_optionflags = ["ELLIPSIS", "NORMALIZE_WHITESPACE",]
doctest_optionflags = ["ELLIPSIS"]

[tool.ruff]
line-length = 88

[tool.ruff.format]
quote-style = "preserve"

[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"F", # pyflakes
"I", # isort
]
ignore = [
"E203", # Whitespace before '{symbol}'
"E265", # Block comment should start with #
"E266", # Too many leading # before block comment
"E501", # Line too long ({width} > {limit})
"E741", # Ambiguous variable name '{name}'
]

[tool.ruff.lint.mccabe]
max-complexity = 20

[tool.ruff.lint.isort]
#

[tool.coverage.run]
branch = true
source = ["atpbar", "tests"]
Expand All @@ -67,14 +91,6 @@ exclude_lines = [
"if TYPE_CHECKING:",
]

[tool.black]
# Doesn't appear to be effective with VSCode extension Black Formatter
skip-string-normalization = true

[tool.isort]
profile = "black"


[[tool.mypy.overrides]]
module = ["ipywidgets"]
ignore_missing_imports = true
1 change: 0 additions & 1 deletion tests/eoferror/test_script_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@pytest.mark.script_launch_mode('subprocess')
def test_run(script_runner: ScriptRunner) -> None:

cwd = os.path.dirname(os.path.abspath(__file__))

script_path = os.path.join('.', 'script.py')
Expand Down
3 changes: 0 additions & 3 deletions tests/presentation/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def test_register_report( # type: ignore
expected_complete_task_ids,
expected_return,
):

obj._new_task_ids[:] = initial_new_task_ids
obj._active_task_ids[:] = initial_active_task_ids
obj._finishing_task_ids[:] = initial_finishing_task_ids
Expand Down Expand Up @@ -153,7 +152,6 @@ def test_update_registry( # type: ignore
expected_finishing_task_ids,
expected_complete_task_ids,
):

obj._new_task_ids[:] = initial_new_task_ids
obj._active_task_ids[:] = initial_active_task_ids
obj._finishing_task_ids[:] = initial_finishing_task_ids
Expand Down Expand Up @@ -189,7 +187,6 @@ def test_need_to_present( # type: ignore
interval,
expected,
):

obj._new_task_ids[:] = new_task_ids
obj._finishing_task_ids[:] = finishing_task_ids

Expand Down
3 changes: 0 additions & 3 deletions tests/progress_report/test_pickup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class TestStart:

@pytest.fixture()
def presentation(self) -> mock.Mock:
return mock.Mock()
Expand Down Expand Up @@ -43,7 +42,6 @@ def test_daemon(


class TestRunUntilTheEndOrderArrives:

@pytest.fixture()
def mock_thread_start(self, monkeypatch: pytest.MonkeyPatch) -> Iterator[mock.Mock]:
y = mock.Mock()
Expand Down Expand Up @@ -142,7 +140,6 @@ def test_two_reports(


class TestRunUntilReportsStopComing:

@pytest.fixture()
def mock_thread_start(self, monkeypatch: pytest.MonkeyPatch) -> Iterator[mock.Mock]:
y = mock.Mock()
Expand Down
1 change: 0 additions & 1 deletion tests/progress_report/test_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def test_repr(obj: ProgressReporter) -> None:


class TestReport:

def test_report_need_to_report(
self,
obj: ProgressReporter,
Expand Down
1 change: 0 additions & 1 deletion tests/scenarios/test_last_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def test_multiprocessing_process(
n_done = min(n_done, n_iterations)

with mock_presentations() as presentations:

if method == 'break':
func_break(n_done, n_iterations)
else:
Expand Down
1 change: 0 additions & 1 deletion tests/scenarios/test_multiprocessing_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def func(n: int, name: str) -> None:
),
)
def test_multiprocessing_pool(n_processes: int, n_iterations: list[int]) -> None:

with mock_presentations() as presentations:
reporter = find_reporter()
with (
Expand Down
2 changes: 0 additions & 2 deletions tests/scenarios/test_multiprocessing_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def func(n: int, name: str, reporter: ProgressReporter) -> None:
to_disable=st.booleans(),
)
def test_multiprocessing_process(n_iterations: list[int], to_disable: bool) -> None:

with mock_presentations() as presentations:

if to_disable:
disable()

Expand Down
4 changes: 1 addition & 3 deletions tests/scenarios/test_nested_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
to_disable=st.booleans(),
)
def test_nested_loop(n_outer: int, n_inner: int, to_disable: bool) -> None:

with mock_presentations() as presentations:

if to_disable:
disable()

for _ in atpbar(range(n_outer)):
for _ in atpbar(range(n_inner)):
pass

if to_disable:
assert len(presentations) == 0
return
Expand Down
2 changes: 0 additions & 2 deletions tests/scenarios/test_one_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

@given(n_iterations=st.integers(min_value=0, max_value=10), to_disable=st.booleans())
def test_one_loop(n_iterations: int, to_disable: bool) -> None:

with mock_presentations() as presentations:

if to_disable:
disable()

Expand Down
1 change: 0 additions & 1 deletion tests/scenarios/test_process_pool_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def func(n: int, name: str) -> None:
),
)
def test_process_pool_executor(n_workers: int, n_iterations: list[int]) -> None:

with mock_presentations() as presentations:
reporter = find_reporter()
assert reporter is not None
Expand Down
1 change: 0 additions & 1 deletion tests/scenarios/test_thread_pool_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def func(n: int, name: str) -> None:
),
)
def test_thread_pool_executor(n_workers: int, n_iterations: list[int]) -> None:

with mock_presentations() as presentations:
with flushing(), ThreadPoolExecutor(max_workers=n_workers) as executor:
for n in n_iterations:
Expand Down
2 changes: 0 additions & 2 deletions tests/scenarios/test_threading_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def func(n: int, name: str) -> None:
to_disable=st.booleans(),
)
def test_threading_thread(n_iterations: list[int], to_disable: bool) -> None:

with mock_presentations() as presentations:

if to_disable:
disable()

Expand Down
1 change: 0 additions & 1 deletion tests/scenarios/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


def test_mock_presentations() -> None:

class MockException(Exception):
pass

Expand Down
3 changes: 0 additions & 3 deletions tests/test_atpbar_name_raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def test_atpbar_name_repr(
mock_reporter: mock.Mock,
caplog: pytest.LogCaptureFixture,
) -> None:

iterable = Iter(content)
returned = [e for e in atpbar.atpbar(iterable)]

Expand All @@ -86,7 +85,6 @@ def test_atpbar_name_given(
mock_reporter: mock.Mock,
caplog: pytest.LogCaptureFixture,
) -> None:

iterable = Iter(content)
returned = [e for e in atpbar.atpbar(iterable, name='given')]

Expand All @@ -109,7 +107,6 @@ def test_atpbar_raise(
mock_reporter: mock.Mock,
caplog: pytest.LogCaptureFixture,
) -> None:

iterable = Iter(content)
returned = [e for e in atpbar.atpbar(iterable, name='given')]

Expand Down
4 changes: 1 addition & 3 deletions tests/test_run_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'''Test if example scripts run
'''
'''Test if example scripts run'''

from pathlib import Path

Expand Down

0 comments on commit f015a4c

Please sign in to comment.