Skip to content

Commit 15b96c4

Browse files
committed
Look for deprecated configs and warn about them
1 parent 9dc3e34 commit 15b96c4

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
@@ -86,7 +86,13 @@ def proc_pipeline(name):
8686
Keyword arguments:
8787
name -- file name string
8888
"""
89-
config_file = Config(os.path.dirname(name), ".wpiformat")
89+
try:
90+
config_file = Config(os.path.dirname(name), ".wpiformat")
91+
except OSError:
92+
# TODO: Remove handling for deprecated .styleguide file
93+
config_file = Config(os.path.dirname(name), ".styleguide")
94+
print("Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'.")
95+
9096
if verbose1 or verbose2:
9197
with print_lock:
9298
print("Processing", name)
@@ -128,7 +134,13 @@ def proc_standalone(name):
128134
Keyword arguments:
129135
name -- file name string
130136
"""
131-
config_file = Config(os.path.dirname(name), ".wpiformat")
137+
try:
138+
config_file = Config(os.path.dirname(name), ".wpiformat")
139+
except OSError:
140+
# TODO: Remove handling for deprecated .styleguide file
141+
config_file = Config(os.path.dirname(name), ".styleguide")
142+
print("Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'.")
143+
132144
if verbose2:
133145
with print_lock:
134146
print("Processing", name)
@@ -178,7 +190,15 @@ def proc_batch(files):
178190
for subtask in task_pipeline:
179191
work = []
180192
for name in files:
181-
config_file = Config(os.path.dirname(name), ".wpiformat")
193+
try:
194+
config_file = Config(os.path.dirname(name), ".wpiformat")
195+
except OSError:
196+
# TODO: Remove handling for deprecated .styleguide file
197+
config_file = Config(os.path.dirname(name), ".styleguide")
198+
print(
199+
"Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'."
200+
)
201+
182202
if subtask.should_process_file(config_file, name):
183203
work.append(name)
184204

@@ -443,7 +463,14 @@ def main():
443463
# Don't run tasks on modifiable or generated files
444464
work = []
445465
for name in files:
446-
config_file = Config(os.path.dirname(name), ".wpiformat")
466+
try:
467+
config_file = Config(os.path.dirname(name), ".wpiformat")
468+
except OSError:
469+
# TODO: Remove handling for deprecated .styleguide file
470+
config_file = Config(os.path.dirname(name), ".styleguide")
471+
print(
472+
"Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'."
473+
)
447474

448475
if config_file.is_modifiable_file(name):
449476
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)