def pip_import_string(python_exe): os_utils = OSUtils() cmd = [python_exe, "-c", "import pip; print(pip.__version__)"] p = os_utils.popen(cmd, stdout=os_utils.pipe, stderr=os_utils.pipe, env=os_utils.original_environ()) stdout, stderr = p.communicate() if not p.returncode == 0: raise MissingPipError(python_path=python_exe) pip_version = stdout.decode("utf-8").strip() pip_major_version = int(pip_version.split(".")[0]) pip_minor_version = int(pip_version.split(".")[1]) # Pip moved its internals to an _internal module in version 10. # In order to be compatible with version 9 which has it at at the # top level we need to figure out the correct import path here. if pip_major_version == 9: return "from pip import main" # Pip changed their import structure again in 19.3 # https://github.com/pypa/pip/commit/09fd200 elif (pip_major_version, pip_minor_version) >= (19, 3): return "from pip._internal.main import main" else: return "from pip._internal import main"
def pip_import_string(python_exe): os_utils = OSUtils() cmd = [ python_exe, "-c", "import pip; assert int(pip.__version__.split('.')[0]) <= 9" ] p = os_utils.popen(cmd,stdout=os_utils.pipe, stderr=os_utils.pipe) p.communicate() # Pip moved its internals to an _internal module in version 10. # In order to be compatible with version 9 which has it at at the # top level we need to figure out the correct import path here. if p.returncode == 0: return 'from pip import main' else: return 'from pip._internal import main'
def execute(self): os_utils = OSUtils() python_path = self.binaries[self.LANGUAGE].binary_path try: pip = SubprocessPip(osutils=os_utils, python_exe=python_path) except MissingPipError as ex: raise ActionFailedError(str(ex)) pip_runner = PipRunner(python_exe=python_path, pip=pip) dependency_builder = DependencyBuilder(osutils=os_utils, pip_runner=pip_runner, runtime=self.runtime, architecture=self.architecture) package_builder = PythonPipDependencyBuilder( osutils=os_utils, runtime=self.runtime, dependency_builder=dependency_builder) try: target_artifact_dir = self.artifacts_dir # if dependencies folder is provided, download the dependencies into dependencies folder if self.dependencies_dir: target_artifact_dir = self.dependencies_dir package_builder.build_dependencies( artifacts_dir_path=target_artifact_dir, scratch_dir_path=self.scratch_dir, requirements_path=self.manifest_path, ) except PackagerError as ex: raise ActionFailedError(str(ex))
def setUp(self): self.osutils = OSUtils() self.osutils_mock = Mock(spec=self.osutils) self.osutils_mock.file_exists.return_value = True self.workflow = PythonPipWorkflow("source", "artifacts", "scratch_dir", "manifest", runtime="python3.7", osutils=self.osutils_mock)
def pip_import_string(python_exe): os_utils = OSUtils() cmd = [python_exe, "-c", "import pip; print(pip.__version__)"] p = os_utils.popen(cmd, stdout=os_utils.pipe, stderr=os_utils.pipe) stdout, stderr = p.communicate() pip_version = stdout.decode('utf-8').strip() pip_major_version = int(pip_version.split('.')[0]) pip_minor_version = int(pip_version.split('.')[1]) # Pip moved its internals to an _internal module in version 10. # In order to be compatible with version 9 which has it at at the # top level we need to figure out the correct import path here. if pip_major_version == 9: return 'from pip import main' # Pip changed their import structure again in 19.3 # https://github.com/pypa/pip/commit/09fd200 elif pip_major_version >= 19 and pip_minor_version >= 3: return 'from pip._internal.main import main' else: return 'from pip._internal import main'
def execute(self): os_utils = OSUtils() python_path = self.binaries[self.LANGUAGE].binary_path pip = SubprocessPip(osutils=os_utils, python_exe=python_path) pip_runner = PipRunner(python_exe=python_path, pip=pip) dependency_builder = DependencyBuilder(osutils=os_utils, pip_runner=pip_runner, runtime=self.runtime) package_builder = PythonPipDependencyBuilder(osutils=os_utils, runtime=self.runtime, dependency_builder=dependency_builder) try: package_builder.build_dependencies( self.artifacts_dir, self.manifest_path, self.scratch_dir ) except PackagerError as ex: raise ActionFailedError(str(ex))
def osutils(): return OSUtils()
def _make_appdir_and_dependency_builder(self, reqs, tmpdir, runner): appdir = str(_create_app_structure(tmpdir)) self._write_requirements_txt(reqs, appdir) builder = DependencyBuilder(OSUtils(), "python3.6", runner) return appdir, builder