コード例 #1
0
    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))
            ]
コード例 #2
0
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)
コード例 #3
0
def test_get_command(entry_point_type_script):
    assert _entry_point_type.get("bla", "program.sh") == _entry_point_type.COMMAND
コード例 #4
0
def test_get_program():
    assert _entry_point_type.get("bla", "program.py") == _entry_point_type.PYTHON_PROGRAM
コード例 #5
0
def test_get_package(entry_point_type_module):
    assert _entry_point_type.get("bla", "program.py") == _entry_point_type.PYTHON_PACKAGE