Beispiel #1
0
 def _get_file_contents(self, path):
     if isurl(path):
         return requests.get(path).text
     else:
         file_path = os.path.join(self.sourcedir, path)
         with open(file_path) as _file:
             return _file.read()
Beispiel #2
0
    def _run_pip(self, setup, download=False):
        self._install_pip(download)

        env = self._get_build_env()

        constraints = []
        if self.options.constraints:
            if isurl(self.options.constraints):
                constraints = self.options.constraints
            else:
                constraints = os.path.join(self.sourcedir,
                                           self.options.constraints)

        pip = _Pip(exec_func=self.run, runnable='pip',
                   package_dir=self._python_package_dir, env=env,
                   constraints=constraints,
                   dependency_links=self.options.process_dependency_links)

        commands = self._get_commands(setup)

        if download:
            for command in commands:
                pip.download(**command)
        else:
            for command in commands:
                wheels = pip.wheel(**command)
                installed = pip.list(self.run_output)
                wheel_names = [os.path.basename(w).split('-')[0]
                               for w in wheels]
                # we want to avoid installing what is already provided in
                # stage-packages
                need_install = [k for k in wheel_names if k not in installed]
                pip.install(need_install + ['--no-deps', '--upgrade'])
Beispiel #3
0
    def _run_pip(self, setup, download=False):
        self._install_pip(download)

        env = self._get_build_env()

        constraints = []
        if self.options.constraints:
            if isurl(self.options.constraints):
                constraints = self.options.constraints
            else:
                constraints = os.path.join(self.sourcedir,
                                           self.options.constraints)

        pip = _Pip(exec_func=self.run, runnable='pip',
                   package_dir=self._python_package_dir, env=env,
                   constraints=constraints,
                   dependency_links=self.options.process_dependency_links)

        commands = self._get_commands(setup)

        if download:
            for command in commands:
                pip.download(**command)
        else:
            for command in commands:
                wheels = pip.wheel(**command)
                installed = pip.list(self.run_output)
                wheel_names = [os.path.basename(w).split('-')[0]
                               for w in wheels]
                # we want to avoid installing what is already provided in
                # stage-packages
                need_install = [k for k in wheel_names if k not in installed]
                pip.install(need_install + ['--no-deps', '--upgrade'])
Beispiel #4
0
 def _get_file_contents(self, path):
     if isurl(path):
         return requests.get(path).text
     else:
         file_path = os.path.join(self.sourcedir, path)
         with open(file_path) as _file:
             return _file.read()
Beispiel #5
0
    def _run_pip(self, setup, download=False):
        self._install_pip(download)

        env = self._get_build_env()

        constraints = []
        if self.options.constraints:
            if isurl(self.options.constraints):
                constraints = self.options.constraints
            else:
                constraints = os.path.join(self.sourcedir,
                                           self.options.constraints)

        pip = _Pip(exec_func=self.run, runnable='pip',
                   package_dir=self._python_package_dir, env=env,
                   constraints=constraints,
                   dependency_links=self.options.process_dependency_links)

        if self.options.requirements:
            if isurl(self.options.requirements):
                requirements = self.options.requirements
            else:
                requirements = os.path.join(self.sourcedir,
                                            self.options.requirements)
            if download:
                pip.download(['--requirement', requirements])
            else:
                pip.wheel(['--requirement', requirements])
                pip.install(['--requirement', requirements])

        if self.options.python_packages:
            if download:
                pip.download(self.options.python_packages)
            else:
                pip.wheel(self.options.python_packages)
                pip.install(self.options.python_packages)

        if os.path.exists(setup):
            cwd = os.path.dirname(setup)
            if download:
                pip.download(['.'], cwd=cwd)
            else:
                pip.wheel(['.'], cwd=cwd)
                pip.install(['.'], cwd=cwd)
Beispiel #6
0
    def _get_requirements(self):
        requirements = None
        if self.options.requirements:
            if isurl(self.options.requirements):
                requirements = {self.options.requirements}
            else:
                requirements = {os.path.join(
                    self.sourcedir, self.options.requirements)}

        return requirements
Beispiel #7
0
 def _get_constraints(self):
     constraints = None
     if self.options.constraints:
         if isurl(self.options.constraints):
             constraints = {self.options.constraints}
         else:
             constraints = {
                 os.path.join(self.sourcedir, self.options.constraints)
             }
     return constraints
Beispiel #8
0
 def _get_constraints(self):
     constraints = None
     if self.options.constraints:
         if isurl(self.options.constraints):
             constraints = {self.options.constraints}
         else:
             constraints_file = self._find_file(filename=self.options.constraints)
             if not constraints_file:
                 raise SnapcraftPluginPythonFileMissing(
                     plugin_property="constraints",
                     plugin_property_value=self.options.constraints,
                 )
             constraints = {constraints_file}
     return constraints
Beispiel #9
0
    def _get_requirements(self):
        requirements = None
        if self.options.requirements:
            if isurl(self.options.requirements):
                requirements = {self.options.requirements}
            else:
                requirements_file = self._find_file(filename=self.options.requirements)
                if not requirements_file:
                    raise SnapcraftPluginPythonFileMissing(
                        plugin_property="requirements",
                        plugin_property_value=self.options.requirements,
                    )
                requirements = {requirements_file}

        return requirements
Beispiel #10
0
    def _get_normalized_property_set(self, property_name,
                                     property_list: List[str]) -> Set[str]:
        """Return a normalized set from a requirements or constraints list."""
        normalized = set()  # type: Set[str]
        for entry in property_list:
            if isurl(entry):
                normalized.add(entry)
            else:
                entry_file = self._find_file(filename=entry)
                if not entry_file:
                    raise SnapcraftPluginPythonFileMissing(
                        plugin_property=property_name,
                        plugin_property_value=entry)
                normalized.add(entry_file)

        return normalized
Beispiel #11
0
    def _run_pip(self, setup, download=False):
        self._install_pip(download)

        env = self._get_build_env()

        pip_command = [self._get_python_command(), '-m', 'pip']

        constraints = []
        if self.options.constraints:
            if isurl(self.options.constraints):
                constraints = self.options.constraints
            else:
                constraints = os.path.join(self.sourcedir,
                                           self.options.constraints)

        pip = _Pip(exec_func=self.run,
                   runnable=pip_command,
                   package_dir=self._python_package_dir,
                   env=env,
                   constraints=constraints,
                   dependency_links=self.options.process_dependency_links)

        commands = self._get_commands(setup)

        if download:
            for command in commands:
                pip.download(**command)
        else:
            for command in commands:
                wheels = pip.wheel(**command)
                installed = pip.list(self.run_output)
                wheel_names = [
                    os.path.basename(w).split('-')[0] for w in wheels
                ]
                # we want to avoid installing what is already provided in
                # stage-packages
                need_install = [k for k in wheel_names if k not in installed]
                pip.install(need_install + ['--no-deps', '--upgrade'])
            if os.path.exists(setup):
                # pbr and others don't work using `pip install .`
                # LP: #1670852
                # There is also a chance that this setup.py is distutils based
                # in which case we will rely on the `pip install .` ran before
                #  this.
                with suppress(subprocess.CalledProcessError):
                    self._setup_tools_install(setup)
        return pip.list(self.run_output)
Beispiel #12
0
    def _run_pip(self, setup, download=False):
        self._install_pip(download)

        env = self._get_build_env()

        pip_command = [self._get_python_command(), '-m', 'pip']

        constraints = []
        if self.options.constraints:
            if isurl(self.options.constraints):
                constraints = self.options.constraints
            else:
                constraints = os.path.join(self.sourcedir,
                                           self.options.constraints)

        pip = _Pip(exec_func=self.run,
                   runnable=pip_command,
                   package_dir=self._python_package_dir, env=env,
                   constraints=constraints,
                   dependency_links=self.options.process_dependency_links)

        commands = self._get_commands(setup)

        if download:
            for command in commands:
                pip.download(**command)
        else:
            for command in commands:
                wheels = pip.wheel(**command)
                installed = pip.list(self.run_output)
                wheel_names = [os.path.basename(w).split('-')[0]
                               for w in wheels]
                # we want to avoid installing what is already provided in
                # stage-packages
                need_install = [k for k in wheel_names if k not in installed]
                pip.install(need_install + ['--no-deps', '--upgrade'])
            if os.path.exists(setup):
                # pbr and others don't work using `pip install .`
                # LP: #1670852
                # There is also a chance that this setup.py is distutils based
                # in which case we will rely on the `pip install .` ran before
                #  this.
                with suppress(subprocess.CalledProcessError):
                    self._setup_tools_install(setup)
        return pip.list(self.run_output)
Beispiel #13
0
    def _get_commands(self, setup):
        commands = []
        if self.options.requirements:
            requirements = self.options.requirements
            if not isurl(requirements):
                requirements = os.path.join(self.sourcedir,
                                            self.options.requirements)

            commands.append(dict(args=['--requirement', requirements]))

        if self.options.python_packages:
            commands.append(dict(args=self.options.python_packages))

        if os.path.exists(setup):
            cwd = os.path.dirname(setup)
            commands.append(dict(args=['.'], cwd=cwd))

        return commands
Beispiel #14
0
    def _get_pip_command(self):
        self._install_pip()

        pip_install = ['pip', 'install', '--user', '--no-compile',
                       '--disable-pip-version-check']

        if self.options.constraints:
            if isurl(self.options.constraints):
                constraints = self.options.constraints
            else:
                constraints = os.path.join(self.sourcedir,
                                           self.options.constraints)
            pip_install = pip_install + ['--constraint', constraints]

        if self.options.process_dependency_links:
            pip_install.append('--process-dependency-links')

        return pip_install
Beispiel #15
0
    def _get_commands(self, setup):
        commands = []
        if self.options.requirements:
            requirements = self.options.requirements
            if not isurl(requirements):
                requirements = os.path.join(self.sourcedir,
                                            self.options.requirements)

            commands.append(dict(args=['--requirement', requirements]))

        if self.options.python_packages:
            commands.append(dict(args=self.options.python_packages))

        if os.path.exists(setup):
            cwd = os.path.dirname(setup)
            commands.append(dict(args=['.'], cwd=cwd))

        return commands
Beispiel #16
0
    def _get_pip_command(self):
        self._install_pip()

        pip_install = ['pip', 'install', '--user', '--no-compile',
                       '--disable-pip-version-check']

        if self.options.constraints:
            if isurl(self.options.constraints):
                constraints = self.options.constraints
            else:
                constraints = os.path.join(self.sourcedir,
                                           self.options.constraints)
            pip_install = pip_install + ['--constraint', constraints]

        if self.options.process_dependency_links:
            pip_install.append('--process-dependency-links')

        return pip_install
Beispiel #17
0
    def _run_pip(self, setup):
        pip_install = self._get_pip_command()

        env = self._get_build_env()

        if self.options.requirements:
            if isurl(self.options.requirements):
                requirements = self.options.requirements
            else:
                requirements = os.path.join(self.sourcedir,
                                            self.options.requirements)
            self.run(pip_install + ['--requirement', requirements], env=env)

        if self.options.python_packages:
            self.run(pip_install + self.options.python_packages, env=env)

        if os.path.exists(setup):
            cwd = os.path.dirname(setup)
            self.run(pip_install + ['.'], cwd=cwd, env=env)
Beispiel #18
0
    def _run_pip(self, setup):
        pip_install = self._get_pip_command()

        env = self._get_build_env()

        if self.options.requirements:
            if isurl(self.options.requirements):
                requirements = self.options.requirements
            else:
                requirements = os.path.join(self.sourcedir,
                                            self.options.requirements)
            self.run(pip_install + ['--requirement', requirements], env=env)

        if self.options.python_packages:
            self.run(pip_install + self.options.python_packages, env=env)

        if os.path.exists(setup):
            cwd = os.path.dirname(setup)
            self.run(pip_install + ['.'], cwd=cwd, env=env)
Beispiel #19
0
    def _get_commands(self, setup):
        args = []
        cwd = None
        if self.options.requirements:
            requirements = self.options.requirements
            if not isurl(requirements):
                requirements = os.path.join(self.sourcedir,
                                            self.options.requirements)

            args.extend(['--requirement', requirements])
        if os.path.exists(setup):
            args.append('.')
            cwd = os.path.dirname(setup)

        if self.options.python_packages:
            args.extend(self.options.python_packages)

        if args:
            return [dict(args=args, cwd=cwd)]
        else:
            return []
Beispiel #20
0
    def _get_commands(self, setup):
        args = []
        cwd = None
        if self.options.requirements:
            requirements = self.options.requirements
            if not isurl(requirements):
                requirements = os.path.join(self.sourcedir,
                                            self.options.requirements)

            args.extend(['--requirement', requirements])
        if os.path.exists(setup):
            args.append('.')
            cwd = os.path.dirname(setup)

        if self.options.python_packages:
            args.extend(self.options.python_packages)

        if args:
            return [dict(args=args, cwd=cwd)]
        else:
            return []
Beispiel #21
0
 def test_isurl(self):
     self.assertTrue(common.isurl('git://'))
     self.assertTrue(common.isurl('bzr://'))
     self.assertFalse(common.isurl('./'))
     self.assertFalse(common.isurl('/foo'))
     self.assertFalse(common.isurl('/fo:o'))
Beispiel #22
0
 def test_isurl(self):
     self.assertTrue(common.isurl('git://'))
     self.assertTrue(common.isurl('bzr://'))
     self.assertFalse(common.isurl('./'))
     self.assertFalse(common.isurl('/foo'))
     self.assertFalse(common.isurl('/fo:o'))