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

Feature/add codespell support linting - issue #71 #75

Closed

Conversation

DanielOX
Copy link

@DanielOX DanielOX commented Dec 25, 2023

  1. added support for codespell in hooks.py along with black and flake8
  2. added codespell packages as requirements in setup.py
  3. added codespell support for ipynb/notebooks

Closes #71

cc: @edublancas

src/pkgmt/hook.py Outdated Show resolved Hide resolved
@edublancas
Copy link
Collaborator

the CI is failing. please check the tests and the linting. more info: https://ploomber-contributing.readthedocs.io/en/latest/contributing/submitting-pr.html

@DanielOX
Copy link
Author

Thanks, for letting me know i will look into it

@DanielOX
Copy link
Author

DanielOX commented Dec 26, 2023

I was able to pass the linting error raised by flake8 in github actions test. but moving on there these test cases which are failing, i am not sure how to proceed with these pytest cases.

here is the complete log test cases run on latest PR. @edublancas

============================= test session starts ==============================
platform linux -- Python 3.7.17, pytest-7.4.3, pluggy-1.2.0
rootdir: /home/runner/work/pkgmt/pkgmt
collected 247 items

src/pkgmt/assets/template/tests/test_sample.py .                         [  0%]
tests/test_changelog.py ..............................                   [ 12%]
tests/test_cli.py .................FFFFFF......F.F........               [ 28%]
tests/test_config.py ......                                              [ 31%]
tests/test_dependencies.py .                                             [ 31%]
tests/test_deprecation.py ......                                         [ 34%]
tests/test_github.py .....                                               [ 36%]
tests/test_links.py .........F..........                                 [ 44%]
tests/test_modified.py .........                                         [ 47%]
tests/test_new.py .                                                      [ 48%]
tests/test_test.py ..                                                    [ 48%]
tests/test_versioneer.py ............................................... [ 68%]
.........................................................                [ 91%]
tests/test_versioner_util.py ......................                      [100%]

=================================== FAILURES ===================================
_____________________ test_lint_error[lint tmp_folder1-1] ______________________

command = 'lint tmp_folder1', exit_code = 1
tmp_empty = '/tmp/pytest-of-runner/pytest-0/test_lint_error_lint_tmp_folde0'

    @pytest.mark.parametrize(
        "command,exit_code",
        [
            [
                "lint tmp_folder1",
                1,
            ],
            ["lint tmp_folder2", 0],
            ["lint", 1],
            ["lint . -e tmp_folder1", 0],
            ["lint . -e tmp_folder1 -e tmp_folder2", 0],
            ["lint . -e tmp_folder2", 1],
        ],
    )
    def test_lint_error(command, exit_code, tmp_empty):
        Path("pyproject.toml").touch()
        Path("tmp_folder1").mkdir()
        Path("tmp_folder1", "file.py").write_text("a=1\n")
        Path("tmp_folder2", "file.py").write_text("a = 1\n\n")
    
        runner = CliRunner()
        result = runner.invoke(cli.cli, command)
    
>       assert output in result.output
E       AssertionError: assert 'following command failed: black --check' in '==================== Running: flake8 . --extend-exclude tmp_folder1 ====================\n==================== Running: black --check . --extend-exclude tmp_folder1 ====================\n'
E        +  where '==================== Running: flake8 . --extend-exclude tmp_folder1 ====================\n==================== Running: black --check . --extend-exclude tmp_folder1 ====================\n' = <Result TypeError('sequence item 3: expected str instance, list found')>.output

/home/runner/work/pkgmt/pkgmt/tests/test_cli.py:265: AssertionError
----------------------------- Captured stdout call -----------------------------
./tmp_folder2/file.py:2:1: W391 blank line at end of file
----------------------------- Captured stderr call -----------------------------
would reformat /tmp/pytest-of-runner/pytest-0/test_lint_black_pyproj__tool_b1/tmp_folder2/file.py

Oh no! 💥 💔 💥
1 file would be reformatted.
_______________ test_check_if_broken_doesnt_accept_head_request ________________

    def test_check_if_broken_doesnt_accept_head_request():
        response = links.LinkChecker().check_if_broken("https://binder.ploomber.io/")
>       assert response.code == 405
E       assert None == 405
E        +  where None = (None) https://binder.ploomber.io.code/

tests/test_links.py:95: AssertionError
=============================== warnings summary ===============================
tests/test_versioneer.py::test_picks_up_first_module_under_src
  /opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/pkgmt/versioner/util.py:78: UserWarning: Found more than one dir, choosing the first one: package_name
    warnings.warn("Found more than one dir, " f"choosing the first one: {dirs[0]}")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/test_cli.py::test_lint_error[lint tmp_folder1-1] - AssertionError: assert 'The following command failed: black --check' in '==================== Running: flake8 tmp_folder1 ====================\n==================== Running: black --check tm...ailed: codespell tmp_folder1 *.ipynb --skip \\nTo fix it: Install nbqa jupytext and run: pkgmt format\nError linting\n'
 +  where '==================== Running: flake8 tmp_folder1 ====================\n==================== Running: black --check tm...ailed: codespell tmp_folder1 *.ipynb --skip \\nTo fix it: Install nbqa jupytext and run: pkgmt format\nError linting\n' = <Result SystemExit('Error linting')>.output
FAILED tests/test_cli.py::test_lint_error[lint tmp_folder2-0] - AssertionError: assert 1 == 0
 +  where 1 = <Result SystemExit('Error linting')>.exit_code
FAILED tests/test_cli.py::test_lint_error[lint-1] - AssertionError: assert 'The following command failed: black --check' in '==================== Running: flake8 . ====================\n==================== Running: black --check . ==========... command failed: codespell . *.ipynb --skip \\nTo fix it: Install nbqa jupytext and run: pkgmt format\nError linting\n'
 +  where '==================== Running: flake8 . ====================\n==================== Running: black --check . ==========... command failed: codespell . *.ipynb --skip \\nTo fix it: Install nbqa jupytext and run: pkgmt format\nError linting\n' = <Result SystemExit('Error linting')>.output
FAILED tests/test_cli.py::test_lint_error[lint . -e tmp_folder1-0] - AssertionError: assert 1 == 0
 +  where 1 = <Result TypeError('sequence item 3: expected str instance, list found')>.exit_code
FAILED tests/test_cli.py::test_lint_error[lint . -e tmp_folder1 -e tmp_folder2-0] - AssertionError: assert 1 == 0
 +  where 1 = <Result TypeError('sequence item 3: expected str instance, list found')>.exit_code
FAILED tests/test_cli.py::test_lint_error[lint . -e tmp_folder2-1] - AssertionError: assert 'The following command failed: black --check' in '==================== Running: flake8 . --extend-exclude tmp_folder2 ====================\n==================== Running: black --check . --extend-exclude tmp_folder2 ====================\n'
 +  where '==================== Running: flake8 . --extend-exclude tmp_folder2 ====================\n==================== Running: black --check . --extend-exclude tmp_folder2 ====================\n' = <Result TypeError('sequence item 3: expected str instance, list found')>.output
FAILED tests/test_cli.py::test_lint_black_pyproj[-command0-following command failed: black --check] - AssertionError: assert 'following command failed: black --check' in '==================== Running: flake8 . ====================\n==================== Running: black --check . ==========... command failed: codespell . *.ipynb --skip \\nTo fix it: Install nbqa jupytext and run: pkgmt format\nError linting\n'
 +  where '==================== Running: flake8 . ====================\n==================== Running: black --check . ==========... command failed: codespell . *.ipynb --skip \\nTo fix it: Install nbqa jupytext and run: pkgmt format\nError linting\n' = <Result SystemExit('Error linting')>.output
FAILED tests/test_cli.py::test_lint_black_pyproj[[tool.black]\nextend-exclude = "tmp_folder2"-command2-following command failed: black --check] - AssertionError: assert 'following command failed: black --check' in '==================== Running: flake8 . --extend-exclude tmp_folder1 ====================\n==================== Running: black --check . --extend-exclude tmp_folder1 ====================\n'
 +  where '==================== Running: flake8 . --extend-exclude tmp_folder1 ====================\n==================== Running: black --check . --extend-exclude tmp_folder1 ====================\n' = <Result TypeError('sequence item 3: expected str instance, list found')>.output
FAILED tests/test_links.py::test_check_if_broken_doesnt_accept_head_request - assert None == 405
 +  where None = (None) https://binder.ploomber.io.code/
============= 9 failed, 238 passed, 1 warning in 289.62s (0:04:49) =============
Error: Process completed with exit code 1.

@edublancas edublancas closed this Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add codespell to pkgmt lint and git hook
2 participants