-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat(cli): default new command to src layout #10135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,24 @@ def init_basic_toml() -> str: | |
readme = "README.md" | ||
requires-python = ">=3.6" | ||
""" | ||
|
||
|
||
@pytest.fixture() | ||
def new_basic_toml() -> str: | ||
return """\ | ||
[project] | ||
name = "my-package" | ||
version = "1.2.3" | ||
description = "This is a description" | ||
authors = [ | ||
{name = "Your Name",email = "[email protected]"} | ||
] | ||
license = {text = "MIT"} | ||
readme = "README.md" | ||
requires-python = ">=3.6" | ||
dependencies = [ | ||
] | ||
|
||
[tool.poetry] | ||
packages = [{include = "my_package", from = "src"}] | ||
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ def verify_project_directory( | |
path: Path, | ||
package_name: str, | ||
package_path: str | Path, | ||
include_from: str | None = None, | ||
is_flat: bool = False, | ||
) -> Poetry: | ||
package_path = Path(package_path) | ||
assert path.is_dir() | ||
|
@@ -49,13 +49,13 @@ def verify_project_directory( | |
poetry = Factory().create_poetry(cwd=path) | ||
assert poetry.package.name == package_name | ||
|
||
if include_from: | ||
if is_flat: | ||
package_include = {"include": package_path.parts[0]} | ||
else: | ||
package_include = { | ||
"include": package_path.relative_to(include_from).parts[0], | ||
"from": include_from, | ||
"include": package_path.relative_to("src").parts[0], | ||
"from": "src", | ||
} | ||
else: | ||
package_include = {"include": package_path.parts[0]} | ||
|
||
name = poetry.package.name | ||
packages = poetry.local_config.get("packages") | ||
|
@@ -72,81 +72,87 @@ def verify_project_directory( | |
@pytest.mark.parametrize( | ||
"options,directory,package_name,package_path,include_from", | ||
[ | ||
([], "package", "package", "package", None), | ||
(["--src"], "package", "package", "src/package", "src"), | ||
(["--flat"], "package", "package", "package", None), | ||
([], "package", "package", "src/package", "src"), | ||
( | ||
["--name namespace.package"], | ||
["--flat", "--name namespace.package"], | ||
"namespace-package", | ||
"namespace-package", | ||
"namespace/package", | ||
None, | ||
), | ||
( | ||
["--src", "--name namespace.package"], | ||
["--name namespace.package"], | ||
"namespace-package", | ||
"namespace-package", | ||
"src/namespace/package", | ||
"src", | ||
), | ||
( | ||
["--name namespace.package_a"], | ||
["--flat", "--name namespace.package_a"], | ||
"namespace-package_a", | ||
"namespace-package-a", | ||
"namespace/package_a", | ||
None, | ||
), | ||
( | ||
["--src", "--name namespace.package_a"], | ||
["--name namespace.package_a"], | ||
"namespace-package_a", | ||
"namespace-package-a", | ||
"src/namespace/package_a", | ||
"src", | ||
), | ||
( | ||
["--name namespace_package"], | ||
["--flat", "--name namespace_package"], | ||
"namespace-package", | ||
"namespace-package", | ||
"namespace_package", | ||
None, | ||
), | ||
( | ||
["--name namespace_package", "--src"], | ||
["--name namespace_package"], | ||
"namespace-package", | ||
"namespace-package", | ||
"src/namespace_package", | ||
"src", | ||
), | ||
( | ||
["--name namespace.package"], | ||
["--flat", "--name namespace.package"], | ||
"package", | ||
"namespace-package", | ||
"namespace/package", | ||
None, | ||
), | ||
( | ||
["--name namespace.package", "--src"], | ||
["--name namespace.package"], | ||
"package", | ||
"namespace-package", | ||
"src/namespace/package", | ||
"src", | ||
), | ||
( | ||
["--name namespace.package"], | ||
["--name namespace.package", "--flat"], | ||
"package", | ||
"namespace-package", | ||
"namespace/package", | ||
None, | ||
), | ||
( | ||
["--name namespace.package", "--src"], | ||
["--name namespace.package"], | ||
"package", | ||
"namespace-package", | ||
"src/namespace/package", | ||
"src", | ||
), | ||
([], "namespace_package", "namespace-package", "namespace_package", None), | ||
( | ||
["--src", "--name namespace_package"], | ||
["--flat"], | ||
"namespace_package", | ||
"namespace-package", | ||
"namespace_package", | ||
None, | ||
), | ||
( | ||
["--name namespace_package"], | ||
"namespace_package", | ||
"namespace-package", | ||
"src/namespace_package", | ||
|
@@ -166,7 +172,7 @@ def test_command_new( | |
path = tmp_path / directory | ||
options.append(str(path)) | ||
tester.execute(" ".join(options)) | ||
verify_project_directory(path, package_name, package_path, include_from) | ||
verify_project_directory(path, package_name, package_path, "--flat" in options) | ||
|
||
|
||
@pytest.mark.parametrize(("fmt",), [(None,), ("md",), ("rst",), ("adoc",), ("creole",)]) | ||
|
@@ -182,7 +188,7 @@ def test_command_new_with_readme( | |
|
||
tester.execute(" ".join(options)) | ||
|
||
poetry = verify_project_directory(path, package, package, None) | ||
poetry = verify_project_directory(path, package, Path("src") / package) | ||
project_section = poetry.pyproject.data["project"] | ||
assert isinstance(project_section, dict) | ||
assert project_section["readme"] == f"README.{fmt or 'md'}" | ||
|
@@ -222,9 +228,9 @@ def test_respect_use_poetry_python_on_new( | |
|
||
|
||
def test_basic_interactive_new( | ||
tester: CommandTester, tmp_path: Path, init_basic_inputs: str, init_basic_toml: str | ||
tester: CommandTester, tmp_path: Path, init_basic_inputs: str, new_basic_toml: str | ||
) -> None: | ||
path = tmp_path / "somepackage" | ||
tester.execute(f"--interactive {path.as_posix()}", inputs=init_basic_inputs) | ||
verify_project_directory(path, "my-package", "my_package", None) | ||
assert init_basic_toml in tester.io.fetch_output() | ||
verify_project_directory(path, "my-package", "src/my_package") | ||
assert new_basic_toml in tester.io.fetch_output() | ||
Comment on lines
+235
to
+236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Test interactive mode with --flat. Add a new test case for interactive mode with the |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.