Skip to content

Commit

Permalink
Make poetry plugin work with the --directory option on the poetry cli (
Browse files Browse the repository at this point in the history
  • Loading branch information
worldworm committed Apr 13, 2024
1 parent 7fecb34 commit 262017f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
6 changes: 5 additions & 1 deletion poethepoet/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ def get_poe(cls, application: Application, io: IO):
except: # noqa: E722
poetry_env_path = None

cwd = Path().resolve()
# Get the cwd from poetry to ensure '--directory subdir' usage
try:
cwd = application.poetry.pyproject_path
except AttributeError:
cwd = Path().resolve()
config = PoeConfig(cwd=cwd)

if io.output.is_quiet():
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def run_poetry(args: List[str], cwd: str, env: Optional[Dict[str, str]] = None):
venv_location,
[
".[poetry_plugin]",
"./tests/fixtures/packages/poetry-1.2.1-py3-none-any.whl",
"./tests/fixtures/packages/poetry-1.8.2-py3-none-any.whl",
],
require_empty=True,
):
Expand Down
Binary file not shown.
Binary file not shown.
37 changes: 37 additions & 0 deletions tests/test_poetry_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,40 @@ def test_running_poetry_command_with_hooks(run_poetry, projects):
assert "THIS IS YOUR ENV!" in result.stdout
assert "THAT WAS YOUR ENV!" in result.stdout
# assert result.stderr == ""


@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project")
def test_running_poetry_command_with_hooks_with_directory(run_poetry, projects):
result = run_poetry(
["--directory=" + str(projects["poetry_plugin"]), "env", "info"],
cwd=projects["poetry_plugin"].parent,
)
assert "THIS IS YOUR ENV!" in result.stdout
assert "THAT WAS YOUR ENV!" in result.stdout
# assert result.stderr == ""


@pytest.mark.slow()
@pytest.mark.usefixtures("_setup_poetry_project")
def test_task_with_cli_dependency_with_directory(run_poetry, projects, is_windows):
result = run_poetry(
[
"--directory=" + str(projects["poetry_plugin"]),
"poe",
"cow-greet",
"yo yo yo",
],
cwd=projects["poetry_plugin"].parent,
)
if is_windows:
assert result.stdout.startswith("Poe => cowpy 'yo yo yo'")
assert "< yo yo yo >" in result.stdout
else:
# On POSIX cowpy expects notices its being called as a subprocess and tries
# unproductively to take input from stdin
assert result.stdout.startswith("Poe => cowpy 'yo yo yo'")
assert (
"< Cowacter, eyes:default, tongue:False, thoughts:False >" in result.stdout
)
# assert result.stderr == ""

0 comments on commit 262017f

Please sign in to comment.