def get_user_required_packages(app_dir_path): """Look for a requirements.txt file. If found, parse the file and return a list of eggs. """ requirements_file = os.path.join(app_dir_path, "requirements.txt") if os.path.exists(requirements_file): logger.debug("Found requirements.txt file") return parse_requirements.parse(requirements_file) else: logger.debug("Did not find requirements.txt file") return []
def install_requirements(python_virtualenv_dir, requirements_file, package_cache_dir=None): if len(package_data.problem_packages)>0: # If there are packages known to cause problems, we check that list # against the requirements file and stop everything if a problematic # package is found. packages = parse(requirements_file, parse_version_constraints=False) for pkg in packages: lpkg = pkg.lower() if lpkg in package_data.problem_packages: raise RequestedPackageError( "Package '%s' is known to cause problems with Engage deployments. Please remove it from your requirements.txt file (or comment it out)." % pkg) pip = os.path.abspath(os.path.join(os.path.expanduser(python_virtualenv_dir), "bin/pip")) if not os.path.exists(pip): raise RequestedPackageError("Could not find pip executable") req_file_path = os.path.abspath(os.path.expanduser(requirements_file)) if package_cache_dir: # If the package cache is present, we read through the requirements file to see # if we have any matches. If matches are found, we install them directly. We'll # still run pip on the requirements file at the end to catch anything that is missing # or the wrong version. package_cache_dir = os.path.abspath(os.path.expanduser(package_cache_dir)) logger.debug("Checking for packages in directory %s" % package_cache_dir) if os.path.exists(package_cache_dir): cache_files = os.listdir(package_cache_dir) package_files = get_local_files_matching_requirements(requirements_file, cache_files) for pkg_file in package_files: pkg_path = os.path.join(package_cache_dir, pkg_file) logger.debug("Installing %s from package cache" % pkg_file) cmd = [pip, "install", pkg_path] try: check_run_and_log_program(cmd, None, logger) except Exception, e: logger.exception("Problem in running pip on package %s. Command was '%s', error was %s" % (pkg_file, ' '.join(cmd), str(e))) raise PipError("Problem in running pip on package %s. Command was '%s', error was %s" % (pkg_file, ' '.join(cmd), str(e)))