-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Python: Extract files in hidden dirs by default #19424
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0c1b379
Python: Extract files in hidden dirs by default
tausbn 605f2bf
Python: Add integration test
tausbn 67d04d5
Python: Add change note
tausbn 2ded42c
Python: Update extractor tests
tausbn 61719cf
Python: Fix a bug in glob conversion
tausbn 98388be
Python: Remove special casing of hidden files
tausbn 96558b5
Python: Update test
tausbn 72ae633
Python: Update change note and extractor config
tausbn c8cca12
Python: Bump extractor version
tausbn 2158eaa
Python: Fix a bug in glob regex creation
tausbn 9ee3e4c
Python: Update change note
tausbn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
python/extractor/cli-integration-test/hidden-files/config.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: Test Config | ||
paths-ignore: | ||
- "**/.*/**" |
6 changes: 6 additions & 0 deletions
6
python/extractor/cli-integration-test/hidden-files/query-default.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
| name | | ||
+-------------------------------+ | ||
| .hidden_file.py | | ||
| another_non_hidden.py | | ||
| foo.py | | ||
| visible_file_in_hidden_dir.py | |
4 changes: 4 additions & 0 deletions
4
python/extractor/cli-integration-test/hidden-files/query-skipped.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
| name | | ||
+-----------------+ | ||
| .hidden_file.py | | ||
| foo.py | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import python | ||
|
||
select any(File f).getShortName() as name order by name |
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions
1
python/extractor/cli-integration-test/hidden-files/repo_dir/foo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print(42) |
24 changes: 24 additions & 0 deletions
24
python/extractor/cli-integration-test/hidden-files/test.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
set -Eeuo pipefail # see https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ | ||
|
||
set -x | ||
|
||
CODEQL=${CODEQL:-codeql} | ||
|
||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
cd "$SCRIPTDIR" | ||
|
||
rm -rf db db-skipped | ||
|
||
# Test 1: Default behavior should be to extract files in hidden directories | ||
$CODEQL database create db --language python --source-root repo_dir/ | ||
$CODEQL query run --database db query.ql > query-default.actual | ||
diff query-default.expected query-default.actual | ||
|
||
# Test 2: The default behavior can be overridden by setting `paths-ignore` in the config file | ||
$CODEQL database create db-skipped --language python --source-root repo_dir/ --codescanning-config=config.yml | ||
$CODEQL query run --database db-skipped query.ql > query-skipped.actual | ||
diff query-skipped.expected query-skipped.actual | ||
|
||
rm -rf db db-skipped |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
python/ql/lib/change-notes/2025-04-30-extract-hidden-files-by-default.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
category: minorAnalysis | ||
--- | ||
|
||
- The Python extractor now extracts files in hidden directories by default. If you would like to skip files in hidden directories, add `paths-ignore: ["**/.*/**"]` to your [Code Scanning config](https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning#specifying-directories-to-scan). If you would like to skip all hidden files, you can use `paths-ignore: ["**/.*"]`. When using the CodeQL CLI for extraction, specify the configuration (creating the configuration file if necessary) using the `--codescanning-config` option. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
| .hidden/inner/test.py | | ||
| .hidden/module.py | | ||
| folder/module.py | | ||
| package | | ||
| package/__init__.py | | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
| Module foo.bar | | ||
| Module foo.include_test | | ||
| Package foo | | ||
| Script hidden_foo.py | |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it, this is equivalent to:
which might be simpler, if
rstrip_only_repeated
was something that existed :-)I will not insist on rewriting this, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. In hindsight, perhaps I should have done
Or perhaps an even better idea would be to first transform all runs of
/
into single occurrences, and then only dolstrip
.I think I'll leave it as-is for now. At some point we can hopefully just get rid of this code altogether.