Skip to content

Commit 262017f

Browse files
authored
Make poetry plugin work with the --directory option on the poetry cli (#211)
1 parent 7fecb34 commit 262017f

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

poethepoet/plugin.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def get_poe(cls, application: Application, io: IO):
5656
except: # noqa: E722
5757
poetry_env_path = None
5858

59-
cwd = Path().resolve()
59+
# Get the cwd from poetry to ensure '--directory subdir' usage
60+
try:
61+
cwd = application.poetry.pyproject_path
62+
except AttributeError:
63+
cwd = Path().resolve()
6064
config = PoeConfig(cwd=cwd)
6165

6266
if io.output.is_quiet():

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def run_poetry(args: List[str], cwd: str, env: Optional[Dict[str, str]] = None):
254254
venv_location,
255255
[
256256
".[poetry_plugin]",
257-
"./tests/fixtures/packages/poetry-1.2.1-py3-none-any.whl",
257+
"./tests/fixtures/packages/poetry-1.8.2-py3-none-any.whl",
258258
],
259259
require_empty=True,
260260
):
Binary file not shown.
Binary file not shown.

tests/test_poetry_plugin.py

+37
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,40 @@ def test_running_poetry_command_with_hooks(run_poetry, projects):
134134
assert "THIS IS YOUR ENV!" in result.stdout
135135
assert "THAT WAS YOUR ENV!" in result.stdout
136136
# assert result.stderr == ""
137+
138+
139+
@pytest.mark.slow()
140+
@pytest.mark.usefixtures("_setup_poetry_project")
141+
def test_running_poetry_command_with_hooks_with_directory(run_poetry, projects):
142+
result = run_poetry(
143+
["--directory=" + str(projects["poetry_plugin"]), "env", "info"],
144+
cwd=projects["poetry_plugin"].parent,
145+
)
146+
assert "THIS IS YOUR ENV!" in result.stdout
147+
assert "THAT WAS YOUR ENV!" in result.stdout
148+
# assert result.stderr == ""
149+
150+
151+
@pytest.mark.slow()
152+
@pytest.mark.usefixtures("_setup_poetry_project")
153+
def test_task_with_cli_dependency_with_directory(run_poetry, projects, is_windows):
154+
result = run_poetry(
155+
[
156+
"--directory=" + str(projects["poetry_plugin"]),
157+
"poe",
158+
"cow-greet",
159+
"yo yo yo",
160+
],
161+
cwd=projects["poetry_plugin"].parent,
162+
)
163+
if is_windows:
164+
assert result.stdout.startswith("Poe => cowpy 'yo yo yo'")
165+
assert "< yo yo yo >" in result.stdout
166+
else:
167+
# On POSIX cowpy expects notices its being called as a subprocess and tries
168+
# unproductively to take input from stdin
169+
assert result.stdout.startswith("Poe => cowpy 'yo yo yo'")
170+
assert (
171+
"< Cowacter, eyes:default, tongue:False, thoughts:False >" in result.stdout
172+
)
173+
# assert result.stderr == ""

0 commit comments

Comments
 (0)