from CommonEnvironmentEx.Package import InitRelativeImports # ---------------------------------------------------------------------- _script_fullpath = CommonEnvironment.ThisFullpath() _script_dir, _script_name = os.path.split(_script_fullpath) # ---------------------------------------------------------------------- with InitRelativeImports(): from .Schema.Parse import ParseFiles # ---------------------------------------------------------------------- PLUGINS = GeneratorFactory.CreatePluginMap( "DEVELOPMENT_ENVIRONMENT_SIMPLE_SCHEMA_PLUGINS", os.path.join(_script_dir, "Plugins"), sys.stdout) _PluginTypeInfo = CommandLine.EnumTypeInfo(list(six.iterkeys(PLUGINS))) # ---------------------------------------------------------------------- def _GetOptionalMetadata(*args, **kwargs): return __GetOptionalMetadata(*args, **kwargs) def _CreateContext(*args, **kwargs): return __CreateContext(*args, **kwargs) def _Invoke(*args, **kwargs): return __Invoke(*args, **kwargs)
from CommonEnvironment import Process from CommonEnvironment.Shell.All import CurrentShell from CommonEnvironment.StreamDecorator import StreamDecorator # ---------------------------------------------------------------------- _script_fullpath = CommonEnvironment.ThisFullpath() _script_dir, _script_name = os.path.split(_script_fullpath) # ---------------------------------------------------------------------- CONFIGURATIONS = ["Debug", "Release"] JSON_FILENAME = "Microsoft MLFeaturizers.FileAttributes.json" # ---------------------------------------------------------------------- @CommandLine.EntryPoint @CommandLine.Constraints( configuration=CommandLine.EnumTypeInfo(CONFIGURATIONS), output_dir=CommandLine.DirectoryTypeInfo( ensure_exists=False, ), prerelease_build_name=CommandLine.StringTypeInfo( arity="?", ), cmake_generator=CommandLine.StringTypeInfo( arity="?", ), output_stream=None, ) def Build( configuration, output_dir, release_build=False,
def CreateCompileMethod(compiler_type): # ---------------------------------------------------------------------- @CommandLine.EntryPoint @CommandLine.Constraints( input=CommandLine.FilenameTypeInfo(arity='+'), output_dir=CommandLine.DirectoryTypeInfo(ensure_exists=False), output_name=CommandLine.StringTypeInfo(arity='?'), build_type=CommandLine.EnumTypeInfo([ "console", "windows", ], arity='?'), manifest_filename=CommandLine.FilenameTypeInfo(arity='?'), icon_filename=CommandLine.FilenameTypeInfo(arity='?'), path=CommandLine.DirectoryTypeInfo(arity='*'), include_module=CommandLine.StringTypeInfo(arity='*'), exclude_module=CommandLine.StringTypeInfo(arity='*'), package=CommandLine.StringTypeInfo(arity='*'), distutil_arg=CommandLine.StringTypeInfo(arity='*'), comments=CommandLine.StringTypeInfo(arity='?'), company_name=CommandLine.StringTypeInfo(arity='?'), file_description=CommandLine.StringTypeInfo(arity='?'), internal_name=CommandLine.StringTypeInfo(arity='?'), copyright=CommandLine.StringTypeInfo(arity='?'), trademark=CommandLine.StringTypeInfo(arity='?'), name=CommandLine.StringTypeInfo(arity='?'), version=CommandLine.StringTypeInfo(arity='?'), output_stream=None, ) def Compile( input, output_dir, output_name=None, build_type="console", include_tcl=False, no_optimize=False, no_bundle=False, manifest_filename=None, icon_filename=None, path=None, include_module=None, exclude_module=None, package=None, distutil_arg=None, comments=None, company_name=None, file_description=None, internal_name=None, trademark=None, copyright=None, name=None, version=None, preserve_temp_dir=False, output_stream=sys.stdout, no_verbose=False, ): """Creates an executable from one or more python files.""" if build_type == "console": build_type = DistutilsCompilerImpl.BuildType_Console elif build_type == "windows": build_type = DistutilsCompilerImpl.BuildType_Windows else: assert False, build_type return CommandLineCompile( compiler_type, input, output_stream, verbose=not no_verbose, # Generate compiler options output_dir=output_dir, # This compiler options preserve_temp_dir=preserve_temp_dir, build_type=build_type, include_tcl=include_tcl, no_optimize=no_optimize, no_bundle=no_bundle, manifest_filename=manifest_filename, icon_filename=icon_filename, paths=path, includes=include_module, excludes=exclude_module, packages=package, distutil_args=distutil_arg, output_name=output_name, comments=comments, company_name=company_name, file_description=file_description, internal_name=internal_name, copyright=copyright, trademark=trademark, name=name, version=version, ) # ---------------------------------------------------------------------- return Compile
def _GenerateRebuild(build_func, clean_func, config): assert build_func assert clean_func assert config # ---------------------------------------------------------------------- def Impl(configuration, output_dir, build_func, clean_func): result = clean_func(configuration, output_dir) if result is not None and result != 0: return result if config.RequiresOutputDir and not os.path.isdir(output_dir): os.makedirs(output_dir) result = build_func(configuration, output_dir) if result is not None and result != 0: return result return 0 # ---------------------------------------------------------------------- if config.Configurations: if config.RequiresOutputDir: # ---------------------------------------------------------------------- @CommandLine.EntryPoint @CommandLine.Constraints( configuration=CommandLine.EnumTypeInfo(config.Configurations), output_dir=CommandLine.DirectoryTypeInfo(ensure_exists=False), ) def Rebuild(configuration, output_dir): return Impl(configuration, output_dir, build_func, clean_func) # ---------------------------------------------------------------------- else: # ---------------------------------------------------------------------- @CommandLine.EntryPoint @CommandLine.Constraints( configuration=CommandLine.EnumTypeInfo(config.Configurations), ) def Rebuild(configuration): return Impl( configuration, None, lambda cfg, output_dir: build_func(cfg), lambda cfg, output_dir: clean_func(cfg), ) # ---------------------------------------------------------------------- else: if config.RequiresOutputDir: # ---------------------------------------------------------------------- @CommandLine.EntryPoint @CommandLine.Constraints( output_dir=CommandLine.DirectoryTypeInfo(ensure_exists=False), ) def Rebuild(output_dir): return Impl( None, output_dir, lambda cfg, output_dir: build_func(output_dir), lambda cfg, output_dir: clean_func(output_dir), ) # ---------------------------------------------------------------------- else: # ---------------------------------------------------------------------- @CommandLine.EntryPoint def Rebuild(): return Impl( None, None, lambda cfg, output_dir: build_func(), lambda cfg, output_dir: clean_func(), ) # ---------------------------------------------------------------------- return Rebuild
def _RedirectEntryPoint(function_name, entry_point, config): assert function_name assert entry_point assert config # <Use of exec> pylint: disable = W0122 # <Use of eval> pylint: disable = W0123 required_arguments = [] if config.Configurations: if function_name != "Clean" or config.ConfigurationRequiredOnClean: assert "configuration" in entry_point.ConstraintsDecorator.Preconditions, function_name entry_point.ConstraintsDecorator.Preconditions["configuration"] = CommandLine.EnumTypeInfo(config.Configurations) required_arguments.append("configuration") if config.RequiresOutputDir: required_arguments.append("output_dir") num_required_args = six.get_function_code(entry_point.Function).co_argcount - len(list(six.get_function_defaults(entry_point.Function) or [])) arguments = six.get_function_code(entry_point.Function).co_varnames[:num_required_args] if required_arguments and list(arguments[:len(required_arguments) + 1]) != required_arguments: raise Exception("The entry point '{}' should begin with the arguments '{}' ('{}' were found)".format( function_name, ', '.join(required_arguments), ', '.join(arguments), )) # Dynamically redefine the function so that it prints information that lets the user know the the # functionality can't be executed on the current platform/configuration/environment. if config.RequiredDevelopmentEnvironment and config.RequiredDevelopmentEnvironment.lower() not in [ CurrentShell.Name.lower(), CurrentShell.CategoryName.lower(), ]: exec(textwrap.dedent( """\ def {name}({args}): sys.stdout.write("\\nINFO: This can only be run on '{env}'.\\n") return 0 """).format( name=function_name, args=', '.join(arguments), env=config.RequiredDevelopmentEnvironment, )) entry_point.Function = eval(function_name) elif config.RequiredDevelopmentConfigurations and not _RedirectEntryPoint_IsSupportedDevelopmentConfiguration(config.RequiredDevelopmentConfigurations): exec(textwrap.dedent( """\ def {name}({args}): sys.stdout.write("\\nINFO: This can only be run in development environments activated with the configurations {configs}.\\n") return 0 """).format( name=function_name, args=', '.join(arguments), configs=', '.join([ "'{}'".format(configuration) for configuration in config.RequiredDevelopmentConfigurations ]), )) entry_point.Function = eval(function_name) elif config.DisableIfDependencyEnvironment: repo_path = os.getenv(RepositoryBootstrapConstants.DE_REPO_ROOT_NAME) if FileSystem.GetCommonPath(repo_path, inspect.getfile(entry_point.Function)).rstrip(os.path.sep) != repo_path: exec(textwrap.dedent( """\ def {name}({args}): sys.stdout.write("\\nINFO: This module is not build when invoked as a dependency.\\n") return 0 """).format( name=function_name, args=', '.join(arguments), )) entry_point.Function = eval(function_name)
_script_dir, _script_name = os.path.split(_script_fullpath) # ---------------------------------------------------------------------- DOCKER_USER_NAME = "featurizerslibrarybuild" IMAGES = [ os.path.basename(potential_dir) for potential_dir in [os.path.join(_script_dir, item) for item in os.listdir(_script_dir)] if os.path.isdir(potential_dir) ] # ---------------------------------------------------------------------- @CommandLine.EntryPoint @CommandLine.Constraints( image_name=CommandLine.EnumTypeInfo(IMAGES), tag=CommandLine.StringTypeInfo(arity="*", ), output_stream=None, ) def Build( image_name, tag=None, output_stream=sys.stdout, verbose=False, ): """Creates a docker image""" tags = tag del tag with StreamDecorator(output_stream).DoneManager(