예제 #1
0
def _copy_variants(context,
                   bundle_dir,
                   force=False,
                   skip_non_relocatable=False,
                   verbose=False):
    relocated_package_names = []
    repo_path = os.path.join(bundle_dir, "packages")

    for variant in context.resolved_packages:
        package = variant.parent

        if skip_non_relocatable and not package.is_relocatable:
            if verbose:
                print_warning("Skipped bundling of non-relocatable package %s",
                              package.qualified_name)
            continue

        copy_package(package=package,
                     dest_repository=repo_path,
                     variants=[variant.index],
                     force=force,
                     keep_timestamp=True,
                     verbose=verbose)

        relocated_package_names.append(package.name)

    return relocated_package_names
예제 #2
0
    def test_1(self):
        """Simple package copy, no variants, no overwrite."""
        self._reset_dest_repository()

        # make a copy of a package
        src_pkg = self._get_src_pkg("floob", "1.2.0")
        result = copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root
        )

        self._assert_copied(result, 1, 0)

        # check the copied package exists and matches
        dest_pkg = self._get_dest_pkg("floob", "1.2.0")
        result_variant = result["copied"][0][1]
        dest_variant = dest_pkg.iter_variants().next()
        self.assertEqual(dest_variant.handle, result_variant.handle)

        pyfile = os.path.join(dest_pkg.base, "python")
        ctime = os.stat(pyfile).st_ctime

        # copy again but with overwrite=False; should do nothing
        result = copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root
        )

        self._assert_copied(result, 0, 1)

        # check that package payload wasn't overwritten
        self.assertEqual(os.stat(pyfile).st_ctime, ctime)
예제 #3
0
    def test_2(self):
        """Package copy, no variants, overwrite."""
        self._reset_dest_repository()

        # make a copy of a package
        src_pkg = self._get_src_pkg("floob", "1.2.0")
        copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root
        )

        dest_pkg = self._get_dest_pkg("floob", "1.2.0")

        pyfile = os.path.join(dest_pkg.base, "python", "floob", "__init__.py")
        ctime = os.stat(pyfile).st_ctime

        # overwrite same package copy
        result = copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root,
            overwrite=True
        )

        self._assert_copied(result, 1, 0)

        # check that package payload was overwritten
        self.assertNotEqual(os.stat(pyfile).st_ctime, ctime)
예제 #4
0
    def test_8(self):
        """Ensure that include modules are copied."""
        self._reset_dest_repository()

        src_pkg = self._get_src_pkg("foo", "1.1.0")
        copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root,
        )

        dest_pkg = self._get_dest_pkg("foo", "1.1.0")
        dest_variant = next(dest_pkg.iter_variants())

        # do a resolve
        ctxt = ResolvedContext(
            ["foo==1.1.0"],
            package_paths=[self.dest_install_root, self.install_root]
        )

        resolved_variant = ctxt.get_resolved_package("foo")
        self.assertEqual(dest_variant.handle, resolved_variant.handle)

        # this can only match if the include module was copied with the package
        environ = ctxt.get_environ(parent_environ={})
        self.assertEqual(environ.get("EEK"), "2")
예제 #5
0
 def localise(self, packages):
     local_repo = config.get('local_packages_path')
     self.logger.info('Localising..')
     for package in packages:
         copy_package(package, local_repo, keep_timestamp=True)
     self.logger.info(f'{len(packages)} packages localised.')
     self.packagesChanged.emit()
예제 #6
0
    def test_8(self):
        """Ensure that include modules are copied."""
        self._reset_dest_repository()

        src_pkg = self._get_src_pkg("foo", "1.1.0")
        copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root,
        )

        dest_pkg = self._get_dest_pkg("foo", "1.1.0")
        dest_variant = dest_pkg.iter_variants().next()

        # do a resolve
        ctxt = ResolvedContext(
            ["foo==1.1.0"],
            package_paths=[self.dest_install_root, self.install_root]
        )

        resolved_variant = ctxt.get_resolved_package("foo")
        self.assertEqual(dest_variant.handle, resolved_variant.handle)

        # this can only match if the include module was copied with the package
        environ = ctxt.get_environ(parent_environ={})
        self.assertEqual(environ.get("EEK"), "2")
예제 #7
0
    def test_2(self):
        """Package copy, no variants, overwrite."""
        self._reset_dest_repository()

        # make a copy of a package
        src_pkg = self._get_src_pkg("floob", "1.2.0")
        copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root
        )

        dest_pkg = self._get_dest_pkg("floob", "1.2.0")

        pyfile = os.path.join(dest_pkg.base, "python")
        ctime = os.stat(pyfile).st_ctime

        if os.getenv("TRAVIS_OS_NAME") == "osx":
            # In case tests runs too fast
            time.sleep(2)

        # overwrite same package copy
        result = copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root,
            overwrite=True
        )

        self._assert_copied(result, 1, 0)

        # check that package payload was overwritten
        self.assertNotEqual(os.stat(pyfile).st_ctime, ctime)
예제 #8
0
    def test_1(self):
        """Simple package copy, no variants, no overwrite."""
        self._reset_dest_repository()

        # make a copy of a package
        src_pkg = self._get_src_pkg("floob", "1.2.0")
        result = copy_package(package=src_pkg,
                              dest_repository=self.dest_install_root)

        self._assert_copied(result, 1, 0)

        # check the copied package exists and matches
        dest_pkg = self._get_dest_pkg("floob", "1.2.0")
        result_variant = result["copied"][0][1]
        dest_variant = next(dest_pkg.iter_variants())
        self.assertEqual(dest_variant.handle, result_variant.handle)

        pyfile = os.path.join(dest_pkg.base, "python")
        ctime = os.stat(pyfile).st_ctime

        # copy again but with overwrite=False; should do nothing
        result = copy_package(package=src_pkg,
                              dest_repository=self.dest_install_root)

        self._assert_copied(result, 0, 1)

        # check that package payload wasn't overwritten
        self.assertEqual(os.stat(pyfile).st_ctime, ctime)
예제 #9
0
    def test_3(self):
        """Package copy, variants, overwrite and non-overwrite."""
        self._reset_dest_repository()

        # make a copy of a varianted package
        src_pkg = self._get_src_pkg("bah", "2.1")
        result = copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root
        )

        self._assert_copied(result, 2, 0)  # 2 variants

        # check the copied variants exist and match
        dest_pkg = self._get_dest_pkg("bah", "2.1")
        ctimes = []

        for index in (0, 1):
            result_variant = result["copied"][index][1]
            dest_variant = dest_pkg.get_variant(index)
            self.assertEqual(dest_variant.handle, result_variant.handle)

            pyfile = os.path.join(dest_variant.root, "python", "bah", "__init__.py")
            ctime = os.stat(pyfile).st_ctime
            ctimes.append(ctime)

        # copy variant with no overwrite, should do nothing
        result = copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root,
            variants=[1]
        )

        self._assert_copied(result, 0, 1)

        # copy variant with overwrite
        result = copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root,
            variants=[1],
            overwrite=True
        )

        self._assert_copied(result, 1, 0)

        # check copied variant is the one we expect
        dest_pkg = self._get_dest_pkg("bah", "2.1")
        result_variant = result["copied"][0][1]
        dest_variant = dest_pkg.get_variant(1)
        self.assertEqual(dest_variant.handle, result_variant.handle)

        # check copied variant payload was overwritten
        pyfile = os.path.join(dest_variant.root, "python", "bah", "__init__.py")
        self.assertNotEqual(os.stat(pyfile).st_ctime, ctimes[1])

        # check non-copied variant payload was not written
        skipped_variant = dest_pkg.get_variant(0)
        pyfile = os.path.join(skipped_variant.root, "python", "bah", "__init__.py")
        self.assertEqual(os.stat(pyfile).st_ctime, ctimes[0])
예제 #10
0
    def test_3(self):
        """Package copy, variants, overwrite and non-overwrite."""
        self._reset_dest_repository()

        # make a copy of a varianted package
        src_pkg = self._get_src_pkg("bah", "2.1")
        result = copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root
        )

        self._assert_copied(result, 2, 0)  # 2 variants

        # check the copied variants exist and match
        dest_pkg = self._get_dest_pkg("bah", "2.1")
        ctimes = []

        for index in (0, 1):
            result_variant = result["copied"][index][1]
            dest_variant = dest_pkg.get_variant(index)
            self.assertEqual(dest_variant.handle, result_variant.handle)

            pyfile = os.path.join(dest_variant.root, "python")
            ctime = os.stat(pyfile).st_ctime
            ctimes.append(ctime)

        # copy variant with no overwrite, should do nothing
        result = copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root,
            variants=[1]
        )

        self._assert_copied(result, 0, 1)

        # copy variant with overwrite
        result = copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root,
            variants=[1],
            overwrite=True
        )

        self._assert_copied(result, 1, 0)

        # check copied variant is the one we expect
        dest_pkg = self._get_dest_pkg("bah", "2.1")
        result_variant = result["copied"][0][1]
        dest_variant = dest_pkg.get_variant(1)
        self.assertEqual(dest_variant.handle, result_variant.handle)

        # check copied variant payload was overwritten
        pyfile = os.path.join(dest_variant.root, "python")
        self.assertNotEqual(os.stat(pyfile).st_ctime, ctimes[1])

        # check non-copied variant payload was not written
        skipped_variant = dest_pkg.get_variant(0)
        pyfile = os.path.join(skipped_variant.root, "python")
        self.assertEqual(os.stat(pyfile).st_ctime, ctimes[0])
예제 #11
0
    def test_5(self):
        """Package copy with standard, new timestamp."""
        self._reset_dest_repository()

        # wait 1 second to guarantee newer timestamp in copied pkg
        time.sleep(1)

        # copy package and overwrite timestamp
        src_pkg = self._get_src_pkg("floob", "1.2.0")
        copy_package(package=src_pkg, dest_repository=self.dest_install_root)

        # check copied variant contains expected timestamp
        dest_pkg = self._get_dest_pkg("floob", "1.2.0")
        self.assertTrue(dest_pkg.timestamp > src_pkg.timestamp)
예제 #12
0
    def test_6(self):
        """Package copy with keep_timestamp."""
        self._reset_dest_repository()

        # wait 1 second to ensure we don't just accidentally get same timestamp
        time.sleep(1)

        # copy package and overwrite timestamp
        src_pkg = self._get_src_pkg("floob", "1.2.0")
        copy_package(package=src_pkg,
                     dest_repository=self.dest_install_root,
                     keep_timestamp=True)

        # check copied variant contains expected timestamp
        dest_pkg = self._get_dest_pkg("floob", "1.2.0")
        self.assertEqual(dest_pkg.timestamp, src_pkg.timestamp)
예제 #13
0
    def _copy_variants(self):
        relocated_package_names = []

        for variant in self.context.resolved_packages:
            package = variant.parent

            if self.skip_non_relocatable and not package.is_relocatable:
                self._warning("Skipped bundling of non-relocatable package %s",
                              package.qualified_name)
                continue

            result = copy_package(package=package,
                                  dest_repository=self._repo_path,
                                  variants=[variant.index],
                                  force=self.force,
                                  keep_timestamp=True,
                                  verbose=self.verbose)

            assert "copied" in result
            assert len(result["copied"]) == 1
            src_variant, dest_variant = result["copied"][0]

            self.copied_variants[package.name] = (src_variant, dest_variant)
            self._info("Copied %s to %s", src_variant.uri, dest_variant.uri)

            relocated_package_names.append(package.name)

        return relocated_package_names
예제 #14
0
    def test_5(self):
        """Package copy with standard, new timestamp."""
        self._reset_dest_repository()

        # wait 1 second to guarantee newer timestamp in copied pkg
        time.sleep(1)

        # copy package and overwrite timestamp
        src_pkg = self._get_src_pkg("floob", "1.2.0")
        copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root
        )

        # check copied variant contains expected timestamp
        dest_pkg = self._get_dest_pkg("floob", "1.2.0")
        self.assertTrue(dest_pkg.timestamp > src_pkg.timestamp)
예제 #15
0
    def test_6(self):
        """Package copy with keep_timestamp."""
        self._reset_dest_repository()

        # wait 1 second to ensure we don't just accidentally get same timestamp
        time.sleep(1)

        # copy package and overwrite timestamp
        src_pkg = self._get_src_pkg("floob", "1.2.0")
        copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root,
            keep_timestamp=True
        )

        # check copied variant contains expected timestamp
        dest_pkg = self._get_dest_pkg("floob", "1.2.0")
        self.assertEqual(dest_pkg.timestamp, src_pkg.timestamp)
예제 #16
0
    def test_7(self):
        """Package copy with overrides."""
        self._reset_dest_repository()

        overrides = {
            "timestamp": 10000,
            "description": "this is a copy",
            "some_extra_key": True
        }

        # copy package and overwrite timestamp
        src_pkg = self._get_src_pkg("floob", "1.2.0")
        copy_package(package=src_pkg,
                     dest_repository=self.dest_install_root,
                     overrides=overrides)

        # check copied variant contains expected timestamp
        dest_pkg = self._get_dest_pkg("floob", "1.2.0")

        for k, v in list(overrides.items()):
            self.assertEqual(getattr(dest_pkg, k), v)
예제 #17
0
    def test_7(self):
        """Package copy with overrides."""
        self._reset_dest_repository()

        overrides = {
            "timestamp": 10000,
            "description": "this is a copy",
            "some_extra_key": True
        }

        # copy package and overwrite timestamp
        src_pkg = self._get_src_pkg("floob", "1.2.0")
        copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root,
            overrides=overrides
        )

        # check copied variant contains expected timestamp
        dest_pkg = self._get_dest_pkg("floob", "1.2.0")

        for k, v in overrides.iteritems():
            self.assertEqual(getattr(dest_pkg, k), v)
예제 #18
0
    def test_4(self):
        """Package copy with rename, reversion."""
        self._reset_dest_repository()

        # copy a package to a different name and version
        src_pkg = self._get_src_pkg("floob", "1.2.0")
        result = copy_package(package=src_pkg,
                              dest_repository=self.dest_install_root,
                              dest_name="flaab",
                              dest_version="5.4.1")

        self._assert_copied(result, 1, 0)

        # check copied variant is the one we expect
        dest_pkg = self._get_dest_pkg("flaab", "5.4.1")
        result_variant = result["copied"][0][1]
        dest_variant = next(dest_pkg.iter_variants())
        self.assertEqual(dest_variant.handle, result_variant.handle)
예제 #19
0
    def test_4(self):
        """Package copy with rename, reversion."""
        self._reset_dest_repository()

        # copy a package to a different name and version
        src_pkg = self._get_src_pkg("floob", "1.2.0")
        result = copy_package(
            package=src_pkg,
            dest_repository=self.dest_install_root,
            dest_name="flaab",
            dest_version="5.4.1"
        )

        self._assert_copied(result, 1, 0)

        # check copied variant is the one we expect
        dest_pkg = self._get_dest_pkg("flaab", "5.4.1")
        result_variant = result["copied"][0][1]
        dest_variant = dest_pkg.iter_variants().next()
        self.assertEqual(dest_variant.handle, result_variant.handle)
예제 #20
0
파일: cp.py 프로젝트: yawpitch/rez
def command(opts, parser, extra_arg_groups=None):
    import os
    import sys

    from rez.config import config
    from rez.package_repository import package_repository_manager
    from rez.package_copy import copy_package
    from rez.utils.formatting import PackageRequest
    from rez.packages_ import iter_packages

    if (not opts.dest_path) and not (opts.rename or opts.reversion):
        parser.error("--dest-path must be specified unless --rename or "
                     "--reversion are used.")

    # Load the source package.
    #

    if opts.paths:
        paths = opts.paths.split(os.pathsep)
        paths = [x for x in paths if x]
    elif opts.no_local:
        paths = config.nonlocal_packages_path
    else:
        paths = None

    req = PackageRequest(opts.PKG)

    it = iter_packages(name=req.name, range_=req.range_, paths=paths)

    src_pkgs = list(it)
    if not src_pkgs:
        print >> sys.stderr, "No matching packages found."
        sys.exit(1)

    if len(src_pkgs) > 1:
        print >> sys.stderr, "More than one package matches, please choose:"
        for pkg in sorted(src_pkgs, key=lambda x: x.version):
            print >> sys.stderr, pkg.qualified_name
        sys.exit(1)

    src_pkg = src_pkgs[0]

    # Determine repo and perform checks.
    #
    # A common mistake may be to specify a dest package path, rather than the
    # _repo_ path. This would cause a mess, since a package would be installed
    # into a nested location within an existing package.
    #
    if opts.dest_path:
        dest_pkg_repo = package_repository_manager.get_repository(
            opts.dest_path)

        if (not opts.allow_empty) and dest_pkg_repo.is_empty():
            print >> sys.stderr, (
                "Attempting to copy a package into an EMPTY repository. Are you "
                "sure that --dest-path is the correct path? This should not "
                "include package name and/or version."
                "\n\n"
                "If this is a valid new package repository, use the "
                "--allow-empty flag to continue.")
            sys.exit(1)
    else:
        dest_pkg_repo = src_pkg.repository

    # Perform the copy.
    #

    variants = opts.variants or None

    result = copy_package(package=src_pkg,
                          dest_repository=dest_pkg_repo,
                          dest_name=opts.rename,
                          dest_version=opts.reversion,
                          variants=variants,
                          overwrite=opts.overwrite,
                          shallow=opts.shallow,
                          keep_timestamp=opts.keep_timestamp,
                          force=opts.force,
                          verbose=opts.verbose,
                          dry_run=opts.dry_run)

    # Print info about the result.
    #

    copied = result["copied"]
    skipped = result["skipped"]

    if opts.dry_run:
        # show a good indication of target variant when it doesn't get created
        path = dest_pkg_repo.get_package_payload_path(
            package_name=opts.rename or src_pkg.name,
            package_version=opts.reversion or src_pkg.version)

        dry_run_uri = path + "/?"
        verb = "would be"
    else:
        verb = "were"

    # specific output for non-varianted packages
    if src_pkg.num_variants == 0:
        if copied:
            dest_pkg = copied[0][1].parent
            print("Copied %s to %s" % (src_pkg.uri, dest_pkg.uri))
        else:
            assert skipped
            dest_pkg = skipped[0][1].parent
            print(
                "Target package already exists: %s. Use 'overwrite' to replace it."
                % dest_pkg.uri)

    # varianted package
    else:
        if copied:
            print("%d variants %s copied:" % (len(copied), verb))

            for src_variant, dest_variant in copied:
                # None possible if dry_run
                if dest_variant is None:
                    dest_uri = dry_run_uri
                else:
                    dest_uri = dest_variant.uri

                print("  %s -> %s" % (src_variant.uri, dest_uri))

        if skipped:
            print("%d variants %s skipped (target exists):" %
                  (len(skipped), verb))
            for src_variant, dest_variant in skipped:
                print("  %s !-> %s" % (src_variant.uri, dest_variant.uri))
예제 #21
0
파일: cp.py 프로젝트: instinct-vfx/rez
def command(opts, parser, extra_arg_groups=None):
    import os
    import sys

    from rez.config import config
    from rez.package_repository import package_repository_manager
    from rez.package_copy import copy_package
    from rez.utils.formatting import PackageRequest
    from rez.packages_ import iter_packages

    if (not opts.dest_path) and not (opts.rename or opts.reversion):
        parser.error("--dest-path must be specified unless --rename or "
                     "--reversion are used.")

    # Load the source package.
    #

    if opts.paths:
        paths = opts.paths.split(os.pathsep)
        paths = [x for x in paths if x]
    elif opts.no_local:
        paths = config.nonlocal_packages_path
    else:
        paths = None

    req = PackageRequest(opts.PKG)

    it = iter_packages(
        name=req.name,
        range_=req.range_,
        paths=paths
    )

    src_pkgs = list(it)
    if not src_pkgs:
        print >> sys.stderr, "No matching packages found."
        sys.exit(1)

    if len(src_pkgs) > 1:
        print >> sys.stderr, "More than one package matches, please choose:"
        for pkg in sorted(src_pkgs, key=lambda x: x.version):
            print >> sys.stderr, pkg.qualified_name
        sys.exit(1)

    src_pkg = src_pkgs[0]

    # Determine repo and perform checks.
    #
    # A common mistake may be to specify a dest package path, rather than the
    # _repo_ path. This would cause a mess, since a package would be installed
    # into a nested location within an existing package.
    #
    if opts.dest_path:
        dest_pkg_repo = package_repository_manager.get_repository(opts.dest_path)

        if (not opts.allow_empty) and dest_pkg_repo.is_empty():
            print >> sys.stderr, (
                "Attempting to copy a package into an EMPTY repository. Are you "
                "sure that --dest-path is the correct path? This should not "
                "include package name and/or version."
                "\n\n"
                "If this is a valid new package repository, use the "
                "--allow-empty flag to continue."
            )
            sys.exit(1)
    else:
        dest_pkg_repo = src_pkg.repository

    # Perform the copy.
    #

    variants = opts.variants or None

    result = copy_package(
        package=src_pkg,
        dest_repository=dest_pkg_repo,
        dest_name=opts.rename,
        dest_version=opts.reversion,
        variants=variants,
        overwrite=opts.overwrite,
        shallow=opts.shallow,
        follow_symlinks=opts.follow_symlinks,
        keep_timestamp=opts.keep_timestamp,
        force=opts.force,
        verbose=opts.verbose,
        dry_run=opts.dry_run
    )

    # Print info about the result.
    #

    copied = result["copied"]
    skipped = result["skipped"]

    if opts.dry_run:
        # show a good indication of target variant when it doesn't get created
        path = dest_pkg_repo.get_package_payload_path(
            package_name=opts.rename or src_pkg.name,
            package_version=opts.reversion or src_pkg.version
        )

        dry_run_uri = path + "/?"
        verb = "would be"
    else:
        verb = "were"

    # specific output for non-varianted packages
    if src_pkg.num_variants == 0:
        if copied:
            dest_pkg = copied[0][1].parent
            print("Copied %s to %s" % (src_pkg.uri, dest_pkg.uri))
        else:
            assert skipped
            dest_pkg = skipped[0][1].parent
            print(
                "Target package already exists: %s. Use 'overwrite' to replace it."
                % dest_pkg.uri
            )

    # varianted package
    else:
        if copied:
            print("%d variants %s copied:" % (len(copied), verb))

            for src_variant, dest_variant in copied:
                # None possible if dry_run
                if dest_variant is None:
                    dest_uri = dry_run_uri
                else:
                    dest_uri = dest_variant.uri

                print("  %s -> %s" % (src_variant.uri, dest_uri))

        if skipped:
            print("%d variants %s skipped (target exists):" % (len(skipped), verb))
            for src_variant, dest_variant in skipped:
                print("  %s !-> %s" % (src_variant.uri, dest_variant.uri))
예제 #22
0
def move_package(package,
                 dest_repository,
                 keep_timestamp=False,
                 force=False,
                 verbose=False):
    """Move a package.

    Moving a package means copying the package to a destination repo, and
    ignoring (ie hiding - not removing) the source package. The package must
    not already exist in the destination repo.

    Args:
        package (`Package`): Package to move.
        dest_repository (`PackageRepository` or str): The package repository, or
            a package repository path, to move the package into.
        keep_timestamp (bool): By default, a newly copied package will get a
            new timestamp (because that's when it was added to the target repo).
            By setting this option to True, the original package's timestamp
            is kept intact.
        force (bool): Move the package regardless of its relocatable attribute.
            Use at your own risk (there is no guarantee the resulting package
            will be functional).
        verbose (bool): Verbose mode.

    Returns:
        `Package`: The newly created package in the destination repo.
    """
    def _info(msg, *nargs):
        if verbose:
            print_info(msg, *nargs)

    # get dest repo
    if isinstance(dest_repository, basestring):
        repo_path = dest_repository
        dest_pkg_repo = package_repository_manager.get_repository(repo_path)
    else:
        dest_pkg_repo = dest_repository

    # check that the package doesn't already exist in the dest repo
    pkg = dest_pkg_repo.get_package(package.name, package.version)
    if pkg:
        raise PackageMoveError("Package already exists at destination: %s" %
                               pkg.uri)

    # move the pkg as atomically as possible:
    #
    # 1. Hide the dest package (even tho it doesn't exist yet)
    # 2. Copy the package
    # 3. Unhide the dest package
    # 4. Hide the src package
    #

    # 1.
    dest_pkg_repo.ignore_package(package.name,
                                 package.version,
                                 allow_missing=True)
    _info("Ignored %s in %s ahead of time", package.qualified_name,
          dest_pkg_repo)

    try:
        # 2.
        result = copy_package(package=package,
                              dest_repository=dest_pkg_repo,
                              force=force,
                              keep_timestamp=keep_timestamp,
                              verbose=verbose)
    finally:
        # 3.
        dest_pkg_repo.unignore_package(package.name, package.version)
        _info("Unignored %s in %s", package.qualified_name, dest_pkg_repo)

    # 4.
    package.repository.ignore_package(package.name, package.version)
    _info("Ignored %s", package.uri)

    # finish up
    a_dest_variant = result["copied"][0][1]
    dest_pkg = a_dest_variant.parent

    _info("Package %s moved to %s", package.uri, dest_pkg.uri)
    return dest_pkg