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

submodules are only ignore if files_changed_only is True #76

Closed
2bndy5 opened this issue Jul 27, 2022 · 9 comments · Fixed by #81
Closed

submodules are only ignore if files_changed_only is True #76

2bndy5 opened this issue Jul 27, 2022 · 9 comments · Fixed by #81
Labels
bug Something isn't working

Comments

@2bndy5
Copy link
Collaborator

2bndy5 commented Jul 27, 2022

I noticed this on a repo I'm developing that has 4 submodules. When the CI runs

cpp-linter --files-changed-only=false

All the submodules are crawled as if they're part of the current repo's original sources.

Moving the algorithm that detects submodules from list_source_files() into parse_ignored_option() should fix this, but I have to be careful to consider if the user explicitly specifies a submodule to be not ignored.

2bndy5 added a commit that referenced this issue Jul 27, 2022
2bndy5 added a commit that referenced this issue Jul 27, 2022
normalize submodule path separators per runner's OS
@shenxianpeng
Copy link
Collaborator

When --files-changed-only=ture, it should ignore submodules.
When --files-changed-only=false, analyze any source files in the repo including submodules.

So the current behavior of --files-changed-only=false is not expected?

I'm wondering if we should change files-changed-only default value to true. I guess users only care about modified files, not all source files.

@2bndy5
Copy link
Collaborator Author

2bndy5 commented Jul 28, 2022

When --files-changed-only=false, analyze any source files in the repo including submodules.

This was not my original intention. It doesn't make sense (to me) for a linter to be concerned with external sources. That's why in the README, I noted the ignore option can be used to explicitly include submodules (just not hidden folders that begin with a . like .github).

I'm wondering if we should change files-changed-only default value to true. I guess users only care about modified files, not all source files.

I have no objections to this. I think this was the original default until we started encouraging users to have a actions/checkout step. I also expect most users only want the file changes analyzed. Personally, I've been using this action to check all sources in my projects (for completeness because I itch for that 💯 ). I haven't been using clang-tidy for anything lately (but that may change in the future).

@2bndy5
Copy link
Collaborator Author

2bndy5 commented Jul 28, 2022

I'm almost ready to draft a PR... There's a lot of changes, so the description will be wordy. I'd like to learn a bit more about pytest (& plugins) to optimize the unit tests I've written.

@shenxianpeng
Copy link
Collaborator

It doesn't make sense (to me) for a linter to be concerned with external sources

I agree we should only analyze any source files and ignore submodules when --files-changed-only=false

No worries, take your time. I'm also learning about pytest to refactor my bad smell unit tests :(

@2bndy5
Copy link
Collaborator Author

2bndy5 commented Jul 28, 2022

I might have to use a matrix in the CI to test various versions of python with various versions of clang-tools on various OSs... My new database test is failing in CI, but it passes fine locally.

@shenxianpeng
Copy link
Collaborator

It also failed in my local environment.

/home/ubuntu/.local/lib/python3.8/site-packages/requests/adapters.py:501: ConnectionError
--------------------------------------------- Captured log call ---------------------------------------------
WARNING  CPP Linter:run.py:340 Could not find pcsound/pcsound.c! Did you checkout the repo?
========================================== short test summary info ==========================================
FAILED tests/lines_changed_only/test_lines_changed_only.py::test_run_clang_format_diff_only - requests.exc...
FAILED tests/lines_changed_only/test_lines_changed_only.py::test_run_clang_format_diff_adds - requests.exc...
================================= 2 failed, 22 passed in 257.41s (0:04:17) =================================

It's hang and failed from tests/lines_changed_only/test_lines_changed_only.py::test_run_clang_format_diff_only

tests/ignored_paths/test_ignored_paths.py::test_not_ignored PASSED                                    [ 83%]
tests/ignored_paths/test_ignored_paths.py::test_ignore_submodule PASSED                               [ 87%]
tests/lines_changed_only/test_lines_changed_only.py::test_lines_changed_only PASSED                   [ 91%]
tests/lines_changed_only/test_lines_changed_only.py::test_run_clang_format_diff_only 

@2bndy5
Copy link
Collaborator Author

2bndy5 commented Jul 28, 2022

It failed locally for you because it couldn't download the source files from the commit that I'm using in the test.

The test that failed for you was the lines-changed-only test. The one that failed in CI was the database test.

@2bndy5 2bndy5 added the bug Something isn't working label Jul 28, 2022
@2bndy5
Copy link
Collaborator Author

2bndy5 commented Aug 3, 2022

I've been playing with test coverage to see what else needs to be tested. So far I'm (locally) getting 94% coverage if I exclude any functions that directly use the REST API for thread comments:
image

I also configured coverage.py to ignore code specific to type checking and anything related to using rich as a logging extension, thus __init__.py is 100% covered. cpp_linter/thread_comments.py is also ignored because we would need a real CI event to test that code.

@shenxianpeng I see you've already created a codecov token for cpp-linter/clang-tools-pip. Can you create a org secret with a new codecov token, so we can use it for multiple repos? Or does the token have to specific to a project?

ps - Ensuring the best coverage has caused further improvements to the code base.

@shenxianpeng
Copy link
Collaborator

The test coverage is already very high 👍

@2bndy5 I have created a org secret with a new codecov token and also removed codecov token for cpp-linter/clang-tools-pip, then rerun the test action of clang-tools-pip, it still works.

shenxianpeng pushed a commit that referenced this issue Aug 18, 2022
…ed fixes (#81)

* integrate mypy type checking into CI
* resolve #75
* resolve #73
* run pylint workflow on changes to workflow file

- fix a few long line warnings
- add rich to the py dev reqs
- add types-PyYAML to dev reqs

* resolve #76


normalize submodule path separators per runner's OS

* add unit tests for ignored paths

also make sure the current working directory is appended to the .gitmodules path

* run pytest in CI

- add pytest to dev reqs
- rename run-pylint.yml to run-dev-tests.yml
- install cpp-linter pkg in run-dev-tests.yml workflow
- upgrade actions/setup-python to v2 in run-dev-tests.yml workflow
- rename step in run-dev-tests.yml workflow

* resolve #74 and add unit tests for it

This allows the `lines-changed-only` option to accept the following values:
- false: All lines in a file are analyzed
- true: All lines in the diff are analyzed (including unchanged lines)
- strict: Only lines in the diff that contain additions are analyzed

gitignore some test resources as they are fetched running the tests.

Retain original repo structure when fetching files. This is only used when the user doesn't checkout the repo being analyzed.

* improve and test CLI arg parsing

* add unit test for database

also fix a typo in demo.hpp variable name

* switch to pre-commit; run pytest in a matrix

* parametrize  unit tests

* fix changes to dev-test yaml

* make database path absolute

* use pathlib to resolve() relative paths in test

* let db path be independent of repo-root w/o docker

* this fails locally

* show me value for RUNNER_WORKSPACE

* use gh workspace if not in docker env

* simplify the paths' concatenation

* fix assignment of `Globals.FILES`

* treat unsupport events like a push

* explicitly set a env var when using docker

* ammend some logic

* show me some contents of folders on docker

* hardcode the correct worspace dir

* remove unused import

* try detecting the docker env better

* set the docker env var w/ a str

* assume that RUNNER_WORKSPACE is abs

* use only relativer path to db on docker

* Revert "use only relativer path to db on docker"

This reverts commit 37e3083.

* better test coverage

* mkdocstring doesn't support `Tuple[x, x]` type

see mkdocstrings/griffe/#95

* fix workflow

* revert changes to `get_line_cnt_from_cols()`

* upload without codecov token??

* ensure LF used on demo src

* update workflow

* re-implement newer `get_line_cnt_from_cols()`

* switch to pyproject.toml (setup.py is a dummy now)

* resolve version exe path better

* ammend make_annotations() (& its tests)

* adjust for pypi releases

* allow running locally & fix duplicate log cmds

* use pathlib.Path to open files

* rely on pathlib, update pkg name & CI workflows

* `is_relative_to()` introduced in python v3.9

* `lstrip(".")` from file's extension

* tidy v13 use abs path to std libs in output error

* build/install wheel in test CI

* oops, use correct artifact name

* remove identifying info from test's event payload

* make files list simpler for any event

* ammend walking the repo files/folders

This could probably get changed to using pathlib's glob mechanism.

* replace os.walk() with pathlib's rglob()

* only upload coverage report once from test CI

* use OS dependent path separators for DB path

* resolve #82

* ensure tidy fixit_lines end w/ a LF

* workflow continue only if `latest` tag was added

* include v7-9 for CI tests

* fix docs about `parse_ignore_option()`

Also, docs show type annotations in the function signatures

* fix `TidyNotification.__repr__()`

* tell CI to download clang-tools v7-9

* support older versions of clang-tidy YML output

* don't try to traverse a `None` obj

* add common hooks to pre-commit config

* add more configs to toml

This removes the need for a separate .coveragerc file

pytest can be executed without args based on the config in the toml

* update event triggers on dev-test CI workflow

* sort requirements.txt contents

* split pre-commit step into its own CI workflow

update version of used (external) actions

* pleasing pre-commit hooks

* fix run-test.yml (trailing whitespaces)

* revise README & remove .ci-ignore file

* add code coverage badge to README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants