Skip to content

Commit

Permalink
Fix W0135 reported by pylint
Browse files Browse the repository at this point in the history
W0135 -> contextmanager-generator-missing-cleanup

Expects try-finally around `yield`. Checked reported functions,
usually it's FP. In one case I changed the code to make it clear.
  • Loading branch information
pirat89 committed May 14, 2024
1 parent 02d7b68 commit 54fa3b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions repos/system_upgrade/common/libraries/dnfplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ def perform_transaction_install(target_userspace_info, storage_info, used_repos,

@contextlib.contextmanager
def _prepare_perform(used_repos, target_userspace_info, xfs_info, storage_info, target_iso=None):
# noqa: W0135; pylint: disable=contextmanager-generator-missing-cleanup
# NOTE(pstodulk): the pylint check is not valid in this case - finally is covered
# implicitly
reserve_space = overlaygen.get_recommended_leapp_free_space(target_userspace_info.path)
with _prepare_transaction(used_repos=used_repos,
target_userspace_info=target_userspace_info
Expand Down
14 changes: 10 additions & 4 deletions repos/system_upgrade/common/libraries/overlaygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ def _prepare_required_mounts(scratch_dir, mounts_dir, storage_info, scratch_rese

@contextlib.contextmanager
def _build_overlay_mount(root_mount, mounts):
# noqa: W0135; pylint: disable=contextmanager-generator-missing-cleanup
# NOTE(pstodulk): the pylint check is not valid in this case - finally is covered
# implicitly
if not root_mount:
raise StopActorExecutionError('Root mount point has not been prepared for overlayfs.')
if not mounts:
Expand Down Expand Up @@ -519,6 +522,9 @@ def _mount_dnf_cache(overlay_target):
"""
Convenience context manager to ensure bind mounted /var/cache/dnf and removal of the mount.
"""
# noqa: W0135; pylint: disable=contextmanager-generator-missing-cleanup
# NOTE(pstodulk): the pylint check is not valid in this case - finally is covered
# implicitly
with mounting.BindMount(
source='/var/cache/dnf',
target=os.path.join(overlay_target, 'var', 'cache', 'dnf')) as cache_mount:
Expand Down Expand Up @@ -570,6 +576,9 @@ def create_source_overlay(mounts_dir, scratch_dir, xfs_info, storage_info, mount
:type scratch_reserve: Optional[int]
:rtype: mounting.BindMount or mounting.NullMount
"""
# noqa: W0135; pylint: disable=contextmanager-generator-missing-cleanup
# NOTE(pstodulk): the pylint check is not valid in this case - finally is covered
# implicitly
api.current_logger().debug('Creating source overlay in {scratch_dir} with mounts in {mounts_dir}'.format(
scratch_dir=scratch_dir, mounts_dir=mounts_dir))
try:
Expand All @@ -589,11 +598,8 @@ def create_source_overlay(mounts_dir, scratch_dir, xfs_info, storage_info, mount
with _build_overlay_mount(root_overlay, mounts) as overlay:
with _mount_dnf_cache(overlay.target):
yield overlay
except Exception:
finally:
cleanup_scratch(scratch_dir, mounts_dir)
raise
# cleanup always now
cleanup_scratch(scratch_dir, mounts_dir)


# #############################################################################
Expand Down

0 comments on commit 54fa3b0

Please sign in to comment.