Skip to content

Commit 0c1b379

Browse files
committed
Python: Extract files in hidden dirs by default
Changes the default behaviour of the Python extractor so files inside hidden directories are extracted by default. Also adds an extractor option, `skip_hidden_directories`, which can be set to `true` in order to revert to the old behaviour. Finally, I made the logic surrounding what is logged in various cases a bit more obvious. Technically this changes the behaviour of the extractor (in that hidden excluded files will now be logged as `(excluded)`, but I think this makes more sense anyway.
1 parent abbf753 commit 0c1b379

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

python/codeql-extractor.yml

+7
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,10 @@ options:
4444
Use this setting with caution, the Python extractor requires Python 3 to run.
4545
type: string
4646
pattern: "^(py|python|python3)$"
47+
skip_hidden_directories:
48+
title: Controls whether hidden directories are skipped during extraction.
49+
description: >
50+
By default, CodeQL will extract all Python files, including ones located in hidden directories. By setting this option to true, these hidden directories will be skipped instead.
51+
Accepted values are true and false.
52+
type: string
53+
pattern: "^(true|false)$"

python/extractor/semmle/traverser.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,10 @@ def _treewalk(self, path):
8383
self.logger.debug("Ignoring %s (symlink)", fullpath)
8484
continue
8585
if isdir(fullpath):
86-
if fullpath in self.exclude_paths or is_hidden(fullpath):
87-
if is_hidden(fullpath):
88-
self.logger.debug("Ignoring %s (hidden)", fullpath)
89-
else:
90-
self.logger.debug("Ignoring %s (excluded)", fullpath)
86+
if fullpath in self.exclude_paths:
87+
self.logger.debug("Ignoring %s (excluded)", fullpath)
88+
elif is_hidden(fullpath):
89+
self.logger.debug("Ignoring %s (hidden)", fullpath)
9190
else:
9291
empty = True
9392
for item in self._treewalk(fullpath):
@@ -101,7 +100,12 @@ def _treewalk(self, path):
101100
self.logger.debug("Ignoring %s (filter)", fullpath)
102101

103102

104-
if os.name== 'nt':
103+
if os.environ.get("CODEQL_EXTRACTOR_PYTHON_OPTION_SKIP_HIDDEN_DIRECTORIES", "false") == "false":
104+
105+
def is_hidden(path):
106+
return False
107+
108+
elif os.name== 'nt':
105109
import ctypes
106110

107111
def is_hidden(path):

0 commit comments

Comments
 (0)