| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,7 +45,8 @@ Upgrade ``mod.c`` file:: | |||
| 45 | 45 | ||
| 46 | 46 | python3 upgrade_pythoncapi.py mod.c | |
| 47 | 47 | ||
| 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:: | ||
| 49 | 50 | ||
| 50 | 51 | python3 upgrade_pythoncapi.py directory/ | |
| 51 | 52 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,14 @@ | |||
| 15 | 15 | INCLUDE_PYTHONCAPI_COMPAT = f'#include "{PYTHONCAPI_COMPAT_H}"' | |
| 16 | 16 | INCLUDE_PYTHONCAPI_COMPAT2 = f'#include <{PYTHONCAPI_COMPAT_H}>' | |
| 17 | 17 | ||
| 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 | + | ||
| 18 | 26 | ||
| 19 | 27 | # Match a C identifier: 'identifier', 'var_3', 'NameCamelCase' | |
| 20 | 28 | # 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): | |||
| 64 | 72 | ||
| 65 | 73 | ||
| 66 | 74 | def is_c_filename(filename): | |
| 67 | - return filename.endswith((".c", ".h")) | ||
| 75 | + return filename.endswith(C_FILE_EXT) | ||
| 68 | 76 | ||
| 69 | 77 | ||
| 70 | 78 | class Operation: | |
@@ -496,10 +504,11 @@ def _walk_dir(self, path): | |||
| 496 | 504 | ||
| 497 | 505 | for dirpath, dirnames, filenames in os.walk(path): | |
| 498 | 506 | # 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 | ||
| 503 | 512 | for filename in filenames: | |
| 504 | 513 | if is_c_filename(filename): | |
| 505 | 514 | yield os.path.join(dirpath, filename) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments