Package Code and Dependencies into wheelhouse
| 11 | |
| 12 | |
| 13 | class Package(Command): |
| 14 | """Package Code and Dependencies into wheelhouse""" |
| 15 | description = "Run wheels for dependencies and submodules dependencies" |
| 16 | user_options = [] |
| 17 | |
| 18 | def __init__(self, dist): |
| 19 | Command.__init__(self, dist) |
| 20 | |
| 21 | def initialize_options(self): |
| 22 | """Set default values for options.""" |
| 23 | pass |
| 24 | |
| 25 | def finalize_options(self): |
| 26 | """Post-process options.""" |
| 27 | |
| 28 | pass |
| 29 | |
| 30 | def localize_requirements(self): |
| 31 | """ |
| 32 | After the package is unpacked at the target destination, the requirements can be installed |
| 33 | locally from the wheelhouse folder using the option --no-index on pip install which |
| 34 | ignores package index (only looking at --find-links URLs instead). |
| 35 | --find-links <url | path> looks for archive from url or path. |
| 36 | Since the original requirements.txt might have links to a non pip repo such as github |
| 37 | (https) it will parse the links for the archive from a url and not from the wheelhouse. |
| 38 | This functions creates a new requirements.txt with the only name and version for each of |
| 39 | the packages, thus eliminating the need to fetch / parse links from http sources and install |
| 40 | all archives from the wheelhouse. |
| 41 | """ |
| 42 | dependencies = open("requirements.txt").read().split("\n") |
| 43 | local_dependencies = [] |
| 44 | |
| 45 | for dependency in dependencies: |
| 46 | if dependency: |
| 47 | # switched order or git and egg and took text before #egg |
| 48 | if "git+" in dependency: |
| 49 | pkg_name = dependency.split("/")[-1].split(".")[0].split('#egg')[0] |
| 50 | local_dependencies.append(pkg_name) |
| 51 | elif "egg=" in dependency: |
| 52 | pkg_name = dependency.split("egg=")[-1] |
| 53 | local_dependencies.append(pkg_name) |
| 54 | |
| 55 | else: |
| 56 | local_dependencies.append(dependency) |
| 57 | |
| 58 | print("local packages in wheel: %s", local_dependencies) |
| 59 | self.execute("mv requirements.txt requirements.orig") |
| 60 | |
| 61 | with open("requirements.txt", "w") as requirements_file: |
| 62 | # filter is used to remove empty list members (None). |
| 63 | requirements_file.write("\n".join(filter(None, local_dependencies))) |
| 64 | requirements_file.write('\nfount_experiment_runner') |
| 65 | |
| 66 | def execute(self, command, capture_output=False): |
| 67 | """ |
| 68 | The execute command will loop and keep on reading the stdout and check for the return code |
| 69 | and displays the output in real time. |
| 70 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected