File: get_wheel_name.py

package info (click to toggle)
cmake-format 0.6.13-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,436 kB
  • sloc: python: 16,990; makefile: 14
file content (52 lines) | stat: -rw-r--r-- 1,316 bytes parent folder | download | duplicates (4)
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
"""
Get the wheel filename without building the wheel.
"""
from __future__ import print_function

import argparse
import io

from setuptools import Extension
from setuptools.dist import Distribution


def main():
  parser = argparse.ArgumentParser(description=__doc__)
  parser.add_argument("--name", required=True)
  parser.add_argument("--version-from", required=True)
  parser.add_argument("--has-extension-module", action="store_true")
  args = parser.parse_args()

  version = None
  with io.open(args.version_from, "r", encoding="utf-8") as infile:
    for line in infile:
      line = line.strip()
      if line.startswith("VERSION = "):
        version = line.split("=", 1)[1].strip().strip("'\"")

  if version is None:
    raise ValueError(
        "File {} does not container a 'VERSION = '"
        .format(args.version_from))

  attrs = {
      "name": args.name,
      "version": version
  }

  if args.has_extension_module:
    attrs["ext_modules"] = [
        Extension("__dummy", ["dummy.c"])
    ]

  dist = Distribution(attrs=attrs)
  bdist_wheel_cmd = dist.get_command_obj('bdist_wheel')
  bdist_wheel_cmd.ensure_finalized()
  distname = bdist_wheel_cmd.wheel_dist_name
  tag = '-'.join(bdist_wheel_cmd.get_tag())

  print("{}-{}.whl".format(distname, tag))


if __name__ == "__main__":
  main()