def _create_command(self): entrypoint_type = _entry_point_type.get(environment.code_dir, self._user_entry_point) if entrypoint_type is _entry_point_type.PYTHON_PACKAGE: entry_module = self._user_entry_point.replace(".py", "") return self._python_command() + ["-m", entry_module] + self._args elif entrypoint_type is _entry_point_type.PYTHON_PROGRAM: return self._python_command() + [self._user_entry_point ] + self._args else: args = [ six.moves.shlex_quote(arg) # pylint: disable=too-many-function-args for arg in self._args ] return [ "/bin/sh", "-c", "./%s %s" % (self._user_entry_point, " ".join(args)) ]
def install(name, path=environment.code_dir, capture_error=False): """Install the user provided entry point to be executed as follows: - add the path to sys path - if the user entry point is a command, gives exec permissions to the script Args: name (str): Name of the script or module. path (str): Path to directory where the entry point will be installed. capture_error (bool): Default false. If True, the running process captures the stderr, and appends it to the returned Exception message in case of errors. """ if path not in sys.path: sys.path.insert(0, path) entry_point_type = _entry_point_type.get(path, name) if entry_point_type is _entry_point_type.PYTHON_PACKAGE: modules.install(path, capture_error) elif entry_point_type is _entry_point_type.PYTHON_PROGRAM and modules.has_requirements( path): modules.install_requirements(path, capture_error) if entry_point_type is _entry_point_type.COMMAND: os.chmod(os.path.join(path, name), 511)
def test_get_command(entry_point_type_script): assert _entry_point_type.get("bla", "program.sh") == _entry_point_type.COMMAND
def test_get_program(): assert _entry_point_type.get("bla", "program.py") == _entry_point_type.PYTHON_PROGRAM
def test_get_package(entry_point_type_module): assert _entry_point_type.get("bla", "program.py") == _entry_point_type.PYTHON_PACKAGE