Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/rez/package_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def make_package(name: str, path: str,
The 'installed_variants' attribute on the `PackageMaker` instance will
be appended with variant(s) created by this function, if any.
"""
from rez.package_repository import package_repository_manager

maker = PackageMaker(name)
yield maker

Expand All @@ -222,18 +224,28 @@ def make_package(name: str, path: str,
with retain_cwd():
# install the package variant(s) into the filesystem package repo at `path`
for variant in src_variants:
variant_ = variant.install(path)
repository = package_repository_manager.get_repository(path)

base = repository.get_package_payload_path(
package_name=variant.name,
package_version=variant.version
)
repository.pre_variant_install(variant.resource)

base = variant_.base
if make_base and base:
os.makedirs(base, exist_ok=True)
os.chdir(base)
make_base(variant_, base)
make_base(variant, base)

if variant.index is None:
root = base
else:
root = os.path.join(base, variant._non_shortlinked_subpath)

root = variant_.root
if make_root and root:
os.makedirs(root, exist_ok=True)
os.chdir(root)
make_root(variant_, root)
make_root(variant, root)

variant_ = variant.install(path)
maker.installed_variants.append(variant_)
60 changes: 60 additions & 0 deletions src/rez/tests/test_package_maker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright Contributors to the Rez Project


"""
Test package maker.
"""
import os

from rez.tests.util import TestBase, TempdirMixin
from rez.package_maker import make_package


class TestPackages(TestBase, TempdirMixin):
@classmethod
def setUpClass(cls) -> None:
TempdirMixin.setUpClass()

cls.settings = dict()

@classmethod
def tearDownClass(cls) -> None:
TempdirMixin.tearDownClass()

def test_make_package(self):
'''Test make_package makes a package in structure we expect'''
def make_root(variant, root):
assert os.path.isdir(root)
assert variant.resource.repository_type == 'memory'

with open(os.path.join(root, 'payload.txt'), 'w'):
pass

with make_package('test_package1', self.root, make_root=make_root) as pkg:
pkg.version = '1.0.0'

assert os.path.isfile(os.path.join(self.root, 'test_package1', '1.0.0', 'package.py'))
assert os.path.isfile(os.path.join(self.root, 'test_package1', '1.0.0', 'payload.txt'))

def test_make_package_with_variant(self):
'''Test make_package makes a package with variants sub path'''
def make_root(variant, root):
with open(os.path.join(root, 'payload.txt'), 'w'):
pass

with make_package('test_package2', self.root, make_root=make_root) as pkg:
pkg.version = '1.0.1'
pkg.variants = [['python-3']]

payload_path = os.path.join(self.root, 'test_package2', '1.0.1', 'python-3', 'payload.txt')
assert os.path.isfile(payload_path)

def test_make_package_build_token(self):
'''Test make_package has a build prefix token while building payload'''
def make_base(variant, base):
assert os.path.isdir(base)
assert os.path.isfile(os.path.join(os.path.dirname(base), '.building2.0.1'))

with make_package('test_package3', self.root, make_base=make_base) as pkg:
pkg.version = '2.0.1'
Loading