Skip to content

Add poetry dependency manager and package builder #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
713ea54
Added poetry stuff to pyproject.toml
tintin10q Aug 22, 2024
cbbc453
Adding src to the path fixes the console_script and poetry run tagstu…
tintin10q Aug 22, 2024
cd2dfb2
Lazy import the ui modes. Also this fixes cli not being included in t…
tintin10q Aug 22, 2024
08dd179
For poetry to work resources has to be an importable package
tintin10q Aug 22, 2024
ef51164
Add __init__.py to make tagstudio a package
tintin10q Aug 22, 2024
32e9c07
Add __init__.py to package
tintin10q Aug 22, 2024
a2f9b7c
Put packages on multiple lines
tintin10q Aug 22, 2024
bb8558c
Update tagstudio/__init__.py
tintin10q Aug 22, 2024
825af51
Shorter pypackage.toml description
tintin10q Aug 22, 2024
62df241
Added tests to package build
tintin10q Aug 22, 2024
78af477
Included tests in the release package
tintin10q Aug 22, 2024
b5fd573
Removed duplicate readme tag
tintin10q Aug 22, 2024
3cc87cf
Add poetry.lock file to vsc
tintin10q Aug 22, 2024
6f2004a
Ruff suggestions
tintin10q Aug 22, 2024
a06e90d
Update CONTRIBUTING.md with poetry instructions
tintin10q Aug 23, 2024
945b20c
Changed supported python version from just 3.12 to also 3.11
tintin10q Aug 23, 2024
f98d2f6
Bumped version to the actual version of 9.3.2
tintin10q Aug 23, 2024
15e427e
Merge branch 'main' into add-poetry
tintin10q Aug 23, 2024
3b24911
Small word repetition fix
tintin10q Aug 23, 2024
97c7337
Update pyproject.toml
tintin10q Aug 23, 2024
e8f66a9
Unupdate changes to pyproject.toml
tintin10q Aug 23, 2024
f59ad99
Added explanation text to CONTRIBUTING.md about how to add and remove…
tintin10q Aug 23, 2024
f561374
Specify where to run poetry install command.
tintin10q Aug 24, 2024
4a69f11
Merge remote-tracking branch 'origin/main' into add-poetry
tintin10q Sep 1, 2024
4b82769
Move adding the package to the import path into __init__.py
tintin10q Sep 1, 2024
50e05a3
Merge branch 'main' into add-poetry
tintin10q Mar 3, 2025
48de3e0
Update dependencies from requirements.txt and requirements-dev.txt
tintin10q Mar 3, 2025
4b1f52a
Ruff formatting
tintin10q Mar 3, 2025
7f6ac4e
Remove reference from CONTRIBUTING.md of poetry shell because it is n…
tintin10q Mar 3, 2025
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
74 changes: 68 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,43 @@ Thank you so much for showing interest in contributing to TagStudio! Here are a

### Prerequisites

- [Python](https://www.python.org/downloads/) 3.12
- [Ruff](https://github.com/astral-sh/ruff) (Included in `requirements-dev.txt`)
- [Mypy](https://github.com/python/mypy) (Included in `requirements-dev.txt`)
- [PyTest](https://docs.pytest.org) (Included in `requirements-dev.txt`)
- [Python](https://www.python.org/downloads/) 3.12
- [Poetry](https://python-poetry.org/docs/)
- [Ruff](https://github.com/astral-sh/ruff) (Included in `requirements-dev.txt`)
- [Mypy](https://github.com/python/mypy) (Included in `requirements-dev.txt`)
- [PyTest](https://docs.pytest.org) (Included in `requirements-dev.txt`)

> [!TIP]
> On Linux and macOS, you can launch the `tagstudio.sh` script to skip the following process, minus the `requirements-dev.txt` installation step. _Using the script is fine if you just want to launch the program from source._

### Creating a Python Virtual Environment

There are two ways to create a virtual Environment.
Using a poetry or using pyvenv.

#### Poetry

After installing poetry and python you can install the dependencies with the following command:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im in favor of sharing one way to install a tool if there is consensus to use it. I use poetry daily, there are many things I don't like about it, but it makes the interface we use the same for all developers, no matter what platform you are on.

Currently the recommended way to install poetry is by using pipx this is a tool that is recommended for python devs to have, but it is yet another install process to document.

Im happy write the changes needed if that is something you would like me to do.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear to me what changes you are actually suggesting here. @eivl

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pipx install poetry is the command to install poetry. the docs has multiple other ways to install it, but I'm in favor of front loading the information instead of back loading it with more links to click on.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so just adding pipx install poetry in CONTRIBUTING.md with some text?


```shell
poetry install
```

If you plan to make a pull request or develop the code run this instead to also install the dev dependencies:

```shell
poetry install --with dev
```
You should run these (or any other poetry command) at the root of the project where the pyproject.toml file is located.

You can start tag studio with:

```shell
poetry run tagstudio
```

#### Pyvenv

If you wish to launch the source version of TagStudio outside of your IDE:

> [!IMPORTANT]
Expand All @@ -44,6 +74,7 @@ If you wish to launch the source version of TagStudio outside of your IDE:
> [!TIP]
> On Linux and macOS, you can launch the `tagstudio.sh` script to skip the following process, minus the `requirements-dev.txt` installation step. _Using the script is fine if you just want to launch the program from source._

If you plan to make a pull request or develop the code run this instead to also install the dev dependencies:
1. Make sure you're using the correct Python version:
- If the output matches `Python 3.12.x` (where the x is any number) then you're using the correct Python version and can skip to step 2. Otherwise, you can install the correct Python version from the [Python](https://www.python.org/downloads/) website, or you can use a tool like [pyenv](https://github.com/pyenv/pyenv/) to install the correct version without changes to your system:
1. Follow pyenv's [install instructions](https://github.com/pyenv/pyenv/?tab=readme-ov-file#installation) for your system.
Expand All @@ -66,7 +97,6 @@ If you wish to launch the source version of TagStudio outside of your IDE:
|CSH/TCSH|`.venv/bin/activate.csh` |
|PWSH |`.venv/bin/activate.ps1` |


4. Install the required packages:

- `pip install -r requirements.txt`
Expand All @@ -76,7 +106,14 @@ _Learn more about setting up a virtual environment [here](https://docs.python.or

### Manually Launching (Outside of an IDE)

If you encounter errors about the Python version, or seemingly vague script errors, [pyenv](https://github.com/pyenv/pyenv/) may solve your issue. See step 1 of [Creating a Python Virtual Environment](#creating-a-python-virtual-environment).

If you are using poetry just run

```shell
poetry run tagstudio
```

You can also use the following scripts:

- **Windows** (start_win.bat)

Expand All @@ -96,9 +133,13 @@ If you encounter errors about the Python version, or seemingly vague script erro

- Alternatively, with the virtual environment loaded, run the python file at `tagstudio\tag_studio.py` from your terminal. If you're in the project's root directory, simply run `python3 tagstudio/tag_studio.py`.

If you encounter errors about the Python version, or seemingly vague script errors, [pyenv](https://github.com/pyenv/pyenv/) may solve your issue. See step 1 of [Creating a Python Virtual Environment](#creating-a-python-virtual-environment).

## Workflow Checks

When pushing your code, several automated workflows will check it against predefined tests and style checks. It's _highly recommended_ that you run these checks locally beforehand to avoid having to fight back-and-forth with the workflow checks inside your pull requests.
These tools are installed into your environment if you ran `poetry install --with dev`.
You can run the tools by prepending `poetry run` to the command. Like `poetry run ruff`.

> [!TIP]
> To format the code automatically before each commit, there's a configured action available for the `pre-commit` hook. Install it by running `pre-commit install`. The hook will be executed each time on running `git commit`.
Expand Down Expand Up @@ -189,6 +230,27 @@ Most of the style guidelines can be checked, fixed, and enforced via Ruff. Older
- Cause unreasonable slowdowns to the program outside of a progress-indicated task
- Cause undesirable visual glitches or artifacts on screen

#### Adding dependencies

If you want to add a dependency to the project use `poetry add <dependency-name>`.
For example: `poetry add httpx`.
If you decide you did not want to add the dependency after all you can use `poetry remove <dependency-name>`.

If you decide to commit this change be sure to also update the requirements.txt file by generating it from the pyproject.toml with:

```shell
poetry export --without-hashes --format=requirements.txt > requirements.txt
```

If you want to add a dev dependency instead use: `poetry add <name> --group dev`.
To regenerate the requirements-dev.txt use:

```shell
poetry export --without-hashes --without main --with dev --format=requirements.txt > requirements-dev.txt
```

Do not forget to actually commit the updated requirement.txt and pyproject.toml and poetry.lock files when you change/add dependencies.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an important detail missing from this MD file.

The explanation of what the lock file is. The troublesome command poetry update and en explicit warning that this command updates packages and creates a new .lock file. If the PR is updating dependencies, sure, you would use this and update the .lock file.

When you add a new dependencies, poetry will use the caret symbol, I personally dislike this behaviour as it is implicit in nature. Are future dependencies going to follow the pinned nature of the repo? I don't know, but poetry will update the pyproject.toml file as it sees best. This might lead to trouble and worth a note in the readme.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The section you comment on explains how to add dependencies. The reader does not need to know what the poetry.lock file is because it is updated correctly when they run poetry add <dependency> as described. No need to run poetry update either. I don't understand why you bring up poetry update because I did not tell the reader to run this command.

I could add a sentence saying that it is better to pin a specific version of a dependency poetry add package==0.1.0?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a thing I have seen many times in projects that start using poetry. I don't mind the sections that are already added. Im saying I think this detail is missing. It has burned many people in projects I have worked on the past years.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you suggest a text? Like there is not more to it then the poetry.lock pins the versions of each dependency so you get reproducible builds.

## Documentation Guidelines

Documentation contributions include anything inside of the `docs/` folder, as well as the `README.md` and `CONTRIBUTING.md` files. Documentation inside the `docs/` folder is built and hosted on our static documentation site, [docs.tagstud.io](https://docs.tagstud.io/).
Expand Down
Loading