Set the entry point of this PEX environment based upon a distribution script. :param script: The script name as defined either by a console script or ordinary script within the setup.py of one of the distributions added to the PEX. :raises: :class:`PEXBuilder.InvalidExecut
(self, script)
| 268 | self._pex_info.entry_point = entry_point.rpartition(".")[0] |
| 269 | |
| 270 | def set_script(self, script): |
| 271 | """Set the entry point of this PEX environment based upon a distribution script. |
| 272 | |
| 273 | :param script: The script name as defined either by a console script or ordinary |
| 274 | script within the setup.py of one of the distributions added to the PEX. |
| 275 | :raises: :class:`PEXBuilder.InvalidExecutableSpecification` if the script is not found |
| 276 | in any distribution added to the PEX. |
| 277 | """ |
| 278 | |
| 279 | distributions = OrderedSet(self._distributions.values()) |
| 280 | for pex in self._pex_info.pex_path: |
| 281 | if os.path.exists(pex): |
| 282 | distributions.update(PEX(pex, interpreter=self._interpreter).resolve()) |
| 283 | |
| 284 | # Check if 'script' is a console_script. |
| 285 | dist_entry_point = get_entry_point_from_console_script(script, distributions) |
| 286 | if dist_entry_point: |
| 287 | self.set_entry_point(str(dist_entry_point.entry_point)) |
| 288 | TRACER.log( |
| 289 | "Set entrypoint to {console_script}".format( |
| 290 | console_script=dist_entry_point.render_description() |
| 291 | ) |
| 292 | ) |
| 293 | return |
| 294 | |
| 295 | # Check if 'script' is an ordinary script. |
| 296 | dist_script = get_script_from_distributions(script, distributions) |
| 297 | if dist_script: |
| 298 | if self._pex_info.entry_point: |
| 299 | raise self.InvalidExecutableSpecification( |
| 300 | "Cannot set both entry point and script of PEX!" |
| 301 | ) |
| 302 | self._pex_info.script = script |
| 303 | TRACER.log("Set entrypoint to script {!r} in {!r}".format(script, dist_script.dist)) |
| 304 | return |
| 305 | |
| 306 | raise self.InvalidExecutableSpecification( |
| 307 | "Could not find script {!r} in any distribution {} within PEX!".format( |
| 308 | script, ", ".join(str(d) for d in distributions) |
| 309 | ) |
| 310 | ) |
| 311 | |
| 312 | def set_entry_point(self, entry_point): |
| 313 | """Set the entry point of this PEX environment. |