DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (6d9c5aadb636)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import os
import pathlib
import shutil
import subprocess
import sys
import tempfile
import zipfile


HERE = pathlib.Path(__file__).parent
PYTHON = HERE / 'python'
REQUIREMENTS_IN = PYTHON / 'requirements.in'
REQUIREMENTS_TXT = PYTHON / 'requirements.txt'

with tempfile.TemporaryDirectory() as tempd:
    subprocess.run([
        'pip',
        'download',
        '-r', '%s' % REQUIREMENTS_TXT,
        '--dest', '%s' % tempd,
        '--no-binary', ':all',
        '--disable-pip-version-check'])

    for entry in os.scandir(tempd):
        base, ext = os.path.splitext(entry.name)
        if ext == '.whl':
            # Wheels would extract into a directory with the name of the
            # package, but we want the platform signifiers, minus the version
            # number.
            # Wheel filenames look like:
            #
            # {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-
            # {platform tag}
            bits = base.split('-')

            if base.endswith('-py2.py3-none-any'):
                bits.pop()
                bits.pop()
                bits.pop()

            # Remove the version number.
            bits.pop(1)

            target = PYTHON / '-'.join(bits)

            if target.exists():
                shutil.rmtree(target)

            target.mkdir()

            with zipfile.ZipFile(entry.path, 'r') as zf:
                for name in zf.namelist():
                    p = pathlib.PurePosixPath(name)

                    if '.dist-info' in p.parts[0]:
                        if p.parts[1] != 'LICENSE.txt':
                            continue

                        dest = target / p.parts[1]
                        with dest.open('wb') as fh:
                            fh.write(zf.read(name))
                    else:
                        zf.extract(name, target)

        else:
            print('support for %s files not implemented' % ext)
            sys.exit(1)