Takes the installed zappa and brings it into a fresh virtualenv-like folder. All dependencies are then downloaded.
(self, use_zappa_release: Optional[str] = None)
| 375 | return list(set(deps)) # de-dupe before returning |
| 376 | |
| 377 | def create_handler_venv(self, use_zappa_release: Optional[str] = None): |
| 378 | """ |
| 379 | Takes the installed zappa and brings it into a fresh virtualenv-like folder. All dependencies are then downloaded. |
| 380 | """ |
| 381 | import subprocess |
| 382 | |
| 383 | # We will need the currenv venv to pull Zappa from |
| 384 | current_venv: Optional[Path] = self.get_current_venv() |
| 385 | |
| 386 | # Make a new folder for the handler packages |
| 387 | ve_path: Path = Path.cwd() / "handler_venv" |
| 388 | |
| 389 | if current_venv and sys.platform == "win32": |
| 390 | current_site_packages_dir = current_venv / "Lib" / "site-packages" |
| 391 | venv_site_packages_dir = ve_path / "Lib" / "site-packages" |
| 392 | elif current_venv: |
| 393 | current_site_packages_dir = current_venv / "lib" / get_venv_from_python_version() / "site-packages" |
| 394 | venv_site_packages_dir = ve_path / "lib" / get_venv_from_python_version() / "site-packages" |
| 395 | else: |
| 396 | raise ValueError("Could not determine current virtualenv. Please activate it before running this command.") |
| 397 | |
| 398 | if not venv_site_packages_dir.exists(): |
| 399 | venv_site_packages_dir.mkdir(parents=True, exist_ok=True) |
| 400 | |
| 401 | # Copy zappa* to the new virtualenv |
| 402 | for zappa_thing in current_site_packages_dir.glob("[zZ]appa*"): |
| 403 | # copytree( |
| 404 | # os.path.join(current_site_packages_dir, z), |
| 405 | # os.path.join(venv_site_packages_dir, z), |
| 406 | # ) |
| 407 | dest = venv_site_packages_dir / zappa_thing.name |
| 408 | copytree(zappa_thing.resolve(), dest.resolve()) |
| 409 | |
| 410 | # Use pip to download zappa's dependencies. |
| 411 | # Copying from current venv causes issues with things like PyYAML that installs as yaml |
| 412 | zappa_deps = self.get_deps_list("zappa") |
| 413 | pkg_list = [] |
| 414 | for dep, version in zappa_deps: |
| 415 | # allow specified zappa version for slim_handler_test |
| 416 | if dep == "zappa" and use_zappa_release: |
| 417 | pkg_version_str = f"{dep}=={use_zappa_release}" |
| 418 | else: |
| 419 | pkg_version_str = f"{dep}=={version}" |
| 420 | pkg_list.append(pkg_version_str) |
| 421 | |
| 422 | # Need to manually add setuptools |
| 423 | pkg_list.append("setuptools") |
| 424 | command = [ |
| 425 | "pip", |
| 426 | "install", |
| 427 | "--quiet", |
| 428 | "--target", |
| 429 | str(venv_site_packages_dir), |
| 430 | ] + pkg_list |
| 431 | |
| 432 | # This is the recommended method for installing packages if you don't |
| 433 | # to depend on `setuptools` |
| 434 | # https://github.com/pypa/pip/issues/5240#issuecomment-381662679 |