Skip to content

Commit ebbb6ae

Browse files
committed
Look for deprecated configs and warn about them
1 parent 20ab6dc commit ebbb6ae

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

wpiformat/wpiformat/__init__.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ def proc_pipeline(name):
8787
Keyword arguments:
8888
name -- file name string
8989
"""
90-
config_file = Config(os.path.dirname(name), ".wpiformat")
90+
try:
91+
config_file = Config(os.path.dirname(name), ".wpiformat")
92+
except OSError:
93+
# TODO: Remove handling for deprecated .styleguide file
94+
config_file = Config(os.path.dirname(name), ".styleguide")
95+
print("Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'.")
96+
9197
if verbose1 or verbose2:
9298
with print_lock:
9399
print("Processing", name)
@@ -129,7 +135,13 @@ def proc_standalone(name):
129135
Keyword arguments:
130136
name -- file name string
131137
"""
132-
config_file = Config(os.path.dirname(name), ".wpiformat")
138+
try:
139+
config_file = Config(os.path.dirname(name), ".wpiformat")
140+
except OSError:
141+
# TODO: Remove handling for deprecated .styleguide file
142+
config_file = Config(os.path.dirname(name), ".styleguide")
143+
print("Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'.")
144+
133145
if verbose2:
134146
with print_lock:
135147
print("Processing", name)
@@ -179,7 +191,15 @@ def proc_batch(files):
179191
for subtask in task_pipeline:
180192
work = []
181193
for name in files:
182-
config_file = Config(os.path.dirname(name), ".wpiformat")
194+
try:
195+
config_file = Config(os.path.dirname(name), ".wpiformat")
196+
except OSError:
197+
# TODO: Remove handling for deprecated .styleguide file
198+
config_file = Config(os.path.dirname(name), ".styleguide")
199+
print(
200+
"Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'."
201+
)
202+
183203
if subtask.should_process_file(config_file, name):
184204
work.append(name)
185205

@@ -477,7 +497,14 @@ def main():
477497
# Don't run tasks on modifiable or generated files
478498
work = []
479499
for name in files:
480-
config_file = Config(os.path.dirname(name), ".wpiformat")
500+
try:
501+
config_file = Config(os.path.dirname(name), ".wpiformat")
502+
except OSError:
503+
# TODO: Remove handling for deprecated .styleguide file
504+
config_file = Config(os.path.dirname(name), ".styleguide")
505+
print(
506+
"Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'."
507+
)
481508

482509
if config_file.is_modifiable_file(name):
483510
continue

wpiformat/wpiformat/config.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,13 @@ def read_file(directory, file_name):
4343
os.path.join(directory, file_name),
4444
file_contents.read().splitlines(),
4545
)
46-
except OSError:
46+
except OSError as e:
4747
# .git files are ignored, which are created within submodules
4848
if os.path.isdir(directory + os.sep + ".git"):
4949
print(
50-
"Error: config file '"
51-
+ file_name
52-
+ "' not found in '"
53-
+ directory
54-
+ "'"
50+
f"Error: config file '{file_name}' not found in '{directory}'"
5551
)
56-
sys.exit(1)
52+
raise e
5753
directory = os.path.dirname(directory)
5854

5955
def group(self, group_name):

wpiformat/wpiformat/licenseupdate.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,18 @@ def __try_string_search(self, lines, last_year, license_template):
135135
def run_pipeline(self, config_file, name, lines):
136136
linesep = super().get_linesep(lines)
137137

138-
_, license_template = Config.read_file(
139-
os.path.dirname(os.path.abspath(name)), ".wpiformat-license"
140-
)
138+
try:
139+
_, license_template = Config.read_file(
140+
os.path.dirname(os.path.abspath(name)), ".wpiformat-license"
141+
)
142+
except OSError:
143+
# TODO: Remove handling for deprecated .styleguide-license file
144+
_, license_template = Config.read_file(
145+
os.path.dirname(os.path.abspath(name)), ".styleguide-license"
146+
)
147+
print(
148+
"Warning: found deprecated '.styleguide-license' file. Rename to '.wpiformat-license'."
149+
)
141150

142151
# Get year when file was most recently modified in Git history
143152
#

0 commit comments

Comments
 (0)