Skip to content

Commit 4fae81f

Browse files
committed
Disable Poetry "package mode"
The project Python package dependencies are managed using the Poetry tool. By default, Poetry is configured in "package mode", which is intended for use with projects that are a Python package. When Poetry is used in a project like this that is a standalone script, this configuration is inappropriate and has the following effects: * `poetry install` command installs the project as a Python package in addition to the dependencies. * `name`, `version`, `description`, and `authors` fields of the pyproject.toml file are required. Installing the project as a package is completely inappropriate if the project is not a package, and may cause the command to fail with a cryptic error. This can be avoided by passing the `--no-root` flag to the `install` command, but that increases the usage complexity and chance for user error. Although metadata fields under the `tool.poetry` section of the pyproject.toml configuration file are important for a package, in a non-package project there are better ways to provide that information. Since Git tags are used for versioning, the presence of a `version` field is especially harmful since it means duplication of information and extra work for the project maintainer (and likelihood the metadata will not be kept updated). This "package mode" can be disabled via the pyproject.toml configuration file, which causes Poetry to operate purely in the sole capacity in which it is used by the templates: to manage dependencies.
1 parent a478861 commit 4fae81f

11 files changed

+62
-76
lines changed

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
line-length = 120
33

44
[tool.poetry]
5-
name = "tooling-project-assets"
6-
version = "0.0.0"
7-
description = ""
8-
authors = ["Arduino <[email protected]>"]
5+
package-mode = false
96

107
[tool.poetry.dependencies]
118
python = "~3.9"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Poetry Assets
2+
3+
Python package dependencies are managed using the [**Poetry**](https://python-poetry.org/) tool.
4+
5+
In addition to direct dependencies used by project Python code, **Poetry** is also used to manage Python package-based tools that are used for development and maintenance operations in the project.
6+
7+
## Installation
8+
9+
### Assets
10+
11+
Install [`pyproject.toml`](pyproject.toml) to the root of the project repository.
12+
13+
## Configuration
14+
15+
### If the project is not a Python package
16+
17+
No configuration is needed.
18+
19+
### If the project is a Python package
20+
21+
1. Delete the following line from the `pyproject.toml` file:
22+
```toml
23+
package-mode = false
24+
```
25+
1. Define the package metadata under the `tool.poetry` section of the `pyproject.toml` file:<br />
26+
https://python-poetry.org/docs/pyproject#the-toolpoetry-section
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry/pyproject.toml
2+
3+
[build-system]
4+
requires = ["poetry-core>=1.0.0"]
5+
build-backend = "poetry.core.masonry.api"
6+
7+
[tool.poetry]
8+
package-mode = false
9+
10+
[tool.poetry.dependencies]
11+
python = "^3.9"

workflow-templates/check-mkdocs-task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Install the [`check-mkdocs-task.yml`](check-mkdocs-task.yml) GitHub Actions work
1212

1313
### Assets
1414

15+
- [`pyproject.toml`](assets/poetry/pyproject.toml) - [**Poetry**](https://python-poetry.org/) configuration.
16+
- Install to: repository root (unless a `pyproject.toml` file is already present).
1517
- [`Taskfile.yml`](assets/check-mkdocs-task/Taskfile.yml) - Build task.
1618
- Install to: repository root (or merge into the existing `Taskfile.yml`).
1719
- [`Taskfile.yml`](assets/poetry-task/Taskfile.yml) - Installation task.

workflow-templates/check-python-task.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Install the [`check-python-task.yml`](check-python-task.yml) GitHub Actions work
1414

1515
- [`.flake8`](assets/check-python/.flake8) - flake8 configuration file.
1616
- Install to: repository root
17+
- [`pyproject.toml`](assets/poetry/pyproject.toml) - [**Poetry**](https://python-poetry.org/) configuration.
18+
- Install to: repository root (unless a `pyproject.toml` file is already present).
1719
- [`Taskfile.yml`](assets/check-python-task/Taskfile.yml) - Python linting and formatting tasks.
1820
- Install to: repository root (or merge into the existing `Taskfile.yml`).
1921
- [`Taskfile.yml`](assets/poetry-task/Taskfile.yml) - Installation task.
@@ -23,25 +25,13 @@ The code style defined in `pyproject.toml` and `.flake8` is the official standar
2325

2426
### Dependencies
2527

26-
The tool dependencies of this workflow are managed by [Poetry](https://python-poetry.org/).
27-
28-
Install Poetry by following these instructions:<br />
29-
https://python-poetry.org/docs/#installation
30-
31-
If your project does not already use Poetry, you can initialize the [`pyproject.toml`](https://python-poetry.org/docs/pyproject/) file using these commands:
32-
33-
```
34-
poetry init --python="^3.9" --dev-dependency="black@^25.1.0" --dev-dependency="flake8@^7.2.0" --dev-dependency="pep8-naming@^0.15.1"
35-
poetry install
36-
```
37-
38-
If already using Poetry, add the tool using this command:
28+
Add the tool dependencies using this command:
3929

4030
```
4131
poetry add --dev "black@^25.1.0" "flake8@^7.2.0" "pep8-naming@^0.15.1"
4232
```
4333

44-
Commit the resulting `pyproject.toml` and `poetry.lock` files.
34+
Commit the resulting changes to the `pyproject.toml` and `poetry.lock` files.
4535

4636
### Configuration
4737

workflow-templates/check-yaml-task.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Install the [check-yaml-task.yml](check-yaml-task.yml) GitHub Actions workflow t
1616

1717
- [`.yamllint.yml`](assets/check-yaml/.yamllint.yml) - `yamllint` configuration file.
1818
- Install to: repository root
19+
- [`pyproject.toml`](assets/poetry/pyproject.toml) - [**Poetry**](https://python-poetry.org/) configuration.
20+
- Install to: repository root (unless a `pyproject.toml` file is already present).
1921
- [`Taskfile.yml`](assets/check-yaml-task/Taskfile.yml) - Linting task.
2022
- Install to: repository root (or merge into the existing `Taskfile.yml`).
2123
- [`Taskfile.yml`](assets/poetry-task/Taskfile.yml) - Installation task.
@@ -25,25 +27,13 @@ The code style defined in this file is the official standardized style to be use
2527

2628
### Dependencies
2729

28-
The `yamllint` tool dependency is managed by [Poetry](https://python-poetry.org/).
29-
30-
Install Poetry by following these instructions:<br />
31-
https://python-poetry.org/docs/#installation
32-
33-
If your project does not already use Poetry, you can initialize the [`pyproject.toml`](https://python-poetry.org/docs/pyproject/) file using these commands:
34-
35-
```
36-
poetry init --python="^3.9" --dev-dependency="yamllint@^1.37.1"
37-
poetry install
38-
```
39-
40-
If already using Poetry, add the tool using this command:
30+
Add the tool dependency using this command:
4131

4232
```
4333
poetry add --dev "yamllint@^1.37.1"
4434
```
4535

46-
Commit the resulting `pyproject.toml` and `poetry.lock` files.
36+
Commit the resulting changes to the `pyproject.toml` and `poetry.lock` files.
4737

4838
### Configuration
4939

workflow-templates/deploy-mkdocs-poetry.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Install the [`deploy-mkdocs-poetry.yml`](deploy-mkdocs-poetry.yml) GitHub Action
1212

1313
### Assets
1414

15+
- [`pyproject.toml`](assets/poetry/pyproject.toml) - [**Poetry**](https://python-poetry.org/) configuration.
16+
- Install to: repository root (unless a `pyproject.toml` file is already present).
1517
- [`Taskfile.yml`](assets/poetry-task/Taskfile.yml) - Python package dependency management tasks.
1618
- Install to: repository root (or merge into the existing `Taskfile.yml`).
1719
- [`mkdocs.yml`](assets/mkdocs/mkdocs.yml) - base MkDocs configuration file.
@@ -21,25 +23,13 @@ Install the [`deploy-mkdocs-poetry.yml`](deploy-mkdocs-poetry.yml) GitHub Action
2123

2224
### Dependencies
2325

24-
The website build dependencies are managed by [Poetry](https://python-poetry.org/).
25-
26-
Install Poetry by following these instructions:<br />
27-
https://python-poetry.org/docs/#installation
28-
29-
If your project does not already use Poetry, you can initialize the [`pyproject.toml`](https://python-poetry.org/docs/pyproject/) file using these commands:
30-
31-
```
32-
poetry init --python="^3.9" --dev-dependency="mkdocs@^1.3.0" --dev-dependency="mkdocs-material@^8.2.11" --dev-dependency="mdx_truly_sane_lists@^1.2"
33-
poetry install
34-
```
35-
36-
If already using Poetry, add the tool using this command:
26+
Add the tool dependencies using this command:
3727

3828
```
3929
poetry add --dev "mkdocs@^1.3.0" "mkdocs-material@^8.2.11" "mdx_truly_sane_lists@^1.2"
4030
```
4131

42-
Commit the resulting `pyproject.toml` and `poetry.lock` files.
32+
Commit the resulting changes to the `pyproject.toml` and `poetry.lock` files.
4333

4434
### Configuration
4535

workflow-templates/deploy-mkdocs-versioned-poetry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ See the ["Deploy Website" workflow (MkDocs, Poetry) documentation](deploy-mkdocs
3535
```
3636
poetry add --dev "gitpython@^3.1.44" "mike@^1.1.2"
3737
```
38-
1. Commit the resulting `pyproject.toml` and `poetry.lock` files.
38+
1. Commit the resulting changes to the `pyproject.toml` and `poetry.lock` files.
3939

4040
### Configuration
4141

workflow-templates/spell-check-task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ If already using Poetry, add the tool using this command:
3939
poetry add --dev "codespell@^2.4.0"
4040
```
4141

42-
Commit the resulting `pyproject.toml` and `poetry.lock` files.
42+
Commit the resulting changes to the `pyproject.toml` and `poetry.lock` files.
4343

4444
### Configuration
4545

workflow-templates/test-go-integration-task.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Install the [`test-go-integration-task.yml`](test-go-integration-task.yml) GitHu
1212

1313
## Assets
1414

15+
- [`pyproject.toml`](assets/poetry/pyproject.toml) - [**Poetry**](https://python-poetry.org/) configuration.
16+
- Install to: repository root (unless a `pyproject.toml` file is already present).
1517
- [`Taskfile.yml`](assets/test-go-integration-task/Taskfile.yml) - Test runner task.
1618
- Install to: repository root (or merge into the existing `Taskfile.yml`).
1719
- [`Taskfile.yml`](assets/go-task/Taskfile.yml) - Build task.
@@ -27,25 +29,13 @@ Install the [`test-go-integration-task.yml`](test-go-integration-task.yml) GitHu
2729

2830
### Dependencies
2931

30-
The Python dependencies are managed by [Poetry](https://python-poetry.org/).
31-
32-
Install Poetry by following these instructions:<br />
33-
https://python-poetry.org/docs/#installation
34-
35-
If your project does not already use Poetry, you can initialize the [`pyproject.toml`](https://python-poetry.org/docs/pyproject/) file using these commands:
36-
37-
```
38-
poetry init --python="^3.9" --dev-dependency="pytest@^8.4.1" --dev-dependency="invoke@^1.7.0"
39-
poetry install
40-
```
41-
42-
If already using Poetry, add the tool using this command:
32+
Add the tool dependencies using this command:
4333

4434
```
4535
poetry add --dev "pytest@^8.4.1" "invoke@^1.7.0"
4636
```
4737

48-
Commit the resulting `pyproject.toml` and `poetry.lock` files.
38+
Commit the resulting changes to the `pyproject.toml` and `poetry.lock` files.
4939

5040
### Configuration
5141

workflow-templates/test-python-poetry-task.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Install the [`test-python-poetry-task.yml`](test-python-poetry-task.yml) GitHub
1212

1313
### Assets
1414

15+
- [`pyproject.toml`](assets/poetry/pyproject.toml) - [**Poetry**](https://python-poetry.org/) configuration.
16+
- Install to: repository root (unless a `pyproject.toml` file is already present).
1517
- [`Taskfile.yml`](assets/test-python-poetry-task/Taskfile.yml) - Test runner task.
1618
- Install to: repository root (or merge into the existing `Taskfile.yml`).
1719
- [`Taskfile.yml`](assets/poetry-task/Taskfile.yml) - Installation task.
@@ -25,25 +27,13 @@ Install the [`test-python-poetry-task.yml`](test-python-poetry-task.yml) GitHub
2527

2628
### Dependencies
2729

28-
The Python dependencies are managed by [Poetry](https://python-poetry.org/).
29-
30-
Install Poetry by following these instructions:<br />
31-
https://python-poetry.org/docs/#installation
32-
33-
If your project does not already use Poetry, you can initialize the [`pyproject.toml`](https://python-poetry.org/docs/pyproject/) file using these commands:
34-
35-
```
36-
poetry init --python="^3.9" --dev-dependency="pytest@^8.4.1"
37-
poetry install
38-
```
39-
40-
If already using Poetry, add the tool using this command:
30+
Add the tool dependency using this command:
4131

4232
```
4333
poetry add --dev "pytest@^8.4.1"
4434
```
4535

46-
Commit the resulting `pyproject.toml` and `poetry.lock` files.
36+
Commit the resulting changes to the `pyproject.toml` and `poetry.lock` files.
4737

4838
### Readme badge
4939

0 commit comments

Comments
 (0)