Exemplo n.º 1
0
def check_for_backend_python_library_inconsistencies():
    """Checks the state of the 'third_party/python_libs' folder and compares it
    to the required libraries specified in 'requirements.txt'.
    If any inconsistencies are found, the script displays the inconsistencies
    and exits.
    """
    mismatches = install_backend_python_libs.get_mismatches()

    if mismatches:
        python_utils.PRINT(
            'Your currently installed python libraries do not match the\n'
            'libraries listed in your "requirements.txt" file. Here is a\n'
            'full list of library/version discrepancies:\n')

        python_utils.PRINT(
            '{:<35} |{:<25}|{:<25}'.format(
                'Library', 'Requirements Version',
                'Currently Installed Version'))
        for library_name, version_strings in mismatches.items():
            python_utils.PRINT('{!s:<35} |{!s:<25}|{!s:<25}'.format(
                library_name, version_strings[0], version_strings[1]))
        python_utils.PRINT('\n')
        common.print_each_string_after_two_new_lines([
            'Please fix these discrepancies by editing the `requirements.in`\n'
            'file or running `scripts.install_third_party` to regenerate\n'
            'the `third_party/python_libs` directory.\n'])
        sys.exit(1)
    else:
        python_utils.PRINT(
            'Python dependencies consistency check succeeded.')
Exemplo n.º 2
0
def _verify_pip_is_installed():
    """Verify that pip is installed.

    Raises:
        ImportError. Error importing pip.
    """
    try:
        python_utils.PRINT('Checking if pip is installed on the local machine')
        # Importing pip just to check if its installed.
        import pip  #pylint: disable=unused-variable
    except ImportError as e:
        common.print_each_string_after_two_new_lines([
            'Pip is required to install Oppia dependencies, but pip wasn\'t '
            'found on your local machine.',
            'Please see \'Installing Oppia\' on the Oppia developers\' wiki '
            'page:'])

        if common.is_mac_os():
            python_utils.PRINT(
                'https://github.com/oppia/oppia/wiki/Installing-Oppia-%28Mac-'
                'OS%29')
        elif common.is_linux_os():
            python_utils.PRINT(
                'https://github.com/oppia/oppia/wiki/Installing-Oppia-%28Linux'
                '%29')
        else:
            python_utils.PRINT(
                'https://github.com/oppia/oppia/wiki/Installing-Oppia-%28'
                'Windows%29')
        raise ImportError('Error importing pip: %s' % e)
Exemplo n.º 3
0
def verify_pip_is_installed():
    """Verify that pip is installed.

    Raises:
        ImportError. Error importing pip.
    """
    python_utils.PRINT('Checking if pip is installed on the local machine')
    try:
        import pip
    except ImportError as e:
        common.print_each_string_after_two_new_lines([
            'Pip is required to install Oppia dependencies, but pip wasn\'t '
            'found on your local machine.',
            'Please see \'Installing Oppia\' on the Oppia developers\' wiki '
            'page:'
        ])

        if common.is_mac_os():
            python_utils.PRINT(
                'https://github.com/oppia/oppia/wiki/Installing-Oppia-%28Mac-'
                'OS%29')
        elif common.is_linux_os():
            python_utils.PRINT(
                'https://github.com/oppia/oppia/wiki/Installing-Oppia-%28Linux'
                '%29')
        else:
            python_utils.PRINT(
                'https://github.com/oppia/oppia/wiki/Installing-Oppia-%28'
                'Windows%29')
        raise ImportError('Error importing pip: %s' % e)
    else:
        if pip.__version__ != OPPIA_REQUIRED_PIP_VERSION:
            common.print_each_string_after_two_new_lines([
                'Oppia requires pip==%s, but you have pip==%s installed.' %
                (OPPIA_REQUIRED_PIP_VERSION, pip.__version__),
                'Upgrading pip on your behalf...',
            ])
            _run_pip_command(
                ['install', 'pip==%s' % OPPIA_REQUIRED_PIP_VERSION])
Exemplo n.º 4
0
def main(args: Optional[Sequence[str]] = None) -> None:
    """Runs the frontend tests."""
    parsed_args = _PARSER.parse_args(args=args)

    run_dtslint_type_tests()
    if parsed_args.dtslint_only:
        return

    if not parsed_args.skip_install:
        install_third_party_libs.main()

    common.print_each_string_after_two_new_lines([
        'View interactive frontend test coverage reports by navigating to',
        '../karma_coverage_reports', 'on your filesystem.',
        'Running test in development environment'
    ])

    cmd = [
        common.NODE_BIN_PATH, '--max-old-space-size=4096',
        os.path.join(common.NODE_MODULES_PATH, 'karma', 'bin', 'karma'),
        'start',
        os.path.join('core', 'tests', 'karma.conf.ts')
    ]
    if parsed_args.run_minified_tests:
        print('Running test in production environment')

        build.main(args=['--prod_env', '--minify_third_party_libs_only'])

        cmd.append('--prodEnv')
    else:
        build.main(args=[])

    if parsed_args.verbose:
        cmd.append('--terminalEnabled')

    task = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    output_lines = []
    # The value of `process.stdout` should not be None since we passed
    # the `stdout=subprocess.PIPE` argument to `Popen`.
    assert task.stdout is not None
    # Prevents the wget command from running multiple times.
    combined_spec_file_started_downloading = False
    # This variable will be used to define the wget command to download
    # the combined-test.spec.js file.
    download_task = None
    # Reads and prints realtime output from the subprocess until it terminates.
    while True:
        line = task.stdout.readline()
        # No more output from the subprocess, and the subprocess has ended.
        if len(line) == 0 and task.poll() is not None:
            break
        # Suppressing the karma web-server logs.
        if line and not '[web-server]:' in line.decode('utf-8'):
            # Standard output is in bytes, we need to decode
            # the line to print it.
            print(line.decode('utf-8'), end='')
            output_lines.append(line)
        # Download the combined-tests.js file from the web-server.
        if ('Executed' in line.decode('utf-8')
                and not combined_spec_file_started_downloading
                and parsed_args.download_combined_frontend_spec_file):
            download_task = subprocess.Popen([
                'wget', 'http://localhost:9876/base/core/templates/' +
                'combined-tests.spec.js', '-P',
                os.path.join('../karma_coverage_reports')
            ])
            # Wait for the wget command to download the combined-tests.spec.js
            # file to complete.
            download_task.wait()
            combined_spec_file_started_downloading = True
    # Standard output is in bytes, we need to decode the line to print it.
    concatenated_output = ''.join(
        line.decode('utf-8') for line in output_lines)
    if download_task:
        # The result of the download is printed at the end for
        # easy access to it.
        if download_task.returncode:
            print('Failed to download the combined-tests.spec.js file.')
        else:
            print('Downloaded the combined-tests.spec.js file and stored'
                  'in ../karma_coverage_reports')
    print('Done!')

    if 'Trying to get the Angular injector' in concatenated_output:
        print('If you run into the error "Trying to get the Angular injector",'
              ' please see https://github.com/oppia/oppia/wiki/'
              'Frontend-unit-tests-guide#how-to-handle-common-errors'
              ' for details on how to fix it.')

    if parsed_args.check_coverage:
        if task.returncode:
            sys.exit(
                'The frontend tests failed. Please fix it before running the'
                ' test coverage check.')
        else:
            check_frontend_test_coverage.main()
    elif task.returncode:
        sys.exit(task.returncode)