Exemplo n.º 1
0
    def run_go(self):
        with dir_changer(self.dirname, delete_dir=False):
            script_filename = f'{self.__class__.__name__.lower()}.go'
            with open(script_filename, 'w', encoding='utf-8') as fout:
                fout.write(self.go_code())

            if self.leaves_path:
                with open('go.mod', 'w', encoding='utf-8') as fout:
                    fout.write(f"""
module main

require "github.com/ucfunnel/leaves" v0.0.0
replace "github.com/ucfunnel/leaves" v0.0.0 => "{self.leaves_path}"
""")

            self.logger.info(f'Build {script_filename}')
            execute_wrapper(['go', 'build', script_filename])

            executable_filename = script_filename[:-3]
            if not os.path.isfile(executable_filename):
                raise RuntimeError(
                    f'no executable found: {executable_filename}')

            self.logger.info(f'Run {executable_filename}')
            execute_wrapper([f'./{executable_filename}'])
Exemplo n.º 2
0
    def run_python(self):
        with dir_changer(self.dirname, delete_dir=False):
            script_filename = f'{self.__class__.__name__.lower()}.py'
            with open(script_filename, 'w', encoding='utf-8') as fout:
                fout.write(self.python_code())

            execute_wrapper([self.venv.python_path, script_filename])
Exemplo n.º 3
0
def execute_go(program):
    with open(program.filename, 'w', encoding='utf-8') as fout:
        fout.write(program.code)

    logger.info(f'Build {program.filename}')
    execute_wrapper(['go', 'build', program.filename])

    executable_filename = program.filename[:-3]
    if not os.path.isfile(executable_filename):
        raise RuntimeError(f'no executable found: {executable_filename}')

    logger.info(f'Run {executable_filename}')
    execute_check_output([f'./{executable_filename}'], program.output)
Exemplo n.º 4
0
def execute_check_output(args, expected_output=None):
    """Execute external program and compare output with `expected_output`"""
    output = execute_wrapper(args)
    if expected_output is not None and output.strip() != expected_output.strip(
    ):
        raise RuntimeError(
            f'unexpected output\nExpect:\n{expected_output}\n\nGot:\n{output}')
Exemplo n.º 5
0
    def activate(self, library_type: LibraryType, version: str):
        self.logger.info(
            f'Activating environment: {library_type.name} {version}')
        env_full_path = self._env_full_path(library_type, version)
        env = VEnv(
            env_dir=env_full_path,
            python_path=os.path.join(env_full_path, 'bin', 'python'),
            pip_path=os.path.join(env_full_path, 'bin', 'pip'),
            env_name=self._env_name(library_type, version),
            library=library_type,
            version=version,
        )
        if self._if_exist(library_type, version) and self.reuse_envs:
            self.logger.info('Use already existed environment')
            return env

        self.logger.info('Create new environment..')
        venv.create(
            env_dir=env_full_path,
            clear=True,
            symlinks=True,
            with_pip=True,
        )

        if library_type == LibraryType.LIGHTGBM:
            self.logger.info(f'Installing sklearn..')
            execute_wrapper([env.pip_path, 'install', 'sklearn'])
            lightgbm_package = f'lightgbm=={version}'
            self.logger.info(f'Installing {lightgbm_package}..')
            execute_wrapper([env.pip_path, 'install', lightgbm_package])
        else:
            self.logger.info(f'Installing sklearn..')
            execute_wrapper([env.pip_path, 'install', 'sklearn'])
            xgboost_package = f'xgboost=={version}'
            self.logger.info(f'Installing {xgboost_package}..')
            execute_wrapper([env.pip_path, 'install', xgboost_package])

        return env
Exemplo n.º 6
0
def gopath():
    return execute_wrapper('go env GOPATH'.split()).strip()