Example #1
0
    def verify_project_directory(project_directory, project_descriptor):
        project_directory = np(project_directory)

        if not os.path.exists(project_directory):
            raise PyBuilderException("Project directory does not exist: %s",
                                     project_directory)

        if not os.path.isdir(project_directory):
            raise PyBuilderException(
                "Project directory is not a directory: %s", project_directory)

        project_descriptor_full_path = jp(project_directory,
                                          project_descriptor)

        if not os.path.exists(project_descriptor_full_path):
            raise PyBuilderException(
                "Project directory does not contain descriptor file: %s",
                project_descriptor_full_path)

        if not os.path.isfile(project_descriptor_full_path):
            raise PyBuilderException("Project descriptor is not a file: %s",
                                     project_descriptor_full_path)

        return project_directory, project_descriptor_full_path
 def setUp(self):
     self.project = Project(np("/path/to/project"))
     self.project.set_property("dir_source_unittest_python", "unittest")
     self.project.set_property("dir_source_main_python", "src")
Example #3
0
 def test_expand_path_should_return_expanded_path(self):
     self.project.set_property("spam", "spam")
     self.project.set_property("eggs", "eggs")
     self.assertEqual(np(jp(self.project.basedir, "spam", "eggs")),
                      self.project.expand_path("$spam/$eggs"))
Example #4
0
def install_dependencies(logger, project, dependencies, python_env,
                         log_file_name,
                         local_mapping=None,
                         constraints_file_name=None,
                         log_file_mode="ab",
                         package_type="dependency",
                         target_dir=None,
                         ignore_installed=False,
                         ):
    entry_paths = target_dir or python_env.site_paths
    dependencies_to_install, orig_installed_pkgs, dependency_constraints = _filter_dependencies(logger,
                                                                                                project,
                                                                                                dependencies,
                                                                                                entry_paths,
                                                                                                ignore_installed)
    constraints_file = None
    if constraints_file_name:
        constraints_file = np(jp(python_env.env_dir, constraints_file_name))
        create_constraint_file(constraints_file, dependency_constraints)

    if not local_mapping:
        local_mapping = {}

    install_batch = []
    for dependency in dependencies_to_install:
        url = getattr(dependency, "url", None)
        install_options = {}

        if should_update_package(dependency.version) and not getattr(dependency, "version_not_a_spec", False):
            install_options["upgrade"] = True

        if dependency.name in local_mapping or url:
            install_options["force_reinstall"] = bool(url)

        if not target_dir and dependency.name in local_mapping:
            install_options["target_dir"] = local_mapping[dependency.name]

        install_batch.append((as_pip_install_target(dependency), install_options))

        logger.info("Processing %s packages '%s%s'%s to be installed with %s", package_type, dependency.name,
                    dependency.version if dependency.version else "",
                    " from %s" % url if url else "", install_options)

    if install_batch:
        pip_env = {"PIP_NO_INPUT": "1"}

        if project.offline:
            pip_env["PIP_NO_INDEX"] = "1"
            logger.warn("PIP will be operating in the offline mode")

        with open(np(log_file_name), log_file_mode) as log_file:
            results = pip_install_batches(install_batch,
                                          python_env,
                                          index_url=project.get_property("install_dependencies_index_url"),
                                          extra_index_url=project.get_property("install_dependencies_extra_index_url"),
                                          trusted_host=project.get_property("install_dependencies_trusted_host"),
                                          insecure_installs=project.get_property(
                                              "install_dependencies_insecure_installation"),
                                          verbose=project.get_property("pip_verbose"),
                                          constraint_file=constraints_file,
                                          logger=logger,
                                          outfile_name=log_file,
                                          error_file_name=log_file,
                                          target_dir=target_dir,
                                          ignore_installed=ignore_installed)
        for result in results:
            if result:
                raise BuildFailedException("Unable to install %s packages into %s. "
                                           "Please see '%s' for full details:\n%s",
                                           package_type,
                                           python_env.env_dir,
                                           log_file_name,
                                           tail_log(log_file_name))
    return dependencies_to_install
Example #5
0
 def expand_path(self, format_string, *additional_path_elements):
     elements = [self.basedir]
     elements += list(PATH_SEP_RE.split(self.expand(format_string)))
     elements += list(additional_path_elements)
     return np(jp(*elements))
    def test_sphinx_generate(self, mkdir, exists, rmtree, open):
        exists.return_value = True

        sphinx_mock = Mock()
        sys.modules["sphinx"] = sphinx_mock

        try:
            sphinx_mock.version_info = (1, 5, 3, 4, 5)

            self.project.set_property("sphinx_source_dir", "sphinx_source_dir")
            self.project.set_property("sphinx_config_path",
                                      "sphinx_config_path")
            self.project.set_property("sphinx_output_dir", "sphinx_output_dir")
            self.project.set_property("dir_target", "dir_target")
            self.project.set_property("dir_source_main_python", "dir_source")
            self.project.set_property("sphinx_project_name", "project_name")
            self.project.set_property("sphinx_project_conf", {
                "a": 1,
                "b": "foo"
            })
            self.project.set_property("sphinx_run_apidoc", True)
            self.project.set_property("sphinx_doc_builder", ["JSONx", "pdf"])

            sphinx_generate(self.project, Mock(), self.reactor)
        finally:
            del sys.modules["sphinx"]

        exists.assert_called_with(
            np(jp(self.project.basedir, "dir_target/sphinx_pyb/apidoc")))
        rmtree.assert_called_with(
            np(jp(self.project.basedir, "dir_target/sphinx_pyb/apidoc")))
        mkdir.assert_called_with(
            np(jp(self.project.basedir, "dir_target/sphinx_pyb/apidoc")))

        open().__enter__().write.assert_has_calls([
            call("a = 1\n"),
            call("b = 'foo'\n"),
            call("\nimport sys\nsys.path.insert(0, %r)\n" %
                 np(jp(self.project.basedir, "dir_source")))
        ],
                                                  any_order=True)
        self.pyb_env.execute_command.assert_has_calls([
            call(self.reactor.pybuilder_venv.executable + [
                "-c", ANY, "-H", "project_name", "-o",
                np(jp(self.project.basedir, "dir_target/sphinx_pyb/apidoc")),
                np(jp(self.project.basedir, "dir_source"))
            ],
                 np(
                     jp(self.project.basedir,
                        "dir_target/reports/sphinx-apidoc")),
                 shell=False),
            call(self.reactor.pybuilder_venv.executable + [
                "-c", ANY, "-b", "JSONx",
                np(jp(self.project.basedir, "sphinx_config_path")),
                np(jp(self.project.basedir, "sphinx_output_dir/JSONx"))
            ],
                 np(jp(self.project.basedir,
                       "dir_target/reports/sphinx_JSONx")),
                 shell=False),
            call(self.reactor.pybuilder_venv.executable + [
                "-c", ANY, "-b", "pdf",
                np(jp(self.project.basedir, "sphinx_config_path")),
                np(jp(self.project.basedir, "sphinx_output_dir/pdf"))
            ],
                 np(jp(self.project.basedir, "dir_target/reports/sphinx_pdf")),
                 shell=False)
        ])
Example #7
0
 def test_report(self):
     project = Project('.')
     project.set_property('dir_reports', np('any/dir'))
     expected = np(jp(project.basedir, 'any/dir/cram.err'))
     received = _report_file(project)
     self.assertEqual(expected, received)