|
| 1 | +"""Rename enclosing package directories to give them a natural order. |
| 2 | +
|
| 3 | +This file depends on the requirements package, which you can get via: |
| 4 | +pip install requirements-parser |
| 5 | +
|
| 6 | +""" |
| 7 | +import shutil |
| 8 | +import os |
| 9 | +import requirements |
| 10 | +from plotly.version import __version__ |
| 11 | + |
| 12 | +plotly_name = 'plotly' |
| 13 | +file_dir = os.path.split(__file__)[0] |
| 14 | +dist_dir = os.path.join(file_dir, '..', 'stand_alone_dist', 'dist') |
| 15 | +requirements_file = os.path.join(file_dir, '..', 'requirements.txt') |
| 16 | +dependency_packages = os.listdir(dist_dir) |
| 17 | + |
| 18 | +# get ordered dependencies |
| 19 | +with open(requirements_file, 'r') as f: |
| 20 | + contents = f.read() |
| 21 | +num_deps = sum(1 for _ in requirements.parse(contents)) |
| 22 | +reqs = requirements.parse(contents) |
| 23 | + |
| 24 | +# for each dependency, find the uncompressed package and rename it (order it) |
| 25 | +for req_num, req in enumerate(reqs): |
| 26 | + for package_name in dependency_packages: |
| 27 | + if req.name == package_name.split('-')[0]: |
| 28 | + src = os.path.join(dist_dir, package_name) |
| 29 | + dst = os.path.join(dist_dir, "{}_{}-{}".format( |
| 30 | + req_num, req.name, req.specs[0][1] |
| 31 | + )) |
| 32 | + shutil.move(src, dst) |
| 33 | + |
| 34 | +# rename plotly to be the last thing installed |
| 35 | +for package_name in dependency_packages: |
| 36 | + if plotly_name == package_name.split('-')[0]: |
| 37 | + src = os.path.join(dist_dir, package_name) |
| 38 | + dst = os.path.join(dist_dir, "{}_{}-{}".format( |
| 39 | + num_deps, plotly_name, __version__ |
| 40 | + )) |
| 41 | + shutil.move(src, dst) |
0 commit comments