Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
26 changes: 25 additions & 1 deletion tests/console/test_application_global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down