Skip to content

Commit

Permalink
Look for deprecated configs and warn about them
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Nov 14, 2024
1 parent 9cec0e0 commit 9e46194
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
35 changes: 31 additions & 4 deletions wpiformat/wpiformat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ def proc_pipeline(name):
Keyword arguments:
name -- file name string
"""
config_file = Config(os.path.dirname(name), ".wpiformat")
try:
config_file = Config(os.path.dirname(name), ".wpiformat")
except OSError:
# TODO: Remove handling for deprecated .styleguide file
config_file = Config(os.path.dirname(name), ".styleguide")
print("Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'.")

if verbose1 or verbose2:
with print_lock:
print("Processing", name)
Expand Down Expand Up @@ -129,7 +135,13 @@ def proc_standalone(name):
Keyword arguments:
name -- file name string
"""
config_file = Config(os.path.dirname(name), ".wpiformat")
try:
config_file = Config(os.path.dirname(name), ".wpiformat")
except OSError:
# TODO: Remove handling for deprecated .styleguide file
config_file = Config(os.path.dirname(name), ".styleguide")
print("Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'.")

if verbose2:
with print_lock:
print("Processing", name)
Expand Down Expand Up @@ -179,7 +191,15 @@ def proc_batch(files):
for subtask in task_pipeline:
work = []
for name in files:
config_file = Config(os.path.dirname(name), ".wpiformat")
try:
config_file = Config(os.path.dirname(name), ".wpiformat")
except OSError:
# TODO: Remove handling for deprecated .styleguide file
config_file = Config(os.path.dirname(name), ".styleguide")
print(
"Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'."
)

if subtask.should_process_file(config_file, name):
work.append(name)

Expand Down Expand Up @@ -480,7 +500,14 @@ def main():
# Don't run tasks on modifiable or generated files
work = []
for name in files:
config_file = Config(os.path.dirname(name), ".wpiformat")
try:
config_file = Config(os.path.dirname(name), ".wpiformat")
except OSError:
# TODO: Remove handling for deprecated .styleguide file
config_file = Config(os.path.dirname(name), ".styleguide")
print(
"Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'."
)

if config_file.is_modifiable_file(name):
continue
Expand Down
10 changes: 3 additions & 7 deletions wpiformat/wpiformat/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,13 @@ def read_file(directory, file_name):
os.path.join(directory, file_name),
file_contents.read().splitlines(),
)
except OSError:
except OSError as e:
# .git files are ignored, which are created within submodules
if os.path.isdir(directory + os.sep + ".git"):
print(
"Error: config file '"
+ file_name
+ "' not found in '"
+ directory
+ "'"
f"Error: config file '{file_name}' not found in '{directory}'"
)
sys.exit(1)
raise e
directory = os.path.dirname(directory)

def group(self, group_name):
Expand Down
15 changes: 12 additions & 3 deletions wpiformat/wpiformat/licenseupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,18 @@ def __try_string_search(self, lines, last_year, license_template):
def run_pipeline(self, config_file, name, lines):
linesep = super().get_linesep(lines)

_, license_template = Config.read_file(
os.path.dirname(os.path.abspath(name)), ".wpiformat-license"
)
try:
_, license_template = Config.read_file(
os.path.dirname(os.path.abspath(name)), ".wpiformat-license"
)
except OSError:
# TODO: Remove handling for deprecated .styleguide-license file
_, license_template = Config.read_file(
os.path.dirname(os.path.abspath(name)), ".styleguide-license"
)
print(
"Warning: found deprecated '.styleguide-license' file. Rename to '.wpiformat-license'."
)

# Get year when file was most recently modified in Git history
#
Expand Down

0 comments on commit 9e46194

Please sign in to comment.