diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fe7c98b7259..5f449fcffc4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,6 +32,6 @@ repos: - id: validate_manifest - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.9 + rev: v0.1.11 hooks: - id: ruff diff --git a/docs/_index.md b/docs/_index.md index edd356119c3..094e91f7a60 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -28,6 +28,7 @@ Poetry should always be installed in a dedicated virtual environment to isolate It should in no case be installed in the environment of the project that is to be managed by Poetry. This ensures that Poetry's own dependencies will not be accidentally upgraded or uninstalled. (Each of the following installation methods ensures that Poetry is installed into an isolated environment.) +In addition, the isolated virtual environment in which poetry is installed should not be activated for running poetry commands. {{% /warning %}} {{% note %}} diff --git a/docs/basic-usage.md b/docs/basic-usage.md index dd872f4a1c5..b9c0a0d7c41 100644 --- a/docs/basic-usage.md +++ b/docs/basic-usage.md @@ -128,6 +128,19 @@ any Poetry commands that expect to manipulate an environment. To run your script simply use `poetry run python your_script.py`. Likewise if you have command line tools such as `pytest` or `black` you can run them using `poetry run pytest`. +{{% note %}} +If managing your own virtual environment externally, you do not need to use `poetry run` or `poetry shell` since +you will, presumably, already have activated that virtual environment and made available the correct python instance. +For example, these commands should output the same python path: +```shell +conda activate your_env_name +which python +poetry run which python +poetry shell +which python +``` +{{% /note %}} + ### Activating the virtual environment The easiest way to activate the virtual environment is to create a nested shell with `poetry shell`. diff --git a/docs/cli.md b/docs/cli.md index 4ca91f95064..7fb6ca921bc 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -582,6 +582,14 @@ poetry config [options] [setting-key] [setting-value1] ... [setting-valueN] `setting-key` is a configuration option name and `setting-value1` is a configuration value. See [Configuration]({{< relref "configuration" >}}) for all available settings. +{{% warning %}} +Use `--` to terminate option parsing if your values may start with a hyphen (`-`), e.g. +```bash +poetry config http-basic.custom-repo gitlab-ci-token -- ${GITLAB_JOB_TOKEN} +``` +Without `--` this command will fail if `${GITLAB_JOB_TOKEN}` starts with a hyphen. +{{% /warning%}} + ### Options * `--unset`: Remove the configuration element named by `setting-key`. diff --git a/docs/faq.md b/docs/faq.md index 105592ce9bd..a9404955c01 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -83,8 +83,9 @@ If your package will be used as an application, it might be worth to define an u ### Is tox supported? -**Yes**. By using the [isolated builds](https://tox.readthedocs.io/en/latest/config.html#conf-isolated_build) `tox` provides, -you can use it in combination with the PEP 517 compliant build system provided by Poetry. +**Yes**. Provided that you are using `tox` >= 4, you can use it in combination with +the PEP 517 compliant build system provided by Poetry. (With tox 3, you have to set the +[isolated build](https://tox.wiki/en/3.27.1/config.html#conf-isolated_build) option.) So, in your `pyproject.toml` file, add this section if it does not already exist: @@ -97,10 +98,9 @@ build-backend = "poetry.core.masonry.api" `tox` can be configured in multiple ways. It depends on what should be the code under test and which dependencies should be installed. -#### Usecase #1 +#### Use case #1 ```ini [tox] -isolated_build = true [testenv] deps = @@ -112,10 +112,9 @@ commands = `tox` will create an `sdist` package of the project and uses `pip` to install it in a fresh environment. Thus, dependencies are resolved by `pip`. -#### Usecase #2 +#### Use case #2 ```ini [tox] -isolated_build = true [testenv] allowlist_externals = poetry @@ -126,13 +125,12 @@ commands = ``` `tox` will create an `sdist` package of the project and uses `pip` to install it in a fresh environment. -Thus, dependencies are resolved by `pip` in the first place. But afterwards we run Poetry, +Thus, dependencies are resolved by `pip` in the first place. But afterward we run Poetry, which will install the locked dependencies into the environment. -#### Usecase #3 +#### Use case #3 ```ini [tox] -isolated_build = true [testenv] skip_install = true @@ -198,7 +196,7 @@ For example, if Poetry builds a distribution for a project that uses a version t ### Poetry busts my Docker cache because it requires me to COPY my source files in before installing 3rd party dependencies -By default running `poetry install ...` requires you to have your source files present (both the "root" package and any directory path dependencies you might have). +By default, running `poetry install ...` requires you to have your source files present (both the "root" package and any directory path dependencies you might have). This interacts poorly with Docker's caching mechanisms because any change to a source file will make any layers (subsequent commands in your Dockerfile) re-run. For example, you might have a Dockerfile that looks something like this: diff --git a/docs/pyproject.md b/docs/pyproject.md index 0d23d89ff02..aebad9f52ac 100644 --- a/docs/pyproject.md +++ b/docs/pyproject.md @@ -279,7 +279,9 @@ include = [ ] ``` -If no format is specified, it will default to include both `sdist` and `wheel`. +If no format is specified, `include` defaults to only `sdist`. + +In contrast, `exclude` defaults to both `sdist` and `wheel`. ```toml exclude = ["my_package/excluded.py"] diff --git a/src/poetry/console/commands/version.py b/src/poetry/console/commands/version.py index 0af2a004719..7e8d118759c 100644 --- a/src/poetry/console/commands/version.py +++ b/src/poetry/console/commands/version.py @@ -86,7 +86,7 @@ def handle(self) -> int: self.line(self.poetry.package.pretty_version) else: self.line( - f"{self.poetry.package.name}" + f"{self.poetry.package.pretty_name}" f" {self.poetry.package.pretty_version}" ) diff --git a/tests/console/commands/test_version.py b/tests/console/commands/test_version.py index 8d671273bbb..4772a400be1 100644 --- a/tests/console/commands/test_version.py +++ b/tests/console/commands/test_version.py @@ -10,7 +10,10 @@ if TYPE_CHECKING: from cleo.testers.command_tester import CommandTester + from poetry.poetry import Poetry from tests.types import CommandTesterFactory + from tests.types import FixtureDirGetter + from tests.types import ProjectFactory @pytest.fixture() @@ -23,6 +26,18 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester: return command_tester_factory("version") +@pytest.fixture +def poetry_with_underscore( + project_factory: ProjectFactory, fixture_dir: FixtureDirGetter +) -> Poetry: + source = fixture_dir("simple_project") + pyproject_content = (source / "pyproject.toml").read_text(encoding="utf-8") + pyproject_content = pyproject_content.replace("simple-project", "simple_project") + return project_factory( + "project_with_underscore", pyproject_content=pyproject_content + ) + + @pytest.mark.parametrize( "version, rule, expected", [ @@ -79,6 +94,14 @@ def test_version_show(tester: CommandTester) -> None: assert tester.io.fetch_output() == "simple-project 1.2.3\n" +def test_version_show_with_underscore( + command_tester_factory: CommandTesterFactory, poetry_with_underscore: Poetry +) -> None: + tester = command_tester_factory("version", poetry=poetry_with_underscore) + tester.execute() + assert tester.io.fetch_output() == "simple_project 1.2.3\n" + + def test_short_version_show(tester: CommandTester) -> None: tester.execute("--short") assert tester.io.fetch_output() == "1.2.3\n"