def handle(self): from poetry.layouts import layout from poetry.semver import parse_constraint from poetry.utils._compat import Path from poetry.utils.env import SystemEnv from poetry.vcs.git import GitConfig if self.option("src"): layout_ = layout("src") else: layout_ = layout("standard") path = Path.cwd() / Path(self.argument("path")) name = self.option("name") if not name: name = path.name if path.exists(): if list(path.glob("*")): # Directory is not empty. Aborting. raise RuntimeError("Destination <fg=yellow>{}</> " "exists and is not empty".format(path)) readme_format = "rst" config = GitConfig() author = None if config.get("user.name"): author = config["user.name"] author_email = config.get("user.email") if author_email: author += " <{}>".format(author_email) current_env = SystemEnv(Path(sys.executable)) default_python = "^{}".format(".".join( str(v) for v in current_env.version_info[:2])) dev_dependencies = {} python_constraint = parse_constraint(default_python) if parse_constraint("<3.5").allows_any(python_constraint): dev_dependencies["pytest"] = "^4.6" if parse_constraint(">=3.5").allows_all(python_constraint): dev_dependencies["pytest"] = "^5.2" layout_ = layout_( name, "0.1.0", author=author, readme_format=readme_format, python=default_python, dev_dependencies=dev_dependencies, ) layout_.create(path) self.line("Created package <info>{}</> in <fg=blue>{}</>".format( module_name(name), path.relative_to(Path.cwd())))
def handle(self): from poetry.layouts import layout from poetry.utils._compat import Path from poetry.utils.env import EnvManager from poetry.vcs.git import GitConfig if self.option("src"): layout_ = layout("src") else: layout_ = layout("standard") path = Path.cwd() / Path(self.argument("path")) name = self.option("name") if not name: name = path.name if path.exists(): if list(path.glob("*")): # Directory is not empty. Aborting. raise RuntimeError( "Destination <fg=yellow>{}</> " "exists and is not empty".format(path) ) readme_format = "rst" config = GitConfig() author = None if config.get("user.name"): author = config["user.name"] author_email = config.get("user.email") if author_email: author += " <{}>".format(author_email) current_env = EnvManager().get(Path.cwd()) default_python = "^{}".format( ".".join(str(v) for v in current_env.version_info[:2]) ) layout_ = layout_( name, "0.1.0", author=author, readme_format=readme_format, python=default_python, ) layout_.create(path) self.line( "Created package <info>{}</> in <fg=blue>{}</>".format( name, path.relative_to(Path.cwd()) ) )
def handle(self): from poetry.layouts import layout from poetry.utils._compat import Path from poetry.vcs.git import GitConfig if self.option('src'): layout_ = layout('src') else: layout_ = layout('standard') path = Path.cwd() / Path(self.argument('path')) name = self.option('name') if not name: name = path.name if path.exists(): if list(path.glob('*')): # Directory is not empty. Aborting. raise RuntimeError( 'Destination <fg=yellow>{}</> ' 'exists and is not empty'.format( path ) ) readme_format = 'rst' config = GitConfig() author = None if config.get('user.name'): author = config['user.name'] author_email = config.get('user.email') if author_email: author += ' <{}>'.format(author_email) layout_ = layout_(name, '0.1.0', author=author, readme_format=readme_format) layout_.create(path) self.line( 'Created package <info>{}</> in <fg=blue>{}</>' .format(name, path.relative_to(Path.cwd())) )
def handle(self): from poetry.layouts import layout from poetry.utils._compat import Path from poetry.vcs.git import GitConfig if self.option("src"): layout_ = layout("src") else: layout_ = layout("standard") path = Path.cwd() / Path(self.argument("path")) name = self.option("name") if not name: name = path.name if path.exists(): if list(path.glob("*")): # Directory is not empty. Aborting. raise RuntimeError( "Destination <fg=yellow>{}</> " "exists and is not empty".format(path) ) readme_format = "rst" config = GitConfig() author = None if config.get("user.name"): author = config["user.name"] author_email = config.get("user.email") if author_email: author += " <{}>".format(author_email) layout_ = layout_(name, "0.1.0", author=author, readme_format=readme_format) layout_.create(path) self.line( "Created package <info>{}</> in <fg=blue>{}</>".format( name, path.relative_to(Path.cwd()) ) )
def handle(self): from poetry.layouts import layout from poetry.utils._compat import Path from poetry.utils.env import Env from poetry.vcs.git import GitConfig if (Path.cwd() / "pyproject.toml").exists(): self.error("A pyproject.toml file already exists.") return 1 vcs_config = GitConfig() self.line([ "", "This command will guide you through creating your <info>pyproject.toml</> config.", "", ]) name = self.option("name") if not name: name = Path.cwd().name.lower() question = self.create_question( "Package name [<comment>{}</comment>]: ".format(name), default=name) name = self.ask(question) version = "0.1.0" question = self.create_question( "Version [<comment>{}</comment>]: ".format(version), default=version) version = self.ask(question) description = self.option("description") or "" question = self.create_question( "Description [<comment>{}</comment>]: ".format(description), default=description, ) description = self.ask(question) author = self.option("author") if not author and vcs_config and vcs_config.get("user.name"): author = vcs_config["user.name"] author_email = vcs_config.get("user.email") if author_email: author += " <{}>".format(author_email) question = self.create_question( "Author [<comment>{}</comment>, n to skip]: ".format(author), default=author) question.validator = lambda v: self._validate_author(v, author) author = self.ask(question) if not author: authors = [] else: authors = [author] license = self.option("license") or "" question = self.create_question( "License [<comment>{}</comment>]: ".format(license), default=license) question.validator = self._validate_license license = self.ask(question) current_env = Env.get() default_python = "^{}".format(".".join( str(v) for v in current_env.version_info[:2])) question = self.create_question( "Compatible Python versions [<comment>{}</comment>]: ".format( default_python), default=default_python, ) python = self.ask(question) self.line("") requirements = {} question = ("Would you like to define your dependencies" " (require) interactively?") if self.confirm(question, True): requirements = self._format_requirements( self._determine_requirements(self.option("dependency"))) dev_requirements = {} question = ("Would you like to define your dev dependencies" " (require-dev) interactively") if self.confirm(question, True): dev_requirements = self._format_requirements( self._determine_requirements(self.option("dev-dependency"))) layout_ = layout("standard")( name, version, description=description, author=authors[0] if authors else None, license=license, python=python, dependencies=requirements, dev_dependencies=dev_requirements, ) content = layout_.generate_poetry_content() if self.input.is_interactive(): self.line("<info>Generated file</info>") self.line(["", content, ""]) if not self.confirm("Do you confirm generation?", True): self.line("<error>Command aborted</error>") return 1 with (Path.cwd() / "pyproject.toml").open("w") as f: f.write(content)
def handle(self): from poetry.layouts import layout from poetry.utils._compat import Path from poetry.utils.env import EnvManager from poetry.vcs.git import GitConfig if (Path.cwd() / "pyproject.toml").exists(): self.line("<error>A pyproject.toml file already exists.</error>") return 1 vcs_config = GitConfig() self.line("") self.line( "This command will guide you through creating your <info>pyproject.toml</> config." ) self.line("") name = self.option("name") if not name: name = Path.cwd().name.lower() question = self.create_question( "Package name [<comment>{}</comment>]: ".format(name), default=name) name = self.ask(question) version = "0.1.0" question = self.create_question( "Version [<comment>{}</comment>]: ".format(version), default=version) version = self.ask(question) description = self.option("description") or "" question = self.create_question( "Description [<comment>{}</comment>]: ".format(description), default=description, ) description = self.ask(question) author = self.option("author") if not author and vcs_config and vcs_config.get("user.name"): author = vcs_config["user.name"] author_email = vcs_config.get("user.email") if author_email: author += " <{}>".format(author_email) question = self.create_question( "Author [<comment>{}</comment>, n to skip]: ".format(author), default=author) question.set_validator(lambda v: self._validate_author(v, author)) author = self.ask(question) if not author: authors = [] else: authors = [author] license = self.option("license") or "" question = self.create_question( "License [<comment>{}</comment>]: ".format(license), default=license) question.set_validator(self._validate_license) license = self.ask(question) current_env = EnvManager().get(Path.cwd()) default_python = "^{}".format(".".join( str(v) for v in current_env.version_info[:2])) question = self.create_question( "Compatible Python versions [<comment>{}</comment>]: ".format( default_python), default=default_python, ) python = self.ask(question) self.line("") requirements = {} question = "Would you like to define your main dependencies interactively?" help_message = ( "You can specify a package in the following forms:\n" " - A single name (<b>requests</b>)\n" " - A name and a constraint (<b>requests ^2.23.0</b>)\n" " - A git url (<b>https://github.com/sdispater/poetry.git</b>)\n" " - A git url with a revision (<b>https://github.com/sdispater/poetry.git@develop</b>)\n" " - A file path (<b>../my-package/my-package.whl</b>)\n" " - A directory (<b>../my-package/</b>)\n") help_displayed = False if self.confirm(question, True): self.line(help_message) help_displayed = True requirements = self._format_requirements( self._determine_requirements(self.option("dependency"))) self.line("") dev_requirements = {} question = ("Would you like to define your dev dependencies" " (require-dev) interactively") if self.confirm(question, True): if not help_displayed: self.line(help_message) dev_requirements = self._format_requirements( self._determine_requirements(self.option("dev-dependency"))) self.line("") layout_ = layout("standard")( name, version, description=description, author=authors[0] if authors else None, license=license, python=python, dependencies=requirements, dev_dependencies=dev_requirements, ) content = layout_.generate_poetry_content() if self.io.is_interactive(): self.line("<info>Generated file</info>") self.line("") self.line(content) self.line("") if not self.confirm("Do you confirm generation?", True): self.line("<error>Command aborted</error>") return 1 with (Path.cwd() / "pyproject.toml").open("w", encoding="utf-8") as f: f.write(content)
def handle(self): from poetry.layouts import layout from poetry.utils._compat import Path from poetry.vcs.git import GitConfig if (Path.cwd() / "pyproject.toml").exists(): self.error("A pyproject.toml file already exists.") return 1 vcs_config = GitConfig() self.line( [ "", "This command will guide you through creating your <info>pyproject.toml</> config.", "", ] ) name = self.option("name") if not name: name = Path.cwd().name.lower() question = self.create_question( "Package name [<comment>{}</comment>]: ".format(name), default=name ) name = self.ask(question) version = "0.1.0" question = self.create_question( "Version [<comment>{}</comment>]: ".format(version), default=version ) version = self.ask(question) description = self.option("description") or "" question = self.create_question( "Description [<comment>{}</comment>]: ".format(description), default=description, ) description = self.ask(question) author = self.option("author") if not author and vcs_config and vcs_config.get("user.name"): author = vcs_config["user.name"] author_email = vcs_config.get("user.email") if author_email: author += " <{}>".format(author_email) question = self.create_question( "Author [<comment>{}</comment>, n to skip]: ".format(author), default=author ) question.validator = lambda v: self._validate_author(v, author) author = self.ask(question) if not author: authors = [] else: authors = [author] license = self.option("license") or "" question = self.create_question( "License [<comment>{}</comment>]: ".format(license), default=license ) question.validator = self._validate_license license = self.ask(question) question = self.create_question("Compatible Python versions [*]: ", default="*") python = self.ask(question) self.line("") requirements = {} question = "Would you like to define your dependencies" " (require) interactively?" if self.confirm(question, True): requirements = self._format_requirements( self._determine_requirements(self.option("dependency")) ) dev_requirements = {} question = "Would you like to define your dev dependencies" " (require-dev) interactively" if self.confirm(question, True): dev_requirements = self._format_requirements( self._determine_requirements(self.option("dev-dependency")) ) layout_ = layout("standard")( name, version, description=description, author=authors[0] if authors else None, license=license, python=python, dependencies=requirements, dev_dependencies=dev_requirements, ) content = layout_.generate_poetry_content() if self.input.is_interactive(): self.line("<info>Generated file</info>") self.line(["", content, ""]) if not self.confirm("Do you confirm generation?", True): self.line("<error>Command aborted</error>") return 1 with (Path.cwd() / "pyproject.toml").open("w") as f: f.write(content)
def handle(self): from poetry.layouts import layout from poetry.utils._compat import Path from poetry.vcs.git import GitConfig if (Path.cwd() / 'pyproject.toml').exists(): self.error('A pyproject.toml file already exists.') return 1 vcs_config = GitConfig() self.line([ '', 'This command will guide you through creating your <info>poetry.toml</> config.', '' ]) name = self.option('name') if not name: name = Path.cwd().name.lower() question = self.create_question( 'Package name [<comment>{}</comment>]: '.format(name), default=name ) name = self.ask(question) version = '0.1.0' question = self.create_question( 'Version [<comment>{}</comment>]: '.format(version), default=version ) version = self.ask(question) description = self.option('description') or '' question = self.create_question( 'Description [<comment>{}</comment>]: '.format(description), default=description ) description = self.ask(question) author = self.option('author') if not author and vcs_config and vcs_config.get('user.name'): author = vcs_config['user.name'] author_email = vcs_config.get('user.email') if author_email: author += ' <{}>'.format(author_email) question = self.create_question( 'Author [<comment>{}</comment>, n to skip]: '.format(author), default=author ) question.validator = lambda v: self._validate_author(v, author) author = self.ask(question) if not author: authors = [] else: authors = [author] license = self.option('license') or '' question = self.create_question( 'License [<comment>{}</comment>]: '.format(license), default=license ) license = self.ask(question) question = self.create_question( 'Compatible Python versions [*]: ', default='*' ) python = self.ask(question) self.line('') requirements = [] question = 'Would you like to define your dependencies' \ ' (require) interactively?' if self.confirm(question, True): requirements = self._format_requirements( self._determine_requirements(self.option('dependency')) ) dev_requirements = [] question = 'Would you like to define your dev dependencies' \ ' (require-dev) interactively' if self.confirm(question, True): dev_requirements = self._format_requirements( self._determine_requirements(self.option('dev-dependency')) ) layout_ = layout('standard')( name, version, description=description, author=authors[0] if authors else None, license=license, python=python, dependencies=requirements, dev_dependencies=dev_requirements ) content = layout_.generate_poetry_content() if self.input.is_interactive(): self.line('<info>Generated file</info>') self.line(['', content, '']) if not self.confirm('Do you confirm generation?', True): self.line('<error>Command aborted</error>') return 1 with (Path.cwd() / 'pyproject.toml').open('w') as f: f.write(content)