Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-callonnec committed Jan 15, 2024
2 parents 1ca910e + 05f39ef commit 0439a7e
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions docs/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}}
Expand Down
13 changes: 13 additions & 0 deletions docs/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
8 changes: 8 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
18 changes: 8 additions & 10 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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 =
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:

Expand Down
4 changes: 3 additions & 1 deletion docs/pyproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion src/poetry/console/commands/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def handle(self) -> int:
self.line(self.poetry.package.pretty_version)
else:
self.line(
f"<comment>{self.poetry.package.name}</>"
f"<comment>{self.poetry.package.pretty_name}</>"
f" <info>{self.poetry.package.pretty_version}</>"
)

Expand Down
23 changes: 23 additions & 0 deletions tests/console/commands/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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",
[
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 0439a7e

Please sign in to comment.