コード例 #1
0
ファイル: python.py プロジェクト: akramhussein/pre-commit
def install_environment(
        repo_cmd_runner,
        version='default',
        additional_dependencies=None,
):
    assert repo_cmd_runner.exists('setup.py')
    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)

    # Install a virtualenv
    with clean_path_on_failure(repo_cmd_runner.path(directory)):
        venv_cmd = [
            sys.executable, '-m', 'virtualenv',
            '{{prefix}}{0}'.format(directory)
        ]
        if version != 'default':
            venv_cmd.extend(['-p', norm_version(version)])
        repo_cmd_runner.run(venv_cmd)
        with in_env(repo_cmd_runner, version) as env:
            env.run("cd '{prefix}' && pip install .")
            if additional_dependencies:
                env.run(
                    "cd '{prefix}' && pip install " +
                    ' '.join(
                        shell_escape(dep) for dep in additional_dependencies
                    )
                )
コード例 #2
0
ファイル: python.py プロジェクト: bchess/pre-commit
def install_environment(
        repo_cmd_runner,
        version='default',
        additional_dependencies=None,
):
    assert repo_cmd_runner.exists('setup.py')
    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)

    # Install a virtualenv
    with clean_path_on_failure(repo_cmd_runner.path(directory)):
        venv_cmd = [
            sys.executable, '-m', 'virtualenv',
            '{{prefix}}{0}'.format(directory)
        ]
        if version != 'default':
            venv_cmd.extend(['-p', norm_version(version)])
        repo_cmd_runner.run(venv_cmd)
        with in_env(repo_cmd_runner, version) as env:
            env.run("cd '{prefix}' && pip install .", encoding=None)
            if additional_dependencies:
                env.run(
                    "cd '{prefix}' && pip install " +
                    ' '.join(
                        shell_escape(dep) for dep in additional_dependencies
                    ),
                    encoding=None,
                )
コード例 #3
0
ファイル: node.py プロジェクト: akramhussein/pre-commit
def install_environment(
    repo_cmd_runner,
    version='default',
    additional_dependencies=None,
):
    assert repo_cmd_runner.exists('package.json')
    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)

    env_dir = repo_cmd_runner.path(directory)
    with clean_path_on_failure(env_dir):
        cmd = [
            sys.executable,
            '-m',
            'nodeenv',
            '--prebuilt',
            '{{prefix}}{0}'.format(directory),
        ]

        if version != 'default':
            cmd.extend(['-n', version])

        repo_cmd_runner.run(cmd)

        with in_env(repo_cmd_runner, version) as node_env:
            node_env.run("cd '{prefix}' && npm install -g")
            if additional_dependencies:
                node_env.run("cd '{prefix}' && npm install -g " + ' '.join(
                    shell_escape(dep) for dep in additional_dependencies))
コード例 #4
0
ファイル: node.py プロジェクト: imbstack/pre-commit
def install_environment(
        repo_cmd_runner,
        version='default',
        additional_dependencies=None,
):
    assert repo_cmd_runner.exists('package.json')
    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)

    env_dir = repo_cmd_runner.path(directory)
    with clean_path_on_failure(env_dir):
        cmd = [
            sys.executable, '-m', 'nodeenv', '--prebuilt',
            '{{prefix}}{0}'.format(directory),
        ]

        if version != 'default':
            cmd.extend(['-n', version])

        repo_cmd_runner.run(cmd)

        with in_env(repo_cmd_runner, version) as node_env:
            node_env.run("cd '{prefix}' && npm install -g")
            if additional_dependencies:
                node_env.run(
                    "cd '{prefix}' && npm install -g " +
                    ' '.join(
                        shell_escape(dep) for dep in additional_dependencies
                    )
                )
コード例 #5
0
ファイル: ruby.py プロジェクト: bchess/pre-commit
def install_environment(
        repo_cmd_runner,
        version='default',
        additional_dependencies=None,
):
    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
    with clean_path_on_failure(repo_cmd_runner.path(directory)):
        # TODO: this currently will fail if there's no version specified and
        # there's no system ruby installed.  Is this ok?
        _install_rbenv(repo_cmd_runner, version=version)
        with in_env(repo_cmd_runner, version) as ruby_env:
            if version != 'default':
                _install_ruby(ruby_env, version)
            ruby_env.run(
                'cd {prefix} && gem build *.gemspec && '
                'gem install --no-ri --no-rdoc *.gem',
                encoding=None,
            )
            if additional_dependencies:
                ruby_env.run(
                    'cd {prefix} && gem install --no-ri --no-rdoc ' +
                    ' '.join(
                        shell_escape(dep) for dep in additional_dependencies
                    ),
                    encoding=None,
                )
コード例 #6
0
ファイル: pcre.py プロジェクト: meunierd/pre-commit
def run_hook(repo_cmd_runner, hook, file_args):
    # For PCRE the entry is the regular expression to match
    return repo_cmd_runner.run(
        [
            'xargs', '-0', 'sh', '-c',
            # Grep usually returns 0 for matches, and nonzero for non-matches
            # so we flip it here.
            '! grep -H -n -P {0} $@'.format(shell_escape(hook['entry'])),
            '--',
        ],
        stdin=file_args_to_stdin(file_args),
        retcode=None,
        encoding=None,
    )
コード例 #7
0
ファイル: pcre.py プロジェクト: smgx360420/pre-commit
def run_hook(repo_cmd_runner, hook, file_args):
    # For PCRE the entry is the regular expression to match
    return repo_cmd_runner.run(
        [
            'xargs',
            '-0',
            'sh',
            '-c',
            # Grep usually returns 0 for matches, and nonzero for non-matches
            # so we flip it here.
            '! grep -H -n -P {0} $@'.format(shell_escape(hook['entry'])),
            '--',
        ],
        stdin=file_args_to_stdin(file_args),
        retcode=None,
    )
コード例 #8
0
ファイル: pcre.py プロジェクト: hermanocabral/pre-commit
def run_hook(repo_cmd_runner, hook, file_args):
    # For PCRE the entry is the regular expression to match
    return repo_cmd_runner.run(
        [
            "xargs",
            "-0",
            "sh",
            "-c",
            # Grep usually returns 0 for matches, and nonzero for non-matches
            # so we flip it here.
            "! grep -H -n -P {0} $@".format(shell_escape(hook["entry"])),
            "--",
        ],
        stdin=file_args_to_stdin(file_args),
        retcode=None,
    )
コード例 #9
0
ファイル: pcre.py プロジェクト: hitul007/pre-commit
def run_hook(repo_cmd_runner, hook, file_args):
    grep_command = 'grep -H -n -P'
    if platform == 'darwin':  # pragma: no cover (osx)
        grep_command = 'ggrep -H -n -P'

    # For PCRE the entry is the regular expression to match
    return repo_cmd_runner.run(
        [
            'xargs', '-0', 'sh', '-c',
            # Grep usually returns 0 for matches, and nonzero for non-matches
            # so we flip it here.
            '! {0} {1} $@'.format(grep_command, shell_escape(hook['entry'])),
            '--',
        ],
        stdin=file_args_to_stdin(file_args),
        retcode=None,
        encoding=None,
    )
コード例 #10
0
def install_environment(
    repo_cmd_runner,
    version='default',
    additional_dependencies=None,
):
    directory = helpers.environment_dir(ENVIRONMENT_DIR, version)
    with clean_path_on_failure(repo_cmd_runner.path(directory)):
        # TODO: this currently will fail if there's no version specified and
        # there's no system ruby installed.  Is this ok?
        _install_rbenv(repo_cmd_runner, version=version)
        with in_env(repo_cmd_runner, version) as ruby_env:
            if version != 'default':
                _install_ruby(ruby_env, version)
            ruby_env.run(
                'cd {prefix} && gem build *.gemspec && '
                'gem install --no-ri --no-rdoc *.gem', )
            if additional_dependencies:
                ruby_env.run('cd {prefix} && gem install --no-ri --no-rdoc ' +
                             ' '.join(
                                 shell_escape(dep)
                                 for dep in additional_dependencies))
コード例 #11
0
ファイル: pcre.py プロジェクト: imbstack/pre-commit
def run_hook(repo_cmd_runner, hook, file_args):
    grep_command = "grep -H -n -P"
    if platform == "darwin":  # pragma: no cover (osx)
        grep_command = "ggrep -H -n -P"

    # For PCRE the entry is the regular expression to match
    return repo_cmd_runner.run(
        [
            "xargs",
            "-0",
            "sh",
            "-c",
            # Grep usually returns 0 for matches, and nonzero for non-matches
            # so we flip it here.
            "! {0} {1} {2} $@".format(grep_command, " ".join(hook["args"]), shell_escape(hook["entry"])),
            "--",
        ],
        stdin=file_args_to_stdin(file_args),
        retcode=None,
        encoding=None,
    )
コード例 #12
0
def run_hook(repo_cmd_runner, hook, file_args):
    grep_command = 'grep -H -n -P'
    if platform == 'darwin':  # pragma: no cover (osx)
        grep_command = 'ggrep -H -n -P'

    # For PCRE the entry is the regular expression to match
    return repo_cmd_runner.run(
        [
            'xargs',
            '-0',
            'sh',
            '-c',
            # Grep usually returns 0 for matches, and nonzero for non-matches
            # so we flip it here.
            '! {0} {1} {2} $@'.format(grep_command, ' '.join(hook['args']),
                                      shell_escape(hook['entry'])),
            '--',
        ],
        stdin=file_args_to_stdin(file_args),
        retcode=None,
        encoding=None,
    )
コード例 #13
0
def test_shell_escape(input_str, expected):
    assert shell_escape(input_str) == expected
コード例 #14
0
ファイル: util_test.py プロジェクト: smgx360420/pre-commit
def test_shell_escape(input_str, expected):
    assert shell_escape(input_str) == expected