github.phpd.cn/thought-machine/please@v12.2.0+incompatible/build_defs/multiversion_wheel.build_defs (about)

     1  def python_multiversion_wheel(name, version, repos, hashes=None, package_name=None, outs=None,
     2                                subdir='.', licences=None, test_only=False,
     3                                visibility=None, deps=[]):
     4      """Downloads and combines multiple Python wheels.
     5  
     6      This is an extended version of python_wheel that allows fetching multiple wheels for
     7      different Python versions and combining them. For most packages this is unnecessary
     8      since they are pure Python, but for packages with binary components those objects are
     9      linked to one Python version each. By adding all the .so files for all versions we care
    10      about, we can support them all simultaneously.
    11  
    12      Note that python 2 does not support versioned object file names, so this can only work
    13      for one python 2 wheel at a time. For us that's not an issue since we only support 2.7
    14      (and these days that's nearly always what people are using, so often not a big deal).
    15  
    16      The wheels are downloaded one each from the given list of repo URLs, which work in the
    17      same way as python_wheel. Within those directories, the wheels are expected to follow a
    18      simple naming scheme which is essentially:
    19        <package_name>-<version>-<os>_<arch>.whl
    20      Note that non-arch-specific wheels aren't supported since you'd not then need multiple
    21      versions of them and python_wheel would suffice.
    22  
    23      Args:
    24        name (str): Name of the rule. Also doubles as the name of the package if package_name
    25              is not set.
    26        version (str): Version of the package to install.
    27        repos (list): List of repos to download wheels from.
    28        hashes (list): List of hashes to verify the package against.
    29        package_name (str): If given, overrides `name` for the name of the package to look for.
    30        outs (list): List of output files. Defaults to a directory named the same as `name`.
    31        subdir (str): Subdirectory to extract into. If not given, defaults to the current directory.
    32        licences (list): Licences that this rule is subject to.
    33        test_only (bool): If True, this library can only be used by tests.
    34        repo (str): Repository to download wheels from.
    35        visibility (list): Visibility declaration.
    36        deps (list): Dependencies of this rule.
    37      """
    38      package_name = package_name or name
    39  
    40      file_rules = [remote_file(
    41          name = '_%s#%d' % (name, i + 1),
    42          url = '%s/%s-%s-${OS}_${ARCH}.whl' % (repo, package_name, version),
    43          out = '%s-%s-%d.whl' % (package_name, version, i + 1),
    44      ) for i, repo in enumerate(repos)]
    45  
    46      return build_rule(
    47          name = name,
    48          srcs = file_rules,
    49          outs = outs or [package_name],
    50          cmd = 'mkdir -p %s && for SRC in $SRCS; do unzip -o -qq -d %s $SRC; done && rm -rf %s/*.egg-info %s/*.dist-info' %
    51              (subdir, subdir, subdir, subdir),
    52          hashes = hashes,
    53          building_description = 'Extracting...',
    54          requires = ['py'],
    55          test_only = test_only,
    56          visibility = visibility,
    57          labels = ['whl:%s==%s' % (package_name, version)],
    58      )