Skip to content

Commit

Permalink
Updating docs for adding packages using poetry (#481)
Browse files Browse the repository at this point in the history
* updating docs around adding dependencies

* updating the description

* Updating poetry docs & adding poetry extension to devcontainer

* poetry docs

* Moving it back to Contributing.md

* code review suggestion

---------

Co-authored-by: Ross Smith <[email protected]>
  • Loading branch information
komalg1 and ross-p-smith committed Mar 20, 2024
1 parent 79d7ee0 commit 286fe62
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"ms-python.black-formatter",
"ms-python.vscode-pylance",
"ms-vscode.vscode-node-azure-pack",
"TeamsDevApp.ms-teams-vscode-extension"
"TeamsDevApp.ms-teams-vscode-extension",
"zeshuaro.vscode-python-poetry"
],
"settings": {
"azureFunctions.projectSubpath": "code/backend/batch",
Expand Down
37 changes: 37 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,43 @@ a proposal for your work first, to be sure that we can use it.

* **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).

## Managing Dependencies Using Poetry

Poetry is a package manager for Python that allows developers to manage dependencies, create virtual environments, and package their projects for distribution, all using a single command-line tool.

Poetry is setup for you in the devcontainer, but should you need to set this up manually you can
```sh
sh ./.devcontainer/postCreate.sh
```

The following manual steps can also be followed to setup poetry:
- Poetry can be installed using `pip install poetry`.
- Using `poetry init` poetry creates a `pyproject.toml` file with all the main dependencies required to run the application.
- Executing `poetry install` from the root folder which has the `pyproject.toml` file, installs all the dependencies and creates a virtual environment which is used to run the application. `poetry install` also generates a `poetry.lock` file which locks the dependency versions so that any user who installs the application get the same package version.
- Executing `pip install .` from the root folder only installs the main dependencies.
- Dependencies for different environments (dev, test etc.) can be managed by creating groups in the `pyproject.toml` file.
- Installing dependencies for different groups can be done using `poetry install --with <group_name>`

* Adding new package to [pyproject.toml](#pyproject.toml) :

To add a new package execute the below command:
```shell
poetry add <package-name>
```
To add a package to specific group:
``` shell
poetry add <package-name> --group <group-name>
```

`poetry add <package-name>` updates the `poetry.lock` file.

**Note**: In case the pyproject.toml file is manually updated, the following command should be executed to update the `poetry.lock` file.

``` shell
poetry lock --no-update
```
`--no-update` Locks the packages without updating the locked versions.

## <a name="submit"></a> Submission Guidelines

### <a name="submit-issue"></a> Submitting an Issue
Expand Down

0 comments on commit 286fe62

Please sign in to comment.