Skip to content

Commit cbb81f1

Browse files
committed
fix: make relative working directory absolute
1 parent d1211c0 commit cbb81f1

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/poetry/console/application.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ def _default_definition(self) -> Definition:
189189
def project_directory(self) -> Path:
190190
return self._project_directory or self._working_directory
191191

192+
@property
193+
def working_directory(self) -> Path:
194+
return self._working_directory
195+
192196
@property
193197
def poetry(self) -> Poetry:
194198
from poetry.factory import Factory
@@ -339,7 +343,7 @@ def _configure_global_options(self, io: IO) -> None:
339343
# this will raise an exception if the path is invalid
340344
self._working_directory = ensure_path(
341345
io.input.option("directory") or Path.cwd(), is_directory=True
342-
)
346+
).resolve()
343347

344348
self._project_directory = io.input.option("project")
345349
if self._project_directory is not None:

tests/console/test_application_global_options.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ def with_mocked_version_command(mocker: MockerFixture) -> None:
9494

9595
def mock_handle(command: VersionCommand) -> int:
9696
exit_code = orig_version_command(command)
97+
application = command.application
98+
assert isinstance(application, Application)
9799

98100
command.io.write_line(f"ProjectPath: {command.poetry.pyproject_path.parent}")
99-
command.io.write_line(f"WorkingDirectory: {Path.cwd()}")
101+
command.io.write_line(f"WorkingDirectory: {application.working_directory}")
100102

101103
return exit_code
102104

@@ -226,6 +228,28 @@ def test_application_with_relative_project_parameter(
226228
""")
227229

228230

231+
def test_application_with_relative_directory_parameter(
232+
tester: ApplicationTester,
233+
project_source_directory: Path,
234+
relative_project_source_directory: Path,
235+
with_mocked_version_command: None,
236+
) -> None:
237+
args = f"--directory '{relative_project_source_directory}' version"
238+
239+
tester.execute(args)
240+
assert tester.io.fetch_error() == ""
241+
assert tester.status_code == 0
242+
243+
output = tester.io.fetch_output()
244+
245+
# relative directory parameter results in absolute path for working directory
246+
assert output == textwrap.dedent(f"""\
247+
foobar 0.1.0
248+
ProjectPath: {project_source_directory}
249+
WorkingDirectory: {project_source_directory}
250+
""")
251+
252+
229253
def test_application_with_relative_directory_parameter_and_early_poetry_access_plugin(
230254
tester: ApplicationTester,
231255
with_early_poetry_access_plugin: None,

0 commit comments

Comments
 (0)