From 8bb0c63099e4d2362ff8f03bc86b486525e9dfc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:04:34 +0100 Subject: [PATCH] add support for PEP 621: poetry init and poetry new (#9135) --- src/poetry/console/commands/init.py | 6 +- src/poetry/layouts/layout.py | 66 ++++-- tests/console/commands/conftest.py | 14 +- tests/console/commands/test_init.py | 331 ++++++++++++++++------------ tests/console/commands/test_new.py | 9 +- 5 files changed, 252 insertions(+), 174 deletions(-) diff --git a/src/poetry/console/commands/init.py b/src/poetry/console/commands/init.py index 6725008daaf..595b53fc232 100644 --- a/src/poetry/console/commands/init.py +++ b/src/poetry/console/commands/init.py @@ -105,8 +105,8 @@ def _init_pyproject( if pyproject.file.exists(): if pyproject.is_poetry_project(): self.line_error( - "A pyproject.toml file with a poetry section already" - " exists." + "A pyproject.toml file with a project and/or" + " a poetry section already exists." ) return 1 @@ -255,7 +255,7 @@ def _init_pyproject( if create_layout: layout_.create(project_path, with_pyproject=False) - content = layout_.generate_poetry_content() + content = layout_.generate_project_content() for section, item in content.items(): pyproject.data.append(section, item) diff --git a/src/poetry/layouts/layout.py b/src/poetry/layouts/layout.py index f5174ba3951..1fbd897f4a8 100644 --- a/src/poetry/layouts/layout.py +++ b/src/poetry/layouts/layout.py @@ -5,12 +5,14 @@ from typing import Any from packaging.utils import canonicalize_name +from poetry.core.packages.package import AUTHOR_REGEX from poetry.core.utils.helpers import module_name from tomlkit import inline_table from tomlkit import loads from tomlkit import table from tomlkit.toml_document import TOMLDocument +from poetry.factory import Factory from poetry.pyproject.toml import PyProjectTOML @@ -21,16 +23,20 @@ POETRY_DEFAULT = """\ -[tool.poetry] +[project] name = "" version = "" description = "" -authors = [] -license = "" +authors = [ +] +license = {} readme = "" -packages = [] +requires-python = "" +dependencies = [ +] -[tool.poetry.dependencies] +[tool.poetry] +packages = [] [tool.poetry.group.dev.dependencies] """ @@ -48,7 +54,7 @@ def __init__( readme_format: str = "md", author: str | None = None, license: str | None = None, - python: str = "*", + python: str | None = None, dependencies: Mapping[str, str | Mapping[str, Any]] | None = None, dev_dependencies: Mapping[str, str | Mapping[str, Any]] | None = None, ) -> None: @@ -117,34 +123,49 @@ def create( if with_pyproject: self._write_poetry(path) - def generate_poetry_content(self) -> TOMLDocument: + def generate_project_content(self) -> TOMLDocument: template = POETRY_DEFAULT content: dict[str, Any] = loads(template) - poetry_content = content["tool"]["poetry"] - poetry_content["name"] = self._project - poetry_content["version"] = self._version - poetry_content["description"] = self._description - poetry_content["authors"].append(self._author) + project_content = content["project"] + project_content["name"] = self._project + project_content["version"] = self._version + project_content["description"] = self._description + m = AUTHOR_REGEX.match(self._author) + if m is None: + # This should not happen because author has been validated before. + raise ValueError(f"Invalid author: {self._author}") + else: + author = {"name": m.group("name")} + if email := m.group("email"): + author["email"] = email + project_content["authors"].append(author) if self._license: - poetry_content["license"] = self._license + project_content["license"]["text"] = self._license + else: + project_content.remove("license") + + project_content["readme"] = f"README.{self._readme_format}" + + if self._python: + project_content["requires-python"] = self._python else: - poetry_content.remove("license") + project_content.remove("requires-python") + + for dep_name, dep_constraint in self._dependencies.items(): + dependency = Factory.create_dependency(dep_name, dep_constraint) + project_content["dependencies"].append(dependency.to_pep_508()) + + poetry_content = content["tool"]["poetry"] - poetry_content["readme"] = f"README.{self._readme_format}" packages = self.get_package_include() if packages: poetry_content["packages"].append(packages) else: poetry_content.remove("packages") - poetry_content["dependencies"]["python"] = self._python - - for dep_name, dep_constraint in self._dependencies.items(): - poetry_content["dependencies"][dep_name] = dep_constraint - if self._dev_dependencies: for dep_name, dep_constraint in self._dev_dependencies.items(): poetry_content["group"]["dev"]["dependencies"][dep_name] = ( @@ -153,6 +174,9 @@ def generate_poetry_content(self) -> TOMLDocument: else: del poetry_content["group"] + if not poetry_content: + del content["tool"]["poetry"] + # Add build system build_system = table() build_system_version = "" @@ -194,7 +218,7 @@ def _create_tests(path: Path) -> None: def _write_poetry(self, path: Path) -> None: pyproject = PyProjectTOML(path / "pyproject.toml") - content = self.generate_poetry_content() + content = self.generate_project_content() for section, item in content.items(): pyproject.data.append(section, item) pyproject.save() diff --git a/tests/console/commands/conftest.py b/tests/console/commands/conftest.py index 8c095a6bb81..b96f5a07e8b 100644 --- a/tests/console/commands/conftest.py +++ b/tests/console/commands/conftest.py @@ -12,7 +12,7 @@ def init_basic_inputs() -> str: "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "n", # Interactive packages "n", # Interactive dev packages "\n", # Generate @@ -23,14 +23,14 @@ def init_basic_inputs() -> str: @pytest.fixture() def init_basic_toml() -> str: return """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {name = "Your Name",email = "you@example.com"} +] +license = {text = "MIT"} readme = "README.md" - -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" +requires-python = ">=3.6" """ diff --git a/tests/console/commands/test_init.py b/tests/console/commands/test_init.py index 80aee46e048..ec85d321f59 100644 --- a/tests/console/commands/test_init.py +++ b/tests/console/commands/test_init.py @@ -93,7 +93,7 @@ def test_noninteractive( toml_content = (tmp_path / "pyproject.toml").read_text(encoding="utf-8") assert 'name = "my-package"' in toml_content - assert 'pytest = "^3.6.0"' in toml_content + assert '"pytest (>=3.6.0,<4.0.0)"' in toml_content def test_interactive_with_dependencies( @@ -110,7 +110,7 @@ def test_interactive_with_dependencies( "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "", # Interactive packages "pendulu", # Search for package "1", # Second option is pendulum @@ -129,18 +129,22 @@ def test_interactive_with_dependencies( tester.execute(inputs="\n".join(inputs)) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {name = "Your Name",email = "you@example.com"} +] +license = {text = "MIT"} readme = "README.md" +requires-python = ">=3.6" +dependencies = [ + "pendulum (>=2.0.0,<3.0.0)", + "flask (>=2.0.0,<3.0.0)" +] -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" -pendulum = "^2.0.0" -flask = "^2.0.0" +[tool.poetry] [tool.poetry.group.dev.dependencies] pytest = "^3.6.0" @@ -163,7 +167,7 @@ def test_interactive_with_dependencies_and_no_selection( "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "", # Interactive packages "pendulu", # Search for package "", # Do not select an option @@ -177,16 +181,16 @@ def test_interactive_with_dependencies_and_no_selection( ] tester.execute(inputs="\n".join(inputs)) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {name = "Your Name",email = "you@example.com"} +] +license = {text = "MIT"} readme = "README.md" - -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" +requires-python = ">=3.6" """ assert expected in tester.io.fetch_output() @@ -208,15 +212,15 @@ def test_empty_license(tester: CommandTester) -> None: python = ".".join(str(c) for c in sys.version_info[:2]) expected = f"""\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "" -authors = ["Your Name "] +authors = [ + {{name = "Your Name",email = "you@example.com"}} +] readme = "README.md" - -[tool.poetry.dependencies] -python = ">={python}" +requires-python = ">={python}" """ assert expected in tester.io.fetch_output() @@ -233,7 +237,7 @@ def test_interactive_with_git_dependencies( "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "", # Interactive packages "git+https://github.com/demo/demo.git", # Search for package "", # Stop searching for packages @@ -247,17 +251,21 @@ def test_interactive_with_git_dependencies( tester.execute(inputs="\n".join(inputs)) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {name = "Your Name",email = "you@example.com"} +] +license = {text = "MIT"} readme = "README.md" +requires-python = ">=3.6" +dependencies = [ + "demo @ git+https://github.com/demo/demo.git" +] -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" -demo = {git = "https://github.com/demo/demo.git"} +[tool.poetry] [tool.poetry.group.dev.dependencies] pytest = "^3.6.0" @@ -325,7 +333,7 @@ def test_interactive_with_git_dependencies_with_reference( "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "", # Interactive packages "git+https://github.com/demo/demo.git@develop", # Search for package "", # Stop searching for packages @@ -339,17 +347,21 @@ def test_interactive_with_git_dependencies_with_reference( tester.execute(inputs="\n".join(inputs)) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {name = "Your Name",email = "you@example.com"} +] +license = {text = "MIT"} readme = "README.md" +requires-python = ">=3.6" +dependencies = [ + "demo @ git+https://github.com/demo/demo.git@develop" +] -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" -demo = {git = "https://github.com/demo/demo.git", rev = "develop"} +[tool.poetry] [tool.poetry.group.dev.dependencies] pytest = "^3.6.0" @@ -370,7 +382,7 @@ def test_interactive_with_git_dependencies_and_other_name( "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "", # Interactive packages "git+https://github.com/demo/pyproject-demo.git", # Search for package "", # Stop searching for packages @@ -384,17 +396,21 @@ def test_interactive_with_git_dependencies_and_other_name( tester.execute(inputs="\n".join(inputs)) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {name = "Your Name",email = "you@example.com"} +] +license = {text = "MIT"} readme = "README.md" +requires-python = ">=3.6" +dependencies = [ + "demo @ git+https://github.com/demo/pyproject-demo.git" +] -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" -demo = {git = "https://github.com/demo/pyproject-demo.git"} +[tool.poetry] [tool.poetry.group.dev.dependencies] pytest = "^3.6.0" @@ -421,7 +437,7 @@ def test_interactive_with_directory_dependency( "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "", # Interactive packages "./demo", # Search for package "", # Stop searching for packages @@ -434,18 +450,23 @@ def test_interactive_with_directory_dependency( ] tester.execute(inputs="\n".join(inputs)) - expected = """\ -[tool.poetry] + demo_uri = (Path.cwd() / "demo").as_uri() + expected = f"""\ +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {{name = "Your Name",email = "you@example.com"}} +] +license = {{text = "MIT"}} readme = "README.md" +requires-python = ">=3.6" +dependencies = [ + "demo @ {demo_uri}" +] -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" -demo = {path = "demo"} +[tool.poetry] [tool.poetry.group.dev.dependencies] pytest = "^3.6.0" @@ -471,7 +492,7 @@ def test_interactive_with_directory_dependency_and_other_name( "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "", # Interactive packages "./pyproject-demo", # Search for package "", # Stop searching for packages @@ -484,18 +505,23 @@ def test_interactive_with_directory_dependency_and_other_name( ] tester.execute(inputs="\n".join(inputs)) - expected = """\ -[tool.poetry] + demo_uri = (Path.cwd() / "pyproject-demo").as_uri() + expected = f"""\ +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {{name = "Your Name",email = "you@example.com"}} +] +license = {{text = "MIT"}} readme = "README.md" +requires-python = ">=3.6" +dependencies = [ + "demo @ {demo_uri}" +] -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" -demo = {path = "pyproject-demo"} +[tool.poetry] [tool.poetry.group.dev.dependencies] pytest = "^3.6.0" @@ -522,7 +548,7 @@ def test_interactive_with_file_dependency( "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "", # Interactive packages "./demo-0.1.0-py2.py3-none-any.whl", # Search for package "", # Stop searching for packages @@ -535,18 +561,23 @@ def test_interactive_with_file_dependency( ] tester.execute(inputs="\n".join(inputs)) - expected = """\ -[tool.poetry] + demo_uri = (Path.cwd() / "demo-0.1.0-py2.py3-none-any.whl").as_uri() + expected = f"""\ +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {{name = "Your Name",email = "you@example.com"}} +] +license = {{text = "MIT"}} readme = "README.md" +requires-python = ">=3.6" +dependencies = [ + "demo @ {demo_uri}" +] -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" -demo = {path = "demo-0.1.0-py2.py3-none-any.whl"} +[tool.poetry] [tool.poetry.group.dev.dependencies] pytest = "^3.6.0" @@ -564,7 +595,7 @@ def test_interactive_with_wrong_dependency_inputs( "This is a description", # Description "n", # Author "MIT", # License - "^3.8", # Python + ">=3.8", # Python "", # Interactive packages "foo 1.19.2", "pendulum 2.0.0 foo", # Package name and constraint (invalid) @@ -580,18 +611,22 @@ def test_interactive_with_wrong_dependency_inputs( tester.execute(inputs="\n".join(inputs)) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {name = "Your Name",email = "you@example.com"} +] +license = {text = "MIT"} readme = "README.md" +requires-python = ">=3.8" +dependencies = [ + "foo (==1.19.2)", + "pendulum (>=2.0.0,<3.0.0)" +] -[tool.poetry.dependencies] -python = "^3.8" -foo = "1.19.2" -pendulum = "^2.0.0" +[tool.poetry] [tool.poetry.group.dev.dependencies] pytest = "3.6.0" @@ -611,19 +646,19 @@ def test_python_option(tester: CommandTester) -> None: "n", # Interactive dev packages "\n", # Generate ] - tester.execute("--python '~2.7 || ^3.6'", inputs="\n".join(inputs)) + tester.execute("--python '>=3.6'", inputs="\n".join(inputs)) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {name = "Your Name",email = "you@example.com"} +] +license = {text = "MIT"} readme = "README.md" - -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" +requires-python = ">=3.6" """ assert expected in tester.io.fetch_output() @@ -638,7 +673,7 @@ def test_predefined_dependency(tester: CommandTester, repo: TestRepository) -> N "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "n", # Interactive packages "n", # Interactive dev packages "\n", # Generate @@ -646,17 +681,19 @@ def test_predefined_dependency(tester: CommandTester, repo: TestRepository) -> N tester.execute("--dependency pendulum", inputs="\n".join(inputs)) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {name = "Your Name",email = "you@example.com"} +] +license = {text = "MIT"} readme = "README.md" - -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" -pendulum = "^2.0.0" +requires-python = ">=3.6" +dependencies = [ + "pendulum (>=2.0.0,<3.0.0)" +] """ assert expected in tester.io.fetch_output() @@ -674,7 +711,7 @@ def test_predefined_and_interactive_dependencies( "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "", # Interactive packages "pyramid", # Search for package "0", # First option @@ -687,21 +724,22 @@ def test_predefined_and_interactive_dependencies( tester.execute("--dependency pendulum", inputs="\n".join(inputs)) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {name = "Your Name",email = "you@example.com"} +] +license = {text = "MIT"} readme = "README.md" - -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" +requires-python = ">=3.6" +dependencies = [ + "pendulum (>=2.0.0,<3.0.0)", + "pyramid (>=1.10,<2.0)" +] """ - output = tester.io.fetch_output() - assert expected in output - assert 'pendulum = "^2.0.0"' in output - assert 'pyramid = "^1.10"' in output + assert expected in tester.io.fetch_output() def test_predefined_dev_dependency(tester: CommandTester, repo: TestRepository) -> None: @@ -713,7 +751,7 @@ def test_predefined_dev_dependency(tester: CommandTester, repo: TestRepository) "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "n", # Interactive packages "n", # Interactive dev packages "\n", # Generate @@ -722,16 +760,20 @@ def test_predefined_dev_dependency(tester: CommandTester, repo: TestRepository) tester.execute("--dev-dependency pytest", inputs="\n".join(inputs)) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {name = "Your Name",email = "you@example.com"} +] +license = {text = "MIT"} readme = "README.md" +requires-python = ">=3.6" +dependencies = [ +] -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" +[tool.poetry] [tool.poetry.group.dev.dependencies] pytest = "^3.6.0" @@ -752,7 +794,7 @@ def test_predefined_and_interactive_dev_dependencies( "This is a description", # Description "n", # Author "MIT", # License - "~2.7 || ^3.6", # Python + ">=3.6", # Python "n", # Interactive packages "", # Interactive dev packages "pytest-requests", # Search for package @@ -765,16 +807,20 @@ def test_predefined_and_interactive_dev_dependencies( tester.execute("--dev-dependency pytest", inputs="\n".join(inputs)) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Your Name "] -license = "MIT" +authors = [ + {name = "Your Name",email = "you@example.com"} +] +license = {text = "MIT"} readme = "README.md" +requires-python = ">=3.6" +dependencies = [ +] -[tool.poetry.dependencies] -python = "~2.7 || ^3.6" +[tool.poetry] [tool.poetry.group.dev.dependencies] pytest = "^3.6.0" @@ -803,7 +849,7 @@ def test_predefined_all_options(tester: CommandTester, repo: TestRepository) -> "--name my-package " "--description 'This is a description' " "--author 'Foo Bar ' " - "--python '^3.8' " + "--python '>=3.8' " "--license MIT " "--dependency pendulum " "--dev-dependency pytest", @@ -811,17 +857,21 @@ def test_predefined_all_options(tester: CommandTester, repo: TestRepository) -> ) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "1.2.3" description = "This is a description" -authors = ["Foo Bar "] -license = "MIT" +authors = [ + {name = "Foo Bar",email = "foo@example.com"} +] +license = {text = "MIT"} readme = "README.md" +requires-python = ">=3.8" +dependencies = [ + "pendulum (>=2.0.0,<3.0.0)" +] -[tool.poetry.dependencies] -python = "^3.8" -pendulum = "^2.0.0" +[tool.poetry] [tool.poetry.group.dev.dependencies] pytest = "^3.6.0" @@ -900,22 +950,24 @@ def test_init_non_interactive_existing_pyproject_add_dependency( tester.execute( "--author 'Your Name ' " "--name 'my-package' " - "--python '^3.6' " + "--python '>=3.6' " "--dependency foo", interactive=False, ) expected = """\ -[tool.poetry] +[project] name = "my-package" version = "0.1.0" description = "" -authors = ["Your Name "] +authors = [ + {name = "Your Name",email = "you@example.com"} +] readme = "README.md" - -[tool.poetry.dependencies] -python = "^3.6" -foo = "^1.19.2" +requires-python = ">=3.6" +dependencies = [ + "foo (>=1.19.2,<2.0.0)" +] """ assert f"{existing_section}\n{expected}" in pyproject_file.read_text( encoding="utf-8" @@ -1005,7 +1057,7 @@ def test_package_include( "", # Description "poetry", # Author "", # License - "^3.10", # Python + ">=3.10", # Python "n", # Interactive packages "n", # Interactive dev packages "\n", # Generate @@ -1015,19 +1067,21 @@ def test_package_include( packages = "" if include and module_name(package_name) != include: - packages = f'packages = [{{include = "{include}"}}]\n' + packages = f'\n[tool.poetry]\npackages = [{{include = "{include}"}}]\n' expected = ( - f"[tool.poetry]\n" + "[project]\n" f'name = "{package_name.replace(".", "-")}"\n' # canonicalized - f'version = "0.1.0"\n' - f'description = ""\n' - f'authors = ["poetry"]\n' - f'readme = "README.md"\n' - f"{packages}" # This line is optional. Thus no newline here. - f"\n" - f"[tool.poetry.dependencies]\n" - f'python = "^3.10"\n' + 'version = "0.1.0"\n' + 'description = ""\n' + 'authors = [\n' + ' {name = "poetry"}\n' + ']\n' + 'readme = "README.md"\n' + 'requires-python = ">=3.10"\n' + 'dependencies = [\n' + ']\n' + f"{packages}" # This line is optional. Thus, no newline here. ) assert expected in tester.io.fetch_output() @@ -1069,8 +1123,7 @@ def mock_check_output(cmd: str, *_: Any, **__: Any) -> str: ) expected = f"""\ -[tool.poetry.dependencies] -python = ">={python}" +requires-python = ">={python}" """ assert expected in pyproject_file.read_text(encoding="utf-8") diff --git a/tests/console/commands/test_new.py b/tests/console/commands/test_new.py index dba738f4e8c..72cb5654a66 100644 --- a/tests/console/commands/test_new.py +++ b/tests/console/commands/test_new.py @@ -57,7 +57,7 @@ def verify_project_directory( else: package_include = {"include": package_path.parts[0]} - name = poetry.local_config.get("name", "") + name = poetry.package.name packages = poetry.local_config.get("packages") if not packages: @@ -183,7 +183,9 @@ def test_command_new_with_readme( tester.execute(" ".join(options)) poetry = verify_project_directory(path, package, package, None) - assert poetry.local_config.get("readme") == f"README.{fmt or 'md'}" + project_section = poetry.pyproject.data["project"] + assert isinstance(project_section, dict) + assert project_section["readme"] == f"README.{fmt or 'md'}" @pytest.mark.parametrize( @@ -224,8 +226,7 @@ def mock_check_output(cmd: str, *_: Any, **__: Any) -> str: pyproject_file = path / "pyproject.toml" expected = f"""\ -[tool.poetry.dependencies] -python = ">={python}" +requires-python = ">={python}" """ assert expected in pyproject_file.read_text(encoding="utf-8")