class Platform(datatype(['normalized_os_name'])): class UnsupportedPlatformError(Exception): """Thrown if pants is running on an unrecognized platform.""" @classmethod def create(cls): return Platform(get_normalized_os_name()) _NORMALIZED_OS_NAMES = frozenset(all_normalized_os_names()) def resolve_platform_specific(self, platform_specific_funs): arg_keys = frozenset(platform_specific_funs.keys()) unknown_plats = self._NORMALIZED_OS_NAMES - arg_keys if unknown_plats: raise self.UnsupportedPlatformError( "platform_specific_funs {} must support platforms {}" .format(platform_specific_funs, list(unknown_plats))) extra_plats = arg_keys - self._NORMALIZED_OS_NAMES if extra_plats: raise self.UnsupportedPlatformError( "platform_specific_funs {} has unrecognized platforms {}" .format(platform_specific_funs, list(extra_plats))) fun_for_platform = platform_specific_funs[self.normalized_os_name] return fun_for_platform()
def platform_specific(normalized_os_name): if normalized_os_name not in all_normalized_os_names(): raise ValueError("unrecognized platform: {}".format(normalized_os_name)) def decorator(test_fn): def wrapper(self, *args, **kwargs): if Platform.current == Platform(normalized_os_name): test_fn(self, *args, **kwargs) return wrapper return decorator
class Platform(enum(all_normalized_os_names())): # TODO: try to turn all of these accesses into v2 dependency injections! @memoized_classproperty def current(cls): return cls(get_normalized_os_name()) @memoized_property def runtime_lib_path_env_var(self): return self.resolve_for_enum_variant({ 'darwin': 'DYLD_LIBRARY_PATH', 'linux': 'LD_LIBRARY_PATH', })
def platform_specific(normalized_os_name): if normalized_os_name not in all_normalized_os_names(): raise ValueError("unrecognized platform: {}".format(normalized_os_name)) def decorator(test_fn): def wrapper(self, *args, **kwargs): # FIXME: This should be drawn from the v2 engine somehow. platform = Platform.create() if platform.normalized_os_name == normalized_os_name: test_fn(self, *args, **kwargs) return wrapper return decorator
def platform_specific(normalized_os_name): if normalized_os_name not in all_normalized_os_names(): raise ValueError( "unrecognized platform: {}".format(normalized_os_name)) def decorator(test_fn): def wrapper(self, *args, **kwargs): # TODO: This should be drawn from the v2 engine somehow. platform = Platform.create() if platform.normalized_os_name == normalized_os_name: test_fn(self, *args, **kwargs) return wrapper return decorator
class Platform(enum(all_normalized_os_names())): # TODO: try to turn all of these accesses into v2 dependency injections! @memoized_classproperty def current(cls): return cls(get_normalized_os_name())
class PlatformConstraint(enum(list(all_normalized_os_names()) + ['none'])): @memoized_classproperty def local_platform(cls): return cls(Platform.current.value)