Skip to content

Commit

Permalink
Fix deprecations (#40)
Browse files Browse the repository at this point in the history
* Migrate from deprecated  rmtree arg
onerror is now deprecated for onexc

* Use f-strings
  • Loading branch information
ruffsl authored Feb 8, 2024
1 parent 1ba8923 commit 35660e2
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion colcon_clean/base_handler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def add_base_handler_arguments(parser):
choices=extension_keys,
default=extension_keys,
help='Select base names to clean in workspace '
'(default: {extension_keys})'.format_map(locals()))
f'(default: {extension_keys})')

group.add_argument(
'--base-ignore', nargs='*', metavar='BASE_NAME',
Expand Down
2 changes: 1 addition & 1 deletion colcon_clean/base_handler/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def add_arguments(self, *, parser): # noqa: D102
'--build-base',
default=self.base_path,
help='The base path for all build directories '
'(default: {self.base_path})'.format_map(locals()))
f'(default: {self.base_path})')

def get_workspace_paths(self, *, args): # noqa: D102
return [args.build_base]
Expand Down
2 changes: 1 addition & 1 deletion colcon_clean/base_handler/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def add_arguments(self, *, parser): # noqa: D102
'--install-base',
default=self.base_path,
help='The base path for all install directories '
'(default: {self.base_path})'.format_map(locals()))
f'(default: {self.base_path})')

def get_workspace_paths(self, *, args): # noqa: D102
return [args.install_base]
Expand Down
2 changes: 1 addition & 1 deletion colcon_clean/base_handler/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def add_arguments(self, *, parser): # noqa: D102
'--log-base',
default=self.base_path,
help='The base path for all log directories '
'(default: {self.base_path})'.format_map(locals()))
f'(default: {self.base_path})')

def get_workspace_paths(self, *, args): # noqa: D102
return [args.log_base]
Expand Down
2 changes: 1 addition & 1 deletion colcon_clean/base_handler/test_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def add_arguments(self, *, parser): # noqa: D102
'--test-result-base',
default=self.base_path,
help='The base path for all test_result directories '
'(default: {self.base_path})'.format_map(locals()))
f'(default: {self.base_path})')

def get_workspace_paths(self, *, args): # noqa: D102
return [args.test_result_base]
Expand Down
15 changes: 6 additions & 9 deletions colcon_clean/subverb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,17 @@ def clean_paths(paths, confirmed=False):
_clean_path(path)


def _onerror(func, path, excinfo): # pragma: no cover
if excinfo[0] in (OSError, PermissionError): # pragma: no branch
logger.warning(
"Skipping path: '{path}'".format_map(locals()))
logger.info(
"Skipping info: '{excinfo[1]}'".format_map(locals()))
def _onexc(func, path, excinfo): # pragma: no cover
if isinstance(excinfo, (PermissionError, OSError)): # pragma: no branch
logger.warning(f"Skipping path: '{path}'")
logger.info(f"Skipping info: '{excinfo}'")
return
raise


def _clean_path(path):
logger.info(
"Cleaning path: '{path}'".format_map(locals()))
logger.info(f"Cleaning path: '{path}'")
if path.is_dir():
shutil.rmtree(path, onerror=_onerror)
shutil.rmtree(path, onexc=_onexc)
else:
path.unlink()
4 changes: 1 addition & 3 deletions colcon_clean/subverb/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def main(self, *, context): # noqa: D102

for base_name in args.base_select:
if base_name in args.base_ignore:
logger.info(
"Ignoring base handler for selection '{base_name}'"
.format_map(locals()))
logger.info(f"Ignoring base handler for selection '{base_name}'")
continue
base_handler_extension = base_handler_extensions[base_name]
for decorator in decorators:
Expand Down
4 changes: 1 addition & 3 deletions colcon_clean/subverb/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def main(self, *, context): # noqa: D102

for base_name in args.base_select:
if base_name in args.base_ignore:
logger.info(
"Ignoring base handler for selection '{base_name}'"
.format_map(locals()))
logger.info(f"Ignoring base handler for selection '{base_name}'")
continue
base_handler_extension = base_handler_extensions[base_name]
workspace_paths = \
Expand Down
1 change: 1 addition & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mkdtemp
monkeypatch
nargs
noqa
onexc
pathlib
plugin
pydocstyle
Expand Down

0 comments on commit 35660e2

Please sign in to comment.