Skip to content

Commit

Permalink
spec: use new linting interface for sanity checks
Browse files Browse the repository at this point in the history
Switch from old sanity_check to new lint interface.

This shouldn't change functionality expect
slightly different output on .spec errors.

Related: #115

Change-Id: I3d3dc6819292fb19783f914e92f6e75afe010e51
  • Loading branch information
Jakub Ruzicka committed Feb 25, 2019
1 parent db4dbf4 commit a2acd11
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 45 deletions.
13 changes: 0 additions & 13 deletions rdopkg/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,6 @@ class InvalidAction(RdopkgException):
msg_fmt = "Invalid action: %(action)s"


class BuildArchSanityCheckFailed(RdopkgException):
msg_fmt = ("Due to mysterious ways of rpm, BuildArch needs to be placed "
"AFTER SourceX and PatchX lines in .spec file, "
"otherwise %%{patches} macro will be empty "
"and both %%autosetup and `git am %%{patches}` will fail.\n\n"
"Please move BuildArch AFTER SourceX and PatchX.")


class DuplicatePatchesBaseError(RdopkgException):
msg_fmt = ("Please make sure to only have one "
"# patches_base= entry in .spec")


class InvalidGitRef(RdopkgException):
msg_fmt = "Invalid git reference: %(ref)s"

Expand Down
2 changes: 0 additions & 2 deletions rdopkg/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ def run(action_runner, cargs, version=None):
except (
exception.ActionInProgress,
exception.BranchNotFound,
exception.BuildArchSanityCheckFailed,
exception.CantGuess,
exception.ConfigError,
exception.CommandNotFound,
exception.DebugAbort,
exception.DuplicatePatchesBaseError,
exception.FileNotFound,
exception.IncompleteChangelog,
exception.InvalidLintCheck,
Expand Down
31 changes: 3 additions & 28 deletions rdopkg/utils/specfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time

from rdopkg import exception
from rdopkg.utils import lint

RPM_AVAILABLE = False
try:
Expand Down Expand Up @@ -408,35 +409,9 @@ def get_patch_fns(self):
def wipe_patches(self):
self._txt = re.sub(r'\n+(?:(?:Patch|.patch)\d+[^\n]*)', '', self.txt)

def sanity_check_buildarch(self):
# make sure BuildArch is AFTER SourceX and PatchX lines,
# otherwise %{patches} macro is empty which causes trouble
bm = re.search(r'^BuildArch:', self.txt, flags=re.M)
if not bm:
return
bi = bm.start()
sm = re.search(r'^Source\d+:', self.txt, flags=re.M)
if sm:
si = sm.start()
if bi < si:
raise exception.BuildArchSanityCheckFailed()
pm = re.search(r'^Patch\d+:', self.txt, flags=re.M)
if pm:
pi = pm.start()
if bi < pi:
raise exception.BuildArchSanityCheckFailed()

def sanity_check_patches_base(self):
# duplicate patches_base might lead to unexpected behavior
bases = re.findall(r'^#\s*patches_base', self.txt, flags=re.M)
if len(bases) > 1:
raise exception.DuplicatePatchesBaseError()

def sanity_check(self):
method = self.patches_apply_method()
if method in ['git-am', 'autosetup']:
self.sanity_check_buildarch()
self.sanity_check_patches_base()
hints = lint.lint(self.fn, checks=['sanity'])
lint.lint_report(hints, error_level='E')

def patches_apply_method(self):
if '\ngit am %{patches}' in self.txt:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_update_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_update_git_am_buildarch_fail(tmpdir):
with dist_path.as_cwd():
common.prep_patches_branch()
common.add_patches(extra=True)
with pytest.raises(rdopkg.exception.BuildArchSanityCheckFailed):
with pytest.raises(rdopkg.exception.LintProblemsFound):
update_patches('master',
local_patches_branch='master-patches',
version='1.2.3')
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_update_double_patches_base(tmpdir):
dist_path = common.prep_spec_test(tmpdir, 'double-patches')
with dist_path.as_cwd():
common.prep_patches_branch()
with pytest.raises(rdopkg.exception.DuplicatePatchesBaseError):
with pytest.raises(rdopkg.exception.LintProblemsFound):
update_patches('master',
local_patches_branch='master-patches',
version='1.2.3')
Expand Down

0 comments on commit a2acd11

Please sign in to comment.