-
Notifications
You must be signed in to change notification settings - Fork 382
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
base: main
Are you sure you want to change the base?
Changes from all commits
713ea54
cbbc453
cd2dfb2
08dd179
ef51164
32e9c07
a2f9b7c
bb8558c
825af51
62df241
78af477
b5fd573
3cc87cf
6f2004a
a06e90d
945b20c
f98d2f6
15e427e
3b24911
97c7337
e8f66a9
f59ad99
f561374
4a69f11
4b82769
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,58 +24,48 @@ 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: | ||
|
||
> [!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) | ||
If you plan to make a pull request or develop the code run this instead to also install the dev dependencies: | ||
|
||
- **Windows** (start_win.bat) | ||
```shell | ||
poetry install --with dev | ||
``` | ||
|
||
- 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. | ||
You should run these (or any other poetry command) at the root of the project where the pyproject.toml file is located. | ||
|
||
- **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`. | ||
|
@@ -103,7 +93,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). | ||
|
||
|
@@ -144,7 +134,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 | ||
|
||
|
@@ -155,9 +145,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. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 I could add a sentence saying that it is better to pin a specific version of a dependency There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -167,4 +178,4 @@ Documentation contributions include anything inside of the `doc/` folder, as wel | |
|
||
## Translation Guidelines | ||
|
||
_TBA_ | ||
_TBA_ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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?