Skip to content
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

Add poetry dependency manager and package builder #368

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 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
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
93 changes: 51 additions & 42 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,58 +24,46 @@ 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.11 or 3.12
- [Poetry](https://python-poetry.org/docs/)

### Creating a Python Virtual Environment
### Installing dependencies

If you wish to launch the source version of TagStudio outside of your IDE:
After installing poetry and python you can install the dependencies with the following command:
Copy link
Collaborator

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
Collaborator

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?


> [!IMPORTANT]
> Depending on your system, Python may be called `python`, `py`, `python3`, or `py3`. These instructions use the alias `python3` for consistency. You can check to see which alias your system uses and if it's for the correct Python version by typing `python3 --version` (or whichever alias) into your terminal.
```shell
poetry install
```
tintin10q marked this conversation as resolved.
Show resolved Hide resolved

> [!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._

1. In the root repository directory, create a python virtual environment:
`python3 -m venv .venv`
2. Activate your environment:

- Windows w/Powershell: `.venv\Scripts\Activate.ps1`
- Windows w/Command Prompt: `.venv\Scripts\activate.bat`
- Linux/macOS: `source .venv/bin/activate`

3. Install the required packages:

- `pip install -r requirements.txt`
- If developing (includes Ruff and Mypy): `pip install -r requirements-dev.txt`

_Learn more about setting up a virtual environment [here](https://docs.python.org/3/tutorial/venv.html)._

### Manually Launching (Outside of an IDE)

- **Windows** (start_win.bat)
If you plan to make a pull request or develop the code run this instead to also install the dev dependencies:

- To launch TagStudio, launch the `start_win.bat` file. You can modify this .bat file or create a shortcut and add one or more additional arguments if desired.
```shell
poetry install --with dev
```

- **Linux/macOS** (TagStudio.sh)
### Running TagStudio

- Run the "TagStudio.sh" script and the program should launch! (Make sure that the script is marked as executable if on Linux). Note that launching from the script from outside of a terminal will not launch a terminal window with any debug or crash information. If you wish to see this information, just launch the shell script directly from your terminal with `./TagStudio.sh`.
After installing the dependencies you can start TagStudio by running this command at the root of the project:

- **NixOS** (Nix Flake)
> [!WARNING]
> Support for NixOS is still a work in progress.
- Use the provided [Flake](https://nixos.wiki/wiki/Flakes) to create and enter a working environment by running `nix develop`. Then, run the program via `python3 tagstudio/tag_studio.py` from the root directory.
```shell
poetry run tagstudio
```

#### Nix

- **Any** (No Scripts)
Alternatively, you can also run TagStudio using Nix.

- 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`.
> [!WARNING]
> Support for NixOS is still a work in progress.

Use the provided [Flake](https://nixos.wiki/wiki/Flakes) to create and enter a working environment by running `nix develop`.
Then, run the program via `python3 tagstudio/tag_studio.py` from the root directory.

## 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 get a shell with these tools on the activated on the path with `poetry shell`.

> [!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 @@ -103,7 +91,7 @@ Mypy is a static type checker for Python. It sure has a lot to say sometimes, bu
- Check code by moving into the `/tagstudio` directory with `cd tagstudio` _(if you aren't already inside)_ and running `mypy --config-file ../pyproject.toml .`. _(Don't forget the `.` at the end!)_

> [!CAUTION]
> There's a known issue between PySide v6.6.3 and Mypy where Mypy will detect issues with the `.pyi` files inside of PySide and prematurely stop checking files. This issue is not present in PySide v6.6.2, which _should_ be compatible with everything else if you wish to try using that version in the meantime.
> There's a known issue between PySide v6.6.3 and Mypy where Mypy will detect issues with the `.pyi` files inside PySide and prematurely stop checking files. This issue is not present in PySide v6.6.2, which _should_ be compatible with everything else if you wish to try using that version in the meantime.

Mypy is also available as a VS Code [extension](https://marketplace.visualstudio.com/items?itemName=matangover.mypy), PyCharm [plugin](https://plugins.jetbrains.com/plugin/11086-mypy), and [more](https://plugins.jetbrains.com/plugin/11086-mypy).

Expand Down Expand Up @@ -144,7 +132,7 @@ Most of the style guidelines can be checked, fixed, and enforced via Ruff. Older
- macOS: 12.0+
- Linux: TBD
- Avoid use of unnecessary logging statements in final submitted code.
- Code should not cause unreasonable slowdowns to the program outside of a progress-indicated task.
- Code should not cause unreasonable slowdowns to the program outside a progress-indicated task.

#### Git/GitHub Specifics

Expand All @@ -155,9 +143,30 @@ Most of the style guidelines can be checked, fixed, and enforced via Ruff. Older
- "Fix function foobar"
- Pull Requests should have an adequate title and description which clearly outline your intentions and changes/additions. Feel free to provide screenshots, GIFs, or videos, especially for UI changes.

#### 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
Collaborator

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
Collaborator

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 `doc/` folder, as well as the `README.md` and `CONTRIBUTING.md` files.
Documentation contributions include anything inside the `doc/` folder, as well as the `README.md` and `CONTRIBUTING.md` files.

- Use "[snake_case](https://developer.mozilla.org/en-US/docs/Glossary/Snake_case)" for file and folder names
- Follow the folder structure pattern
Expand All @@ -167,4 +176,4 @@ Documentation contributions include anything inside of the `doc/` folder, as wel

## Translation Guidelines

_TBA_
_TBA_
Loading