コード例 #1
0
def find_version_in_range(versions, semver_range):
    '''versions is an array of semver versions and semver_range is a semver range expression.

    Assumes the environment has `node` on the $PATH.
    '''
    logging.debug('Trying to match %s against %s.', semver_range, versions)
    if platform_checker.is_windows():
        shell = True
        # Because we have to use `shell=True` on Windows due to https://bugs.python.org/issue17023,
        # we have to do our own escaping. In particular, if semver_range is '>=0.12.0' and is not
        # escaped correctly, then Windows will try to write to a file with that name. The built-in
        # escaping done by subprocess.Popen() does not appear to do the right thing here (it uses
        # single quotes instead of double quotes, which is not sufficient), so we must do the
        # escaping ourselves and convert the args into a string to override the default escaping.
        semver_range = '"%s"' % semver_range
    else:
        shell = False

    args = [
        platform_checker.get_node_executable(), semver, '--range', semver_range
    ] + versions

    if platform_checker.is_windows():
        args = ' '.join(args)

    proc = subprocess.Popen(args, stdout=subprocess.PIPE, shell=shell)
    matching_versions = []
    for line in proc.stdout:
        matching_versions.append(line.rstrip())
    proc.wait()
    if proc.returncode:
        return None
    else:
        return matching_versions
コード例 #2
0
ファイル: semver.py プロジェクト: Staberinde/nuclide
def find_version_in_range(versions, semver_range):
    '''versions is an array of semver versions and semver_range is a semver range expression.

    Assumes the environment has `node` on the $PATH.
    '''
    logging.debug('Trying to match %s against %s.', semver_range, versions)
    if platform_checker.is_windows():
        shell = True
        # Because we have to use `shell=True` on Windows due to https://bugs.python.org/issue17023,
        # we have to do our own escaping. In particular, if semver_range is '>=0.12.0' and is not
        # escaped correctly, then Windows will try to write to a file with that name. The built-in
        # escaping done by subprocess.Popen() does not appear to do the right thing here (it uses
        # single quotes instead of double quotes, which is not sufficient), so we must do the
        # escaping ourselves and convert the args into a string to override the default escaping.
        semver_range = '"%s"' % semver_range
    else:
        shell = False

    args = [platform_checker.get_node_executable(), semver, '--range', semver_range] + versions

    if platform_checker.is_windows():
        args = ' '.join(args)

    proc = subprocess.Popen(args, stdout=subprocess.PIPE, shell=shell)
    matching_versions = []
    for line in proc.stdout:
        matching_versions.append(line.rstrip())
    proc.wait()
    if proc.returncode:
        return None
    else:
        return matching_versions
コード例 #3
0
ファイル: atom.py プロジェクト: jordwalke/nuclide
def _is_path_env_variable_set_appropriately(include_apm):
    executables = [platform_checker.get_node_executable(), 'npm']
    if include_apm:
        executables += ['apm']
    for executable in executables:
        if not _is_executable_on_path(executable):
            return False
    return True
コード例 #4
0
ファイル: atom.py プロジェクト: vinayathimmappa/nuclide
def _is_path_env_variable_set_appropriately(include_apm):
    executables = [platform_checker.get_node_executable(), 'npm']
    if include_apm:
        executables += ['apm']
    for executable in executables:
        if not _is_executable_on_path(executable):
            return False
    return True
コード例 #5
0
ファイル: atom.py プロジェクト: Staberinde/nuclide
def _verify_node():
    '''Ensures that Node v0.12.0 or later is on the user's $PATH.'''
    # As noted in _install_apm_and_npm_os_x(), ultimately that function should be responsible for
    # doing this work.

    # First, check for the presence of node. Make sure it is at least v0.12.0.
    node_executable = platform_checker.get_node_executable()
    if _is_executable_on_path(node_executable):
        node_version = fs.cross_platform_check_output([node_executable, '--version']).rstrip()
        if semver.find_version_in_range([node_version], '>=0.12.0'):
            return

    raise Exception('Must install Node v0.12.0 or later. Not found in %s' % os.environ['PATH'])
コード例 #6
0
ファイル: atom.py プロジェクト: jordwalke/nuclide
def _verify_node():
    '''Ensures that Node v4.1.1 or later is on the user's $PATH.'''
    # As noted in _install_apm_and_npm_os_x(), ultimately that function should be responsible for
    # doing this work.

    # First, check for the presence of node. Make sure it is at least v4.1.1.
    node_executable = platform_checker.get_node_executable()
    if _is_executable_on_path(node_executable):
        node_version = fs.cross_platform_check_output([node_executable, '--version']).rstrip()
        major, minor, patch = re.match(r'^v(\d+)\.(\d+)\.(\d+)$', node_version).group(1, 2, 3)
        if (int(major), int(minor), int(patch)) >= (4, 1, 1):
            return

    raise Exception('Must install Node v4.1.1 or later. Not found in %s' % os.environ['PATH'])
コード例 #7
0
ファイル: atom.py プロジェクト: vinayathimmappa/nuclide
def _verify_node():
    '''Ensures that Node v0.12.0 or later is on the user's $PATH.'''
    # As noted in _install_apm_and_npm_os_x(), ultimately that function should be responsible for
    # doing this work.

    # First, check for the presence of node. Make sure it is at least v0.12.0.
    node_executable = platform_checker.get_node_executable()
    if _is_executable_on_path(node_executable):
        node_version = fs.cross_platform_check_output([node_executable, '--version']).rstrip()
        major, minor = re.match(r'^v(\d+)\.(\d+)\.(\d+)$', node_version).group(1, 2)
        if int(major) > 0 or int(minor) >= 12:
            return

    raise Exception('Must install Node v0.12.0 or later. Not found in %s' % os.environ['PATH'])
コード例 #8
0
ファイル: atom.py プロジェクト: valgaze/nuclide
def _verify_node():
    '''Ensures that Node v0.12.0 or later is on the user's $PATH.'''
    # As noted in _install_apm_and_npm_os_x(), ultimately that function should be responsible for
    # doing this work.

    # First, check for the presence of node. Make sure it is at least v0.12.0.
    node_executable = platform_checker.get_node_executable()
    if _is_executable_on_path(node_executable):
        node_version = fs.cross_platform_check_output(
            [node_executable, '--version']).rstrip()
        if semver.find_version_in_range([node_version], '>=0.12.0'):
            return

    raise Exception('Must install Node v0.12.0 or later. Not found in %s' %
                    os.environ['PATH'])
コード例 #9
0
ファイル: semver.py プロジェクト: dalinaum/nuclide
def find_version_in_range(versions, semver_range):
    '''versions is an array of semver versions and semver_range is a semver range expression.

    Assumes the environment has `node` on the $PATH.
    '''
    logging.debug('Trying to match %s against %s.', semver_range, versions)
    args = [platform_checker.get_node_executable(), semver] + versions + ['-r', semver_range]
    shell = True if platform_checker.is_windows() else False
    proc = subprocess.Popen(args, stdout=subprocess.PIPE, shell=shell)
    matching_versions = []
    for line in proc.stdout:
        matching_versions.append(line.rstrip())
    proc.wait()
    if proc.returncode:
        return None
    else:
        return matching_versions
コード例 #10
0
ファイル: transpiler.py プロジェクト: zgao/as-nuclide
    def _do_transpile(self, babel_file):
        # Store output in memory and then use it to overwrite the original file.
        transpiled_js = fs.cross_platform_check_output([
            platform_checker.get_node_executable(),
            self._transpile_script,
            babel_file,
        ])

        # Note that the generated file will often still start with 'use babel', in which case we
        # want to strip that line to ensure that Atom does not try to transpile the file again.
        # Note that this is not always the case. The transpiled file might start with:
        #
        #     Object.defineProperty(exports, '__esModule', {
        #
        # in which case stripping the first line would leave the file in an unparseable state.
        end_of_first_line = transpiled_js.index('\n')
        first_line = transpiled_js[:end_of_first_line]
        if has_babel_pragma(first_line):
            transpiled_js = transpiled_js[end_of_first_line + 1:]

        with open(babel_file, 'w') as f:
            f.write(transpiled_js)
コード例 #11
0
ファイル: transpiler.py プロジェクト: simendancer/nuclide
    def _do_transpile(self, babel_file):
        # Store output in memory and then use it to overwrite the original file.
        transpiled_js = fs.cross_platform_check_output([
            platform_checker.get_node_executable(),
            self._transpile_script,
            babel_file,
        ])

        # Note that the generated file will often still start with 'use babel', in which case we
        # want to strip that line to ensure that Atom does not try to transpile the file again.
        # Note that this is not always the case. The transpiled file might start with:
        #
        #     Object.defineProperty(exports, '__esModule', {
        #
        # in which case stripping the first line would leave the file in an unparseable state.
        end_of_first_line = transpiled_js.index('\n')
        first_line = transpiled_js[:end_of_first_line]
        if has_babel_pragma(first_line):
            transpiled_js = transpiled_js[end_of_first_line + 1:]

        with open(babel_file, 'w') as f:
            f.write(transpiled_js)