Skip to content

Commit 9e46194

Browse files
committed
Look for deprecated configs and warn about them
1 parent 9cec0e0 commit 9e46194

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

@@ -480,7 +500,14 @@ def main():
480500
# Don't run tasks on modifiable or generated files
481501
work = []
482502
for name in files:
483-
config_file = Config(os.path.dirname(name), ".wpiformat")
503+
try:
504+
config_file = Config(os.path.dirname(name), ".wpiformat")
505+
except OSError:
506+
# TODO: Remove handling for deprecated .styleguide file
507+
config_file = Config(os.path.dirname(name), ".styleguide")
508+
print(
509+
"Warning: found deprecated '.styleguide' file. Rename to '.wpiformat'."
510+
)
484511

485512
if config_file.is_modifiable_file(name):
486513
continue

wpiformat/wpiformat/config.py

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

6056
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)