diff --git a/.vscode/settings.json b/.vscode/settings.json index a232079..1433dd3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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, diff --git a/atpbar/callback.py b/atpbar/callback.py index dad9cce..d96ac60 100644 --- a/atpbar/callback.py +++ b/atpbar/callback.py @@ -9,7 +9,6 @@ class CallbackImp: - def __init__(self) -> None: self.reporter: ProgressReporter | None = None self._machine: StateMachine # to be set by the StateMachine @@ -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 diff --git a/atpbar/presentation/barjupyter.py b/atpbar/presentation/barjupyter.py index 624d0e5..2b36ca3 100755 --- a/atpbar/presentation/barjupyter.py +++ b/atpbar/presentation/barjupyter.py @@ -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) diff --git a/atpbar/presentation/bartty.py b/atpbar/presentation/bartty.py index 124e556..ca7a1a3 100755 --- a/atpbar/presentation/bartty.py +++ b/atpbar/presentation/bartty.py @@ -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 diff --git a/atpbar/presentation/base.py b/atpbar/presentation/base.py index bdc61ba..f7539b3 100755 --- a/atpbar/presentation/base.py +++ b/atpbar/presentation/base.py @@ -17,7 +17,6 @@ class Presentation(ABC): stdout_stderr_redirection = False def __init__(self) -> None: - self.out = sys.stdout self.err = sys.stderr @@ -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: @@ -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 diff --git a/atpbar/presentation/txtprint.py b/atpbar/presentation/txtprint.py index 30f1c68..31b07ec 100755 --- a/atpbar/presentation/txtprint.py +++ b/atpbar/presentation/txtprint.py @@ -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 @@ -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 diff --git a/atpbar/progress_report/reporter.py b/atpbar/progress_report/reporter.py index b9cf2d7..4096192 100755 --- a/atpbar/progress_report/reporter.py +++ b/atpbar/progress_report/reporter.py @@ -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 diff --git a/atpbar/stream/type.py b/atpbar/stream/type.py index 82476fb..ac36fcb 100644 --- a/atpbar/stream/type.py +++ b/atpbar/stream/type.py @@ -7,6 +7,7 @@ else: from typing_extensions import TypeAlias + class FD(Enum): STDOUT = 1 STDERR = 2 diff --git a/pyproject.toml b/pyproject.toml index 43a8d7b..5b84ffa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ @@ -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"] @@ -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 diff --git a/tests/eoferror/test_script_py.py b/tests/eoferror/test_script_py.py index 7b07ff1..069b234 100644 --- a/tests/eoferror/test_script_py.py +++ b/tests/eoferror/test_script_py.py @@ -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') diff --git a/tests/presentation/test_base.py b/tests/presentation/test_base.py index e16e866..b07f264 100644 --- a/tests/presentation/test_base.py +++ b/tests/presentation/test_base.py @@ -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 @@ -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 @@ -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 diff --git a/tests/progress_report/test_pickup.py b/tests/progress_report/test_pickup.py index bb9732c..543c1f5 100644 --- a/tests/progress_report/test_pickup.py +++ b/tests/progress_report/test_pickup.py @@ -8,7 +8,6 @@ class TestStart: - @pytest.fixture() def presentation(self) -> mock.Mock: return mock.Mock() @@ -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() @@ -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() diff --git a/tests/progress_report/test_reporter.py b/tests/progress_report/test_reporter.py index 1c5a7a0..4165821 100644 --- a/tests/progress_report/test_reporter.py +++ b/tests/progress_report/test_reporter.py @@ -34,7 +34,6 @@ def test_repr(obj: ProgressReporter) -> None: class TestReport: - def test_report_need_to_report( self, obj: ProgressReporter, diff --git a/tests/scenarios/test_last_report.py b/tests/scenarios/test_last_report.py index e1d1ab4..fdee86d 100644 --- a/tests/scenarios/test_last_report.py +++ b/tests/scenarios/test_last_report.py @@ -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: diff --git a/tests/scenarios/test_multiprocessing_pool.py b/tests/scenarios/test_multiprocessing_pool.py index 61b3e68..0b44c6b 100644 --- a/tests/scenarios/test_multiprocessing_pool.py +++ b/tests/scenarios/test_multiprocessing_pool.py @@ -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 ( diff --git a/tests/scenarios/test_multiprocessing_process.py b/tests/scenarios/test_multiprocessing_process.py index a13f1fc..0609ce5 100644 --- a/tests/scenarios/test_multiprocessing_process.py +++ b/tests/scenarios/test_multiprocessing_process.py @@ -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() diff --git a/tests/scenarios/test_nested_loops.py b/tests/scenarios/test_nested_loops.py index 89733cd..3cfce2d 100644 --- a/tests/scenarios/test_nested_loops.py +++ b/tests/scenarios/test_nested_loops.py @@ -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 diff --git a/tests/scenarios/test_one_loop.py b/tests/scenarios/test_one_loop.py index 6f1dfb1..69422cc 100644 --- a/tests/scenarios/test_one_loop.py +++ b/tests/scenarios/test_one_loop.py @@ -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() diff --git a/tests/scenarios/test_process_pool_executor.py b/tests/scenarios/test_process_pool_executor.py index 1fa51e2..f93f5df 100644 --- a/tests/scenarios/test_process_pool_executor.py +++ b/tests/scenarios/test_process_pool_executor.py @@ -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 diff --git a/tests/scenarios/test_thread_pool_executor.py b/tests/scenarios/test_thread_pool_executor.py index 4e0a656..ad7da9e 100644 --- a/tests/scenarios/test_thread_pool_executor.py +++ b/tests/scenarios/test_thread_pool_executor.py @@ -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: diff --git a/tests/scenarios/test_threading_thread.py b/tests/scenarios/test_threading_thread.py index d04bee9..33b81c3 100644 --- a/tests/scenarios/test_threading_thread.py +++ b/tests/scenarios/test_threading_thread.py @@ -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() diff --git a/tests/scenarios/test_utils.py b/tests/scenarios/test_utils.py index bc9d6a4..82ba6e2 100644 --- a/tests/scenarios/test_utils.py +++ b/tests/scenarios/test_utils.py @@ -5,7 +5,6 @@ def test_mock_presentations() -> None: - class MockException(Exception): pass diff --git a/tests/test_atpbar_name_raise.py b/tests/test_atpbar_name_raise.py index 7b6b24d..a7e7127 100644 --- a/tests/test_atpbar_name_raise.py +++ b/tests/test_atpbar_name_raise.py @@ -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)] @@ -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')] @@ -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')] diff --git a/tests/test_run_example.py b/tests/test_run_example.py index e479a4e..4f04121 100644 --- a/tests/test_run_example.py +++ b/tests/test_run_example.py @@ -1,6 +1,4 @@ -'''Test if example scripts run - -''' +'''Test if example scripts run''' from pathlib import Path