Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove rez.vendor.enum #1647

Closed
Closed
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
167 changes: 106 additions & 61 deletions src/rez/build_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@


from rez.packages import iter_packages
from rez.exceptions import BuildProcessError, BuildContextResolveError, \
ReleaseHookCancellingError, RezError, ReleaseError, BuildError, \
ReleaseVCSError, _NeverError
from rez.exceptions import (
BuildProcessError,
BuildContextResolveError,
ReleaseHookCancellingError,
RezError,
ReleaseError,
BuildError,
ReleaseVCSError,
_NeverError,
)
from rez.utils.logging_ import print_warning
from rez.utils.colorize import heading, Printer
from rez.resolved_context import ResolvedContext
from rez.release_hook import create_release_hooks
from rez.resolver import ResolverStatus
from rez.config import config
from rez.vendor.enum import Enum
from contextlib import contextmanager
from enum import Enum
from shlex import quote
import getpass
import os.path
Expand All @@ -26,12 +33,22 @@
def get_build_process_types():
"""Returns the available build process implementations."""
from rez.plugin_managers import plugin_manager
return plugin_manager.get_plugins('build_process')


def create_build_process(process_type, working_dir, build_system, package=None,
vcs=None, ensure_latest=True, skip_repo_errors=False,
ignore_existing_tag=False, verbose=False, quiet=False):
return plugin_manager.get_plugins("build_process")


def create_build_process(
process_type,
working_dir,
build_system,
package=None,
vcs=None,
ensure_latest=True,
skip_repo_errors=False,
ignore_existing_tag=False,
verbose=False,
quiet=False,
):
"""Create a :class:`BuildProcess` instance.
.. warning::
Expand All @@ -40,25 +57,29 @@ def create_build_process(process_type, working_dir, build_system, package=None,
and will be removed in rez 3.0.0
"""
from rez.plugin_managers import plugin_manager

process_types = get_build_process_types()
if process_type not in process_types:
raise BuildProcessError("Unknown build process: %r" % process_type)

cls = plugin_manager.get_plugin_class('build_process', process_type)
cls = plugin_manager.get_plugin_class("build_process", process_type)

return cls(working_dir, # ignored (deprecated)
build_system,
package=package, # ignored (deprecated)
vcs=vcs,
ensure_latest=ensure_latest,
skip_repo_errors=skip_repo_errors,
ignore_existing_tag=ignore_existing_tag,
verbose=verbose,
quiet=quiet)
return cls(
working_dir, # ignored (deprecated)
build_system,
package=package, # ignored (deprecated)
vcs=vcs,
ensure_latest=ensure_latest,
skip_repo_errors=skip_repo_errors,
ignore_existing_tag=ignore_existing_tag,
verbose=verbose,
quiet=quiet,
)


class BuildType(Enum):
""" Enum to represent the type of build."""
"""Enum to represent the type of build."""

local = 0
central = 1

Expand All @@ -73,13 +94,23 @@ class BuildProcess(object):
VCS. This is an abstract base class, you should use a BuildProcess
subclass.
"""

@classmethod
def name(cls):
raise NotImplementedError

def __init__(self, working_dir, build_system, package=None, vcs=None,
ensure_latest=True, skip_repo_errors=False,
ignore_existing_tag=False, verbose=False, quiet=False):
def __init__(
self,
working_dir,
build_system,
package=None,
vcs=None,
ensure_latest=True,
skip_repo_errors=False,
ignore_existing_tag=False,
verbose=False,
quiet=False,
):
"""Create a BuildProcess.
Args:
Expand Down Expand Up @@ -110,13 +141,15 @@ def __init__(self, working_dir, build_system, package=None, vcs=None,

if vcs and vcs.pkg_root != self.working_dir:
raise BuildProcessError(
"Build process was instantiated with a mismatched VCS instance")
"Build process was instantiated with a mismatched VCS instance"
)

if os.path.isabs(self.package.config.build_directory):
self.build_path = self.package.config.build_directory
else:
self.build_path = os.path.join(self.working_dir,
self.package.config.build_directory)
self.build_path = os.path.join(
self.working_dir, self.package.config.build_directory
)

@property
def package(self):
Expand Down Expand Up @@ -177,8 +210,8 @@ def get_changelog(self):


class BuildProcessHelper(BuildProcess):
"""A BuildProcess base class with some useful functionality.
"""
"""A BuildProcess base class with some useful functionality."""

@contextmanager
def repo_operation(self):
exc_type = ReleaseVCSError if self.skip_repo_errors else _NeverError
Expand All @@ -195,7 +228,8 @@ def visit_variants(self, func, variants=None, **kwargs):
if invalid_variants:
raise BuildError(
"The package does not contain the variants: %s"
% ", ".join(str(x) for x in sorted(invalid_variants)))
% ", ".join(str(x) for x in sorted(invalid_variants))
)

# iterate over variants
results = []
Expand All @@ -205,7 +239,8 @@ def visit_variants(self, func, variants=None, **kwargs):
if variants and variant.index not in variants:
self._print_header(
"Skipping variant %s (%s)..."
% (variant.index, self._n_of_m(variant)))
% (variant.index, self._n_of_m(variant))
)
continue

# visit the variant
Expand All @@ -226,18 +261,16 @@ def get_package_install_path(self, path):
pkg_repo = package_repository_manager.get_repository(path)

return pkg_repo.get_package_payload_path(
package_name=self.package.name,
package_version=self.package.version
package_name=self.package.name, package_version=self.package.version
)

def create_build_context(self, variant, build_type, build_path):
"""Create a context to build the variant within."""
request = variant.get_requires(build_requires=True,
private_build_requires=True)
request = variant.get_requires(build_requires=True, private_build_requires=True)

req_strs = map(str, request)
quoted_req_strs = map(quote, req_strs)
self._print("Resolving build environment: %s", ' '.join(quoted_req_strs))
self._print("Resolving build environment: %s", " ".join(quoted_req_strs))

if build_type == BuildType.local:
packages_path = self.package.config.packages_path
Expand All @@ -259,10 +292,12 @@ def create_build_context(self, variant, build_type, build_path):
package_filter = None

# create the build context
context = ResolvedContext(request,
package_paths=packages_path,
package_filter=package_filter,
building=True)
context = ResolvedContext(
request,
package_paths=packages_path,
package_filter=package_filter,
building=True,
)
if self.verbose:
context.print_info()

Expand Down Expand Up @@ -299,7 +334,8 @@ def pre_release(self):
raise ReleaseError(
"Cannot release - the current package version '%s' is "
"already tagged in the repository. Use --ignore-existing-tag "
"to force the release" % self.package.version)
"to force the release" % self.package.version
)

it = iter_packages(self.package.name, paths=[release_path])
packages = sorted(it, key=lambda x: x.version, reverse=True)
Expand All @@ -310,15 +346,17 @@ def pre_release(self):
latest_package = packages[0]
if latest_package.uuid and latest_package.uuid != self.package.uuid:
raise ReleaseError(
"Cannot release - the packages are not the same (UUID mismatch)")
"Cannot release - the packages are not the same (UUID mismatch)"
)

# test that a newer package version hasn't already been released
if self.ensure_latest:
for package in packages:
if package.version > self.package.version:
raise ReleaseError(
"Cannot release - a newer package version already "
"exists (%s)" % package.uri)
"exists (%s)" % package.uri
)
else:
break

Expand Down Expand Up @@ -347,20 +385,26 @@ def run_hooks(self, hook_event, **kwargs):
hooks = create_release_hooks(hook_names, self.working_dir)

for hook in hooks:
debug_print("Running %s hook '%s'...",
hook_event.label, hook.name())
debug_print("Running %s hook '%s'...", hook_event.label, hook.name())
try:
func = getattr(hook, hook_event.__name__)
func(user=getpass.getuser(), **kwargs)
except ReleaseHookCancellingError as e:
raise ReleaseError(
"%s cancelled by %s hook '%s': %s:\n%s"
% (hook_event.noun, hook_event.label, hook.name(),
e.__class__.__name__, str(e)))
% (
hook_event.noun,
hook_event.label,
hook.name(),
e.__class__.__name__,
str(e),
)
)
except RezError:
debug_print("Error in %s hook '%s': %s:\n%s"
% (hook_event.label, hook.name(),
e.__class__.__name__, str(e)))
debug_print(
"Error in %s hook '%s': %s:\n%s"
% (hook_event.label, hook.name(), e.__class__.__name__, str(e))
)

def get_previous_release(self):
release_path = self.package.config.release_packages_path
Expand All @@ -382,8 +426,8 @@ def get_changelog(self):
changelog = None
with self.repo_operation():
changelog = self.vcs.get_changelog(
previous_revision,
max_revisions=config.max_package_changelog_revisions)
previous_revision, max_revisions=config.max_package_changelog_revisions
)

return changelog

Expand All @@ -402,8 +446,7 @@ def get_release_data(self):
previous_revision = None

if self.vcs is None:
return dict(vcs="None",
previous_version=previous_version)
return dict(vcs="None", previous_version=previous_version)

revision = None
with self.repo_operation():
Expand All @@ -417,11 +460,13 @@ def get_release_data(self):
if maxlen and changelog and len(changelog) > maxlen + 3:
changelog = changelog[:maxlen] + "..."

return dict(vcs=self.vcs.name(),
revision=revision,
changelog=changelog,
previous_version=previous_version,
previous_revision=previous_revision)
return dict(
vcs=self.vcs.name(),
revision=revision,
changelog=changelog,
previous_version=previous_version,
previous_revision=previous_revision,
)

def _print(self, txt, *nargs):
if self.verbose:
Expand All @@ -433,12 +478,12 @@ def _print_header(self, txt, n=1):
if self.quiet:
return

self._print('')
self._print("")
if n <= 1:
br = '=' * 80
br = "=" * 80
title = "%s\n%s\n%s" % (br, txt, br)
else:
title = "%s\n%s" % (txt, '-' * len(txt))
title = "%s\n%s" % (txt, "-" * len(txt))

pr = Printer(sys.stdout)
pr(title, heading)
Expand Down
2 changes: 1 addition & 1 deletion src/rez/developer_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from rez.utils.execution import add_sys_paths
from rez.utils.sourcecode import SourceCode
from rez.utils.logging_ import print_info, print_error
from rez.vendor.enum import Enum
from inspect import isfunction
from enum import Enum
import os.path
import stat

Expand Down
2 changes: 1 addition & 1 deletion src/rez/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from rez.packages import get_latest_package
from rez.version import Version
from rez.vendor.distlib.database import DistributionPath
from rez.vendor.enum.enum import Enum
from rez.vendor.packaging.version import Version as PackagingVersion
from rez.vendor.packaging.specifiers import Specifier
from rez.resolved_context import ResolvedContext
Expand All @@ -29,6 +28,7 @@
from tempfile import mkdtemp
from textwrap import dedent
from io import StringIO
from enum import Enum


PIP_SPECIFIER = Specifier(">=19") # rez pip only compatible with pip>=19
Expand Down
2 changes: 1 addition & 1 deletion src/rez/release_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from rez.utils.logging_ import print_warning, print_debug
from rez.packages import get_developer_package
from rez.vendor.enum import Enum
from enum import Enum


def get_release_hook_types():
Expand Down
2 changes: 1 addition & 1 deletion src/rez/resolved_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
from rez.utils.resolve_graph import failure_detail_from_graph
from rez.version import VersionRange
from rez.version import Requirement
from rez.vendor.enum import Enum
from rez.vendor import yaml
from rez.utils import json
from rez.utils.yaml import dump_yaml
from rez.utils.platform_ import platform_

from contextlib import contextmanager
from enum import Enum
from functools import wraps
import getpass
import socket
Expand Down
2 changes: 1 addition & 1 deletion src/rez/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from rez.utils.memcached import memcached_client, pool_memcached_connections
from rez.utils.logging_ import log_duration
from rez.config import config
from rez.vendor.enum import Enum
from rez.version import Requirement
from contextlib import contextmanager
from enum import Enum
from hashlib import sha1


Expand Down
Loading