Skip to content

Commit

Permalink
manifest: better handling of path target
Browse files Browse the repository at this point in the history
When passing a `.` path while inside a package directory, it passed to
path restrict generator as a simple path, which resulted in broken
restrict which collected all ebuilds in the repository.

By using `os.path.relpath` to base of repository, we make sure the
correct path is passed and the correct restricts are generated.

Fixes: #85
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
  • Loading branch information
arthurzam committed Oct 14, 2022
1 parent 8bdc31e commit 6cf5a11
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/pkgdev/scripts/pkgdev_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def _restrict_targets(repo, targets):
for target in targets:
if os.path.exists(target):
try:
if target in repo:
target = os.path.relpath(target, repo.location)
restrictions.append(repo.path_restrict(target))
except ValueError as exc:
manifest.error(exc)
Expand Down
32 changes: 32 additions & 0 deletions tests/scripts/test_pkgdev_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,38 @@ def test_repo_cwd(self, repo, capsys, tool):
matches = [x.cpvstr for x in repo.itermatch(options.restriction)]
assert matches == ['cat/pkg-0']

def test_repo_relative_pkg(self, repo, capsys, tool):
repo.create_ebuild('cat/pkg-0')
repo.create_ebuild('cat/newpkg-0')
with chdir(pjoin(repo.location, 'cat/pkg')):
options, _ = tool.parse_args(['manifest', '.'])
matches = [x.cpvstr for x in repo.itermatch(options.restriction)]
assert matches == ['cat/pkg-0']

def test_repo_relative_category(self, repo, capsys, tool):
repo.create_ebuild('cat/pkg-0')
repo.create_ebuild('cat/newpkg-0')

with chdir(pjoin(repo.location, 'cat')):
options, _ = tool.parse_args(['manifest', 'pkg'])
matches = [x.cpvstr for x in repo.itermatch(options.restriction)]
assert matches == ['cat/pkg-0']

with chdir(pjoin(repo.location, 'cat')):
options, _ = tool.parse_args(['manifest', '.'])
matches = [x.cpvstr for x in repo.itermatch(options.restriction)]
assert set(matches) == {'cat/pkg-0', 'cat/newpkg-0'}

def test_repo_relative_outside(self, tmp_path, repo, capsys, tool):
repo.create_ebuild('cat/pkg-0')
(ebuild := tmp_path / 'pkg.ebuild').touch()
with pytest.raises(SystemExit) as excinfo:
with chdir(repo.location):
tool.parse_args(['manifest', str(ebuild)])
assert excinfo.value.code == 2
out, err = capsys.readouterr()
assert err.strip() == f"pkgdev manifest: error: {repo.repo_id!r} repo doesn't contain: {str(ebuild)!r}"

def test_dir_target(self, repo, capsys, tool):
repo.create_ebuild('cat/pkg-0')
with chdir(repo.location):
Expand Down

0 comments on commit 6cf5a11

Please sign in to comment.