Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ See also git tags: https://github.com/jedie/manageprojects/tags
[comment]: <> (✂✂✂ auto generated history start ✂✂✂)

* [**dev**](https://github.com/jedie/manageprojects/compare/v0.15.4...main)
* 2023-12-02 - Use code style tooling from cli-base-utilities
* 2023-12-01 - Apply https://github.com/jedie/cookiecutter_templates updates
* 2023-12-01 - Use: cli_base.cli_tools.test_utils.logs.AssertLogs
* [v0.15.4](https://github.com/jedie/manageprojects/compare/v0.15.3...v0.15.4)
Expand Down
25 changes: 10 additions & 15 deletions manageprojects/test_utils/click_cli_utils.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import warnings

import click
from bx_py_utils.path import assert_is_file
from cli_base.cli_tools.subprocess_utils import verbose_check_output
from cli_base.cli_tools.test_utils.rich_test_utils import NoColorEnvRichClick
from cli_base.cli_tools.test_utils.rich_test_utils import NoColorEnvRichClick, NoColorRichClickCli
from click.testing import CliRunner, Result


TERMINAL_WIDTH = 100


def subprocess_cli(*, cli_bin, args, exit_on_error=True):
assert_is_file(cli_bin)
return verbose_check_output(
cli_bin,
*args,
cwd=cli_bin.parent,
extra_env={
'COLUMNS': str(TERMINAL_WIDTH),
'NO_COLOR': '1',
'PYTHONUNBUFFERED': '1',
'TERM': 'dump',
},
exit_on_error=exit_on_error,
warnings.warn(
'Migrate to: cli_base.cli_tools.test_utils.rich_test_utils.NoColorRichClickCli context manager !',
DeprecationWarning,
stacklevel=2,
)
with NoColorRichClickCli() as cm:
stdout = cm.invoke(cli_bin=cli_bin, args=args, exit_on_error=exit_on_error)
return stdout


class ClickInvokeCliException(Exception):
Expand Down
40 changes: 3 additions & 37 deletions manageprojects/tests/test_project_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
from unittest import TestCase

from bx_py_utils.path import assert_is_file
from cli_base.cli_tools.code_style import assert_code_style
from packaging.version import Version

from manageprojects import __version__
from manageprojects.cli.cli_app import PACKAGE_ROOT
from manageprojects.test_utils.click_cli_utils import subprocess_cli
from manageprojects.test_utils.project_setup import check_editor_config, get_py_max_line_length
from manageprojects.utilities import code_style


class ProjectSetupTestCase(TestCase):
Expand All @@ -31,41 +30,8 @@ def test_version(self):
self.assertIn(f'manageprojects v{__version__}', output)

def test_code_style(self):
dev_cli_bin = PACKAGE_ROOT / 'dev-cli.py'
assert_is_file(dev_cli_bin)

try:
output = subprocess_cli(
cli_bin=dev_cli_bin,
args=('check-code-style',),
exit_on_error=False,
)
except subprocess.CalledProcessError as err:
self.assertIn('.venv/bin/darker', err.stdout) # darker was called?
else:
if 'Code style: OK' in output:
self.assertIn('.venv/bin/darker', output) # darker was called?
return # Nothing to fix -> OK

# Try to "auto" fix code style:

try:
output = subprocess_cli(
cli_bin=dev_cli_bin,
args=('fix-code-style',),
exit_on_error=False,
)
except subprocess.CalledProcessError as err:
output = err.stdout

self.assertIn('.venv/bin/darker', output) # darker was called?

# Check again and display the output:

try:
code_style.check(package_root=PACKAGE_ROOT)
except SystemExit as err:
self.assertEqual(err.code, 0, 'Code style error, see output above!')
return_code = assert_code_style(package_root=PACKAGE_ROOT)
self.assertEqual(return_code, 0, 'Code style error, see output above!')

def test_check_editor_config(self):
check_editor_config(package_root=PACKAGE_ROOT)
Expand Down
13 changes: 12 additions & 1 deletion manageprojects/utilities/code_style.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import warnings
from pathlib import Path

from cli_base.cli_tools.subprocess_utils import ToolsExecutor, verbose_check_call
Expand All @@ -15,7 +16,7 @@ def _call_darker(*args, package_root: Path, color: bool = True, verbose: bool =
final_args += list(args)

tools_executor = ToolsExecutor(cwd=package_root)
tools_executor.verbose_check_output(
tools_executor.verbose_check_call(
*final_args,
exit_on_error=True,
)
Expand All @@ -25,6 +26,11 @@ def fix(package_root: Path, color: bool = True, verbose: bool = False):
"""
Fix code style via darker
"""
warnings.warn(
'Migrate to: cli_base.cli_tools.code_style.fix !',
DeprecationWarning,
stacklevel=2,
)
_call_darker(color=color, verbose=verbose, package_root=package_root)
print('Code style fixed, OK.')
sys.exit(0)
Expand All @@ -34,6 +40,11 @@ def check(package_root: Path, color: bool = True, verbose: bool = False):
"""
Check code style by calling darker + flake8
"""
warnings.warn(
'Migrate to: cli_base.cli_tools.code_style.check !',
DeprecationWarning,
stacklevel=2,
)
_call_darker('--check', color=color, verbose=verbose, package_root=package_root)

if verbose:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = [
"codespell", # https://github.com/codespell-project/codespell
"mypy", # https://github.com/python/mypy

"cli-base-utilities>=0.5.0", # https://github.com/jedie/cli-base-utilities
"cli-base-utilities>=0.6.0", # https://github.com/jedie/cli-base-utilities
"click", # https://github.com/pallets/click/
"rich-click", # https://github.com/ewels/rich-click
"rich", # https://github.com/Textualize/rich
Expand Down
6 changes: 3 additions & 3 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ charset-normalizer==3.3.2 \
--hash=sha256:fd1abc0d89e30cc4e02e4064dc67fcc51bd941eb395c502aac3ec19fab46b519 \
--hash=sha256:ff8fa367d09b717b2a17a052544193ad76cd49979c805768879cb63d9ca50561
# via requests
cli-base-utilities==0.5.0 \
--hash=sha256:366caa000bb0908914bc09e7b9cc2b6921bcf51e0aa2a91ae36cd5e092d774d8 \
--hash=sha256:67eec2c61b00ed9f376ca364e6ef85d65db6c0908cf530d7015483ef2902f27e
cli-base-utilities==0.6.0 \
--hash=sha256:c3e0efafca519f7f79a1aff67d099987d849f1c3d795c4e605b6b9be49537712 \
--hash=sha256:e403c6e584508aa69cc093b7a325127f6ef9835624e4fde7f104e941314645a9
# via manageprojects (pyproject.toml)
click==8.1.7 \
--hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ charset-normalizer==3.3.2 \
--hash=sha256:fd1abc0d89e30cc4e02e4064dc67fcc51bd941eb395c502aac3ec19fab46b519 \
--hash=sha256:ff8fa367d09b717b2a17a052544193ad76cd49979c805768879cb63d9ca50561
# via requests
cli-base-utilities==0.5.0 \
--hash=sha256:366caa000bb0908914bc09e7b9cc2b6921bcf51e0aa2a91ae36cd5e092d774d8 \
--hash=sha256:67eec2c61b00ed9f376ca364e6ef85d65db6c0908cf530d7015483ef2902f27e
cli-base-utilities==0.6.0 \
--hash=sha256:c3e0efafca519f7f79a1aff67d099987d849f1c3d795c4e605b6b9be49537712 \
--hash=sha256:e403c6e584508aa69cc093b7a325127f6ef9835624e4fde7f104e941314645a9
# via manageprojects (pyproject.toml)
click==8.1.7 \
--hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \
Expand Down