diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd067070..6ee58953 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,7 +103,7 @@ jobs: rm -rf branch-test git config --global init.defaultBranch develop mkdir branch-test && cd branch-test && git init - touch .styleguide && git add .styleguide && git commit -q -m "Initial commit" + touch .wpiformat && git add .wpiformat && git commit -q -m "Initial commit" if wpiformat; then exit 1 fi @@ -115,7 +115,7 @@ jobs: rm -rf branch-test git config --global init.defaultBranch develop mkdir branch-test && cd branch-test && git init - touch .styleguide && git add .styleguide && git commit -q -m "Initial commit" + touch .wpiformat && git add .wpiformat && git commit -q -m "Initial commit" wpiformat -default-branch develop # Verify wpiformat reports success if main branch exists @@ -125,7 +125,7 @@ jobs: rm -rf branch-test git config --global init.defaultBranch main mkdir branch-test && cd branch-test && git init - touch .styleguide && git add .styleguide && git commit -q -m "Initial commit" + touch .wpiformat && git add .wpiformat && git commit -q -m "Initial commit" wpiformat # Verify wpiformat reports success if master branch exists @@ -135,7 +135,7 @@ jobs: rm -rf branch-test git config --global init.defaultBranch master mkdir branch-test && cd branch-test && git init - touch .styleguide && git add .styleguide && git commit -q -m "Initial commit" + touch .wpiformat && git add .wpiformat && git commit -q -m "Initial commit" wpiformat - name: Delete branch-test folder diff --git a/.styleguide b/.wpiformat similarity index 100% rename from .styleguide rename to .wpiformat diff --git a/.styleguide-license b/.wpiformat-license similarity index 100% rename from .styleguide-license rename to .wpiformat-license diff --git a/wpiformat/README.md b/wpiformat/README.md index fd5f2bcb..4ca0ab8b 100644 --- a/wpiformat/README.md +++ b/wpiformat/README.md @@ -20,13 +20,13 @@ pip install wpiformat ## Project Setup -To use these tools with a new project, copy `.styleguide`, and `.styleguide-license` from the examples folder into the project and create a new `.clang-format` file based on the desired C/C++ style. +To use these tools with a new project, copy `.wpiformat`, and `.wpiformat-license` from the examples folder into the project and create a new `.clang-format` file based on the desired C/C++ style. Note: Since wpiformat already handles include ordering, it is recommended to use `SortIncludes: false` in `.clang-format`. -## .styleguide +## .wpiformat -wpiformat checks the current directory for the `.styleguide` file. If one doesn't exist, all parent directories are tried as well. This file contains groups of filename regular expressions. +wpiformat checks the current directory for the `.wpiformat` file. If one doesn't exist, all parent directories are tried as well. This file contains groups of filename regular expressions. ``` groupName { regex_here @@ -36,7 +36,7 @@ The regexes are matched using [re.search()](https://docs.python.org/3/library/re Empty config groups can be omitted. Directory separators must be "/", not "\\". During processing, they will be replaced internally with an os.sep that is automatically escaped for regexes. -See the `.styleguide` file in the docs/examples directory for all possible groups. +See the `.wpiformat` file in the docs/examples directory for all possible groups. ### Specifying C/C++ files to format @@ -73,17 +73,17 @@ For example, given a file at `allwpilib/src/main/native/include/wpiutil/support/ The `repoRootNameOverride` group allows one to override the repository name used in include guards. This is useful for giving subprojects within one repository different repository roots in their include guards. Only specify one name in this group because subsequent names will be ignored. -## .styleguide-license +## .wpiformat-license -This file contains the license header template. It should contain `Copyright (c)` followed by the company name and the string `{year}`. See the `.styleguide-license` file in the docs/examples directory. +This file contains the license header template. It should contain `Copyright (c)` followed by the company name and the string `{year}`. See the `.wpiformat-license` file in the docs/examples directory. -wpiformat checks the currently processed file's directory for a `.styleguide` file first and traverses up the directory tree if one isn't found. This allows templates which are closer to the processed file to override a project's main template. +wpiformat checks the currently processed file's directory for a `.wpiformat` file first and traverses up the directory tree if one isn't found. This allows templates which are closer to the processed file to override a project's main template. ### License header semantics The license header is always at the beginning of the file and ends after two newlines. If there isn't one, or it doesn't contain the required copyright contents, wpiformat inserts a new one containing the current year. -### `.styleguide-license` special variables +### `.wpiformat-license` special variables `{year}` is replaced with a year range from the earliest copyright year in the file to the current year. If the earliest year is the current year, only that year will be written. diff --git a/wpiformat/examples/.styleguide b/wpiformat/examples/.wpiformat similarity index 100% rename from wpiformat/examples/.styleguide rename to wpiformat/examples/.wpiformat diff --git a/wpiformat/examples/.styleguide-license b/wpiformat/examples/.wpiformat-license similarity index 100% rename from wpiformat/examples/.styleguide-license rename to wpiformat/examples/.wpiformat-license diff --git a/wpiformat/test/test_config.py b/wpiformat/test/test_config.py index 922c9613..e4f05e35 100644 --- a/wpiformat/test/test_config.py +++ b/wpiformat/test/test_config.py @@ -4,7 +4,7 @@ def test_config(): - config_file = Config(os.path.abspath(os.getcwd()), ".styleguide") + config_file = Config(os.path.abspath(os.getcwd()), ".wpiformat") assert config_file.is_modifiable_file( "." + os.sep + "wpiformat" + os.sep + "javaguidelink.png" ) diff --git a/wpiformat/test/test_licenseupdate.py b/wpiformat/test/test_licenseupdate.py index 1574d3d0..fcca09e1 100644 --- a/wpiformat/test/test_licenseupdate.py +++ b/wpiformat/test/test_licenseupdate.py @@ -227,7 +227,7 @@ def test_licenseupdate(): ) # Ensure excluded files won't be processed - config_file = Config(os.path.abspath(os.getcwd()), ".styleguide") + config_file = Config(os.path.abspath(os.getcwd()), ".wpiformat") assert not LicenseUpdate().should_process_file(config_file, "./Excluded.h") # Create git repo to test license years for commits @@ -235,12 +235,12 @@ def test_licenseupdate(): subprocess.run(["git", "init", "-q"]) # Add base files - with open(".styleguide-license", "w") as file: + with open(".wpiformat-license", "w") as file: file.write("// Copyright (c) {year}") - with open(".styleguide", "w") as file: + with open(".wpiformat", "w") as file: file.write("cppSrcFileInclude {\n" + r"\.cpp$") - subprocess.run(["git", "add", ".styleguide-license"]) - subprocess.run(["git", "add", ".styleguide"]) + subprocess.run(["git", "add", ".wpiformat-license"]) + subprocess.run(["git", "add", ".wpiformat"]) subprocess.run(["git", "commit", "-q", "-m", '"Initial commit"']) # Add file with commit date of last year and range through this year diff --git a/wpiformat/test/test_tasktest.py b/wpiformat/test/test_tasktest.py index fea0d9eb..db468c95 100644 --- a/wpiformat/test/test_tasktest.py +++ b/wpiformat/test/test_tasktest.py @@ -29,7 +29,7 @@ def run_and_check_file( input_contents = input_contents.replace("\n", os.linesep) expected_output_contents = expected_output_contents.replace("\n", os.linesep) - config_file = Config(os.path.abspath(os.getcwd()), ".styleguide") + config_file = Config(os.path.abspath(os.getcwd()), ".wpiformat") if task.should_process_file(config_file, filename): output, success = task.run_pipeline(config_file, filename, input_contents) @@ -59,7 +59,7 @@ def run_and_check_stdout( expected_output_contents -- expected output file contents expected_success -- whether run is expected to succeed """ - config_file = Config(os.path.abspath(os.getcwd()), ".styleguide") + config_file = Config(os.path.abspath(os.getcwd()), ".wpiformat") if task.should_process_file(config_file, filename): with redirect_stdout(io.StringIO()) as f: diff --git a/wpiformat/wpiformat/__init__.py b/wpiformat/wpiformat/__init__.py index 6d81c57d..8171ce0f 100644 --- a/wpiformat/wpiformat/__init__.py +++ b/wpiformat/wpiformat/__init__.py @@ -88,7 +88,12 @@ def proc_pipeline(filename: str) -> bool: Keyword arguments: filename -- filename """ - config_file = Config(os.path.dirname(filename), ".styleguide") + # TODO: Remove handling for deprecated .styleguide file + try: + config_file = Config(os.path.dirname(filename), ".wpiformat") + except OSError: + config_file = Config(os.path.dirname(filename), ".styleguide") + if verbose1 or verbose2: with print_lock: print("Processing", filename) @@ -130,7 +135,12 @@ def proc_standalone(filename: str) -> bool: Keyword arguments: filename -- filename """ - config_file = Config(os.path.dirname(filename), ".styleguide") + # TODO: Remove handling for deprecated .styleguide file + try: + config_file = Config(os.path.dirname(filename), ".wpiformat") + except OSError: + config_file = Config(os.path.dirname(filename), ".styleguide") + if verbose2: with print_lock: print("Processing", filename) @@ -180,7 +190,12 @@ def proc_batch(filenames: list[str]) -> bool: for subtask in task_pipeline: work = [] for filename in filenames: - config_file = Config(os.path.dirname(filename), ".styleguide") + # TODO: Remove handling for deprecated .styleguide file + try: + config_file = Config(os.path.dirname(filename), ".wpiformat") + except OSError: + config_file = Config(os.path.dirname(filename), ".styleguide") + if subtask.should_process_file(config_file, filename): work.append(filename) @@ -477,7 +492,11 @@ def main(): # Don't run tasks on modifiable or generated files work = [] for name in files: - config_file = Config(os.path.dirname(name), ".styleguide") + # TODO: Remove handling for deprecated .styleguide file + try: + config_file = Config(os.path.dirname(name), ".wpiformat") + except OSError: + config_file = Config(os.path.dirname(name), ".styleguide") if config_file.is_modifiable_file(name): continue diff --git a/wpiformat/wpiformat/config.py b/wpiformat/wpiformat/config.py index a509fcc3..60c561cd 100644 --- a/wpiformat/wpiformat/config.py +++ b/wpiformat/wpiformat/config.py @@ -46,6 +46,13 @@ def read_file(directory: str, filename: str) -> tuple[str, list[str]]: with open(filepath, "r") as file_contents: contents = file_contents.read().splitlines() Config.__config_cache[filepath] = contents + + # TODO: Remove deprecation message + if filename.startswith(".styleguide"): + print( + f"warning: rename deprecated {filepath} to {filepath.replace('styleguide', 'wpiformat')}" + ) + return filepath, contents except OSError as e: # .git files are ignored, which are created within submodules diff --git a/wpiformat/wpiformat/licenseupdate.py b/wpiformat/wpiformat/licenseupdate.py index 1a01ab94..fd1d47f4 100644 --- a/wpiformat/wpiformat/licenseupdate.py +++ b/wpiformat/wpiformat/licenseupdate.py @@ -137,9 +137,15 @@ def run_pipeline( ) -> tuple[str, bool]: linesep = super().get_linesep(lines) - _, license_template = Config.read_file( - os.path.dirname(os.path.abspath(filename)), ".styleguide-license" - ) + # TODO: Remove handling for deprecated .styleguide-license file + try: + _, license_template = Config.read_file( + os.path.dirname(os.path.abspath(filename)), ".wpiformat-license" + ) + except OSError: + _, license_template = Config.read_file( + os.path.dirname(os.path.abspath(filename)), ".styleguide-license" + ) # Get year when file was most recently modified in Git history #