-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Everything you need to set up, write code, and contribute to this project.
Make sure these are installed on your machine:
- Python 3.8 or newer
- Git
Check with:
python --version
git --versionWhy do we use virtual environments and what are they?
python -m venv .venvOR if you get an error message:
python3 -m venv .venvThis creates a .venv folder in the project root. It is already in .gitignore so it will never be committed.
Run PowerShell as admin and enter:
set-executionpolicy remotesigned
Linux / macOS:
source .venv/bin/activateWindows (Command Prompt):
.venv\Scripts\activateWindows (PowerShell):
.venv\Scripts\Activate.ps1Your terminal should now show (.venv) before the prompt. That means it is active.
Click here to read about dependencies
Install the project's development tools:
pip install -r requirements.txtCurrently this only includes Ruff, the formatter and linter. The project itself uses only the Python standard library.
This walks you through the full process, from cloning to having your code merged. If you already know git, skip ahead to the quick reference.
NOTE:
- master branch is the main "production" version
- development happens from development branch on individual branches
- create a branch before you make changes
- changes from your branch get merged to development, development gets merged to master once release happens
git clone https://github.com/blomma-dev/pynventory.git
cd pynventoryThe main branch of the repository is master.
Development work takes place from development.
git checkout master
git pull origin mastergit checkout development
git pull origin developmentAlways start new work from an up-to-date development.
git fetch
git pullUseful commands
git statusName it after what you are doing. Use one of the prefixes below:
-
feature/— new functionality -
fix/— bug fixes -
chore/— cleanup, refactoring, docs
Examples:
git checkout -b feature/search-by-name
git checkout -b fix/delete-confirmation
git checkout -b chore/refactor-functionsWrite code, test it manually, and commit as you go. Commit often with clear messages. You can use either VScode git, git through terminal or for example GitHub desktop. Whatever works for you.
git add main.py (or whatever your modified file is named)
git commit -m "add search command"Or stage everything:
git add .
git commit -m "add search command with partial name matching"More on commit messages in section 6.
If someone merged something to master or development while you were working:
git checkout master
git pull origin master
git checkout your-branch
git merge masterOR
git checkout development
git pull origin development
git checkout your-branch
git merge developmentFix any conflicts, then commit the merge.
git push origin your-branchGo to the repository on GitHub. You will see a banner suggesting you open a pull request for your recently pushed branch. Click it.
ALWAYS SELECT DEVELOP TO RECEIVE CHANGES FROM YOUR BRANCH
Fill in the description (see section 8) and make sure to select a reviewer for the PR. Once ready, click submit.
If the reviewer requests changes, make them on the same branch, commit, and push again. The pull request updates automatically.
Once a pull request is approved it can be merged by the maintainer (most likely you if you are reading this), and then your branch can be deleted. GitHub offers a button for this right on the merged PR page. IMPORTANT: Do not attempt to delete development or master branches
Locally, switch back to master and pull:
git checkout master
git pull origin masterOR
git checkout development
git pull origin developmentRead below more about branches
# Start fresh
git checkout master
git pull origin master
# Start from development
git checkout development
git pull origin development
# Branch and work
git checkout -b feature/your-thing
# ... write code ...
git add .
git commit -m "what you did"
# Push and PR
git push origin feature/your-thing
# ... open pull request on GitHub ...
# After merge
git checkout master
git pull origin master
OR
git checkout development
git pull origin developmentStick to these prefixes so anyone can tell what a branch is for at a glance:
| Prefix | Use for |
|---|---|
feature/ |
New functionality |
fix/ |
Bug fixes |
chore/ |
Refactoring, cleanup, docs |
Keep the name short and descriptive. Lowercase, hyphens for spaces.
Good:
feature/search-by-brandfix/empty-name-crashchore/split-functions-file
Bad:
mybranchstuffFeatureSearchByBrand
A good commit message has:
- A short subject line (50 characters or less).
- Written in the imperative mood: "add search" not "added search" or "adds search".
- A blank line, then a longer description if the change needs explaining.
add search command with partial name matching
fix crash when deleting a product that does not exist
The program would raise an IndexError if you tried to
delete an ID that was not in the table. Now it checks
first and shows a clear message.
- Vague messages like "update code" or "fix bug".
- Messages longer than 50 characters for the subject.
- Messages in past tense.
We use Ruff for formatting and linting. It is fast, minimal, and the built-in formatter in Zed. VSCode users can install the Ruff extension.
Install Ruff:
pip install -r requirements.txtOr directly:
pip install ruffFormat your code:
ruff format .Check for issues:
ruff check .Fix issues automatically:
ruff check --fix .VSCode — Install the Ruff extension and add this to your settings:
{
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true
}
}Zed — Ruff is the default formatter for Python. No setup needed.
PyCharm — Install the Ruff plugin:
- Go to Settings → Plugins and search for "Ruff".
- Install and restart PyCharm.
- Go to Settings → Tools → Ruff.
- Check Enabled and set Run on save to
true. - PyCharm will auto-detect the project's
ruff.toml.
The project's ruff.toml file keeps formatting the same across all editors.
Look at what is already in the project and follow the same patterns:
- How functions are named:
snake_case - How classes are named:
PascalCase - How indentation works: 4 spaces
- How input validation is structured
When you add new code, match what is around it.
Code should explain itself most of the time. Add a comment only when something is not obvious at first glance. Keep them short.
Avoid leaving commented-out code. If it is not used, delete it.
Click here to read about pull requests
When you open a pull request, include:
- What you did — a short summary of the change.
- Why — what problem does it solve?
-
Link to the
todo.mditem — if your change relates to one. - How you tested it — what did you try to make sure it works?
Self-review checklist before submitting:
- I tested the change manually and it works.
- I checked for leftover debug prints.
- My branch is up to date with
master. - The code follows the project's style.
Right now testing is manual. Before opening a pull request:
- Run
python main.pyand try your feature. - Try edge cases: empty input, wrong input, fast typing, whatever you can think of.
- Make sure existing commands still work.
Automated tests may be added later. When they are, they must pass before merging.
The project uses SQLite for now as database, read more about SQLite: click here to read more about SQLite.
- The database file is
products.db. It is already in.gitignore. Do not commit it. - To create a fresh database, run:
python database.py- If you ever need to start over, delete
products.dband run that command again.