Beispiel #1
0
    def ensure_project(self, options: argparse.Namespace,
                       obj: Optional[Project]) -> None:
        if obj is not None:
            options.project = obj
        if getattr(options, "project", None) is None:
            global_project = getattr(options, "global_project", None)

            default_root = (None if global_project or getattr(
                options, "search_parent", True) else ".")
            project = self.create_project(
                getattr(options, "project_path", None)
                or default_root,  # type: ignore
                is_global=global_project,
            )
            options.project = project

        migrate_pyproject(options.project)
Beispiel #2
0
    def main(self, args=None, prog_name=None, obj=None, **extra):
        """The main entry function"""
        from pdm.models.pip_shims import global_tempdir_manager

        self.init_parser()
        self.load_plugins()

        self.parser.set_defaults(global_project=None)
        options = self.parser.parse_args(args or None)
        stream.set_verbosity(options.verbose)

        if obj is not None:
            options.project = obj
        if options.global_project:
            options.project = options.global_project
        if options.pep582:
            print_pep582_command(options.pep582)
            sys.exit(0)
        if not getattr(options, "project", None):
            options.project = self.project_class()

        # Add reverse reference for core object
        options.project.core = self
        migrate_pyproject(options.project)

        try:
            f = options.handler
        except AttributeError:
            self.parser.print_help()
            sys.exit(1)
        else:
            try:
                with global_tempdir_manager():
                    f(options.project, options)
            except Exception:
                etype, err, traceback = sys.exc_info()
                if stream.verbosity > stream.NORMAL:
                    raise err.with_traceback(traceback)
                stream.echo(f"{stream.red('[' + etype.__name__ + ']')}: {err}",
                            err=True)
                stream.echo(
                    stream.yellow("Add '-v' to see the detailed traceback"))
                sys.exit(1)
Beispiel #3
0
    def ensure_project(self, options: argparse.Namespace,
                       obj: Optional[Project]) -> None:
        if obj is not None:
            options.project = obj
        if getattr(options, "project", None) is None:
            global_project = getattr(options, "global_project", None)
            if global_project:
                project_factory = self.project_class.create_global
            else:
                project_factory = self.project_class

            default_root = (None if global_project or getattr(
                options, "search_parent", True) else ".")
            project = project_factory(
                getattr(options, "project_path", default_root))
            options.project = project

        # Add reverse reference for core object
        options.project.core = self
        migrate_pyproject(options.project)
Beispiel #4
0
    def ensure_project(
        self, options: argparse.Namespace, obj: Optional[Project]
    ) -> None:
        if obj is not None:
            options.project = obj
        if getattr(options, "project", None) is None:
            project = None
            global_project = getattr(options, "global_project", None)
            if global_project is True:
                project_factory = self.project_class.create_global
            elif global_project:
                project = global_project
            else:
                project_factory = self.project_class

            if project is None:
                project = project_factory(getattr(options, "project_path", None))
            options.project = project

        # Add reverse reference for core object
        options.project.core = self
        migrate_pyproject(options.project)