Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9cd1e5

Browse files
committed
upgrade_pythoncapi.py: C++ files, ignore .git directory
1 parent 0ed3209 commit b9cd1e5

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ Upgrade ``mod.c`` file::
4545

4646
python3 upgrade_pythoncapi.py mod.c
4747

48-
Upgrade all ``.c`` and ``.h`` files of a project::
48+
Upgrade all C and C++ files (``.c``, ``.h``, ``.cc``, ``.cpp``, ``.cxx`` and
49+
``.hpp`` files) of a project::
4950

5051
python3 upgrade_pythoncapi.py directory/
5152

upgrade_pythoncapi.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
INCLUDE_PYTHONCAPI_COMPAT = f'#include "{PYTHONCAPI_COMPAT_H}"'
1616
INCLUDE_PYTHONCAPI_COMPAT2 = f'#include <{PYTHONCAPI_COMPAT_H}>'
1717

18+
C_FILE_EXT = (
19+
# C language
20+
".c", ".h",
21+
# C++ language
22+
".cc", ".cpp", ".cxx", ".hpp",
23+
)
24+
IGNORE_DIRS = (".git", ".tox")
25+
1826

1927
# Match a C identifier: 'identifier', 'var_3', 'NameCamelCase'
2028
# Use \b to only match a full word: match "a_b", but not just "b" in "a_b".
@@ -64,7 +72,7 @@ def call_assign_regex(name):
6472

6573

6674
def is_c_filename(filename):
67-
return filename.endswith((".c", ".h"))
75+
return filename.endswith(C_FILE_EXT)
6876

6977

7078
class Operation:
@@ -496,10 +504,11 @@ def _walk_dir(self, path):
496504

497505
for dirpath, dirnames, filenames in os.walk(path):
498506
# Don't walk into .tox
499-
try:
500-
dirnames.remove(".tox")
501-
except ValueError:
502-
pass
507+
for ignore_name in IGNORE_DIRS:
508+
try:
509+
dirnames.remove(ignore_name)
510+
except ValueError:
511+
pass
503512
for filename in filenames:
504513
if is_c_filename(filename):
505514
yield os.path.join(dirpath, filename)

0 commit comments

Comments
 (0)