diff --git a/src/poetry/console/application.py b/src/poetry/console/application.py index 843279c8bd3..f950511c662 100644 --- a/src/poetry/console/application.py +++ b/src/poetry/console/application.py @@ -189,6 +189,10 @@ def _default_definition(self) -> Definition: def project_directory(self) -> Path: return self._project_directory or self._working_directory + @property + def working_directory(self) -> Path: + return self._working_directory + @property def poetry(self) -> Poetry: from poetry.factory import Factory @@ -339,7 +343,7 @@ def _configure_global_options(self, io: IO) -> None: # this will raise an exception if the path is invalid self._working_directory = ensure_path( io.input.option("directory") or Path.cwd(), is_directory=True - ) + ).resolve() self._project_directory = io.input.option("project") if self._project_directory is not None: diff --git a/tests/console/test_application_global_options.py b/tests/console/test_application_global_options.py index c511e8bdfc5..89a6f7c709a 100644 --- a/tests/console/test_application_global_options.py +++ b/tests/console/test_application_global_options.py @@ -94,9 +94,11 @@ def with_mocked_version_command(mocker: MockerFixture) -> None: def mock_handle(command: VersionCommand) -> int: exit_code = orig_version_command(command) + application = command.application + assert isinstance(application, Application) command.io.write_line(f"ProjectPath: {command.poetry.pyproject_path.parent}") - command.io.write_line(f"WorkingDirectory: {Path.cwd()}") + command.io.write_line(f"WorkingDirectory: {application.working_directory}") return exit_code @@ -226,6 +228,28 @@ def test_application_with_relative_project_parameter( """) +def test_application_with_relative_directory_parameter( + tester: ApplicationTester, + project_source_directory: Path, + relative_project_source_directory: Path, + with_mocked_version_command: None, +) -> None: + args = f"--directory '{relative_project_source_directory}' version" + + tester.execute(args) + assert tester.io.fetch_error() == "" + assert tester.status_code == 0 + + output = tester.io.fetch_output() + + # relative directory parameter results in absolute path for working directory + assert output == textwrap.dedent(f"""\ + foobar 0.1.0 + ProjectPath: {project_source_directory} + WorkingDirectory: {project_source_directory} + """) + + def test_application_with_relative_directory_parameter_and_early_poetry_access_plugin( tester: ApplicationTester, with_early_poetry_access_plugin: None,