|
1 | | -# Developer Guide |
| 1 | +# 🛠️ Developer Guide |
2 | 2 |
|
3 | | -This document will explain how to contribute to the edit-python.pe project. |
| 3 | +This document explains how to contribute to the edit-python.pe project, the commands needed for development, and the translation workflow. |
4 | 4 |
|
5 | | -## How to Contribute |
| 5 | +## 🤝 How to Contribute |
6 | 6 |
|
7 | | -1. Make sure to find an open issue on [GitHub](https://github.com/python.pe/edit-python.pe/issues). |
8 | | -1. Fork the [edit-python.pe](https://github.com/python.pe/edit-python.pe) repository. |
9 | | -1. Clone the forked repository to your local machine. |
10 | | -1. Install [`uv`](https://docs.astral.sh/uv/getting-started/installation/). |
11 | | -1. Install dependencies: |
| 7 | +1. Make sure to find an open issue on [GitHub](https://github.com/pythonpe/edit-python.pe/issues). |
| 8 | +2. Fork the [edit-python.pe](https://github.com/pythonpe/edit-python.pe) repository. |
| 9 | +3. Clone the forked repository to your local machine. |
| 10 | +4. Install [`uv`](https://docs.astral.sh/uv/getting-started/installation/). |
| 11 | +5. Install dependencies: |
| 12 | + ```bash |
| 13 | + uv sync |
| 14 | + ``` |
| 15 | +6. Install the pre-commit hooks (enforces conventional commits and quality checks): |
| 16 | + ```bash |
| 17 | + uv run pre-commit install --hook-type commit-msg |
| 18 | + uv run pre-commit install |
| 19 | + ``` |
| 20 | +7. Make your changes and cover them with tests. |
| 21 | +8. Push your changes to the forked repository. |
| 22 | +9. Open a pull request on [GitHub](https://github.com/pythonpe/edit-python.pe/pulls). |
| 23 | + |
| 24 | +## 🚀 Development Commands |
| 25 | + |
| 26 | +We use `poethepoet` (poe) as our task runner. Run the following commands as needed during development: |
| 27 | + |
| 28 | +- `uv run poe lint`: Runs the `ruff` linter (and checks types using `ty`). |
| 29 | +- `uv run poe lint:format`: Formats the code using `ruff format`. |
| 30 | +- `uv run poe lint:types`: Checks types using `ty check`. |
| 31 | +- `uv run poe test`: Runs the test coverage with `pytest`. |
| 32 | + |
| 33 | +## 📝 Commit Style (Conventional Commits) |
| 34 | + |
| 35 | +This project enforces [Conventional Commits](https://www.conventionalcommits.org/) via a pre-commit hook powered by [Commitizen](https://commitizen-tools.github.io/commitizen/). Every commit message **must** follow this format: |
| 36 | + |
| 37 | +``` |
| 38 | +<type>(<optional scope>): <short description> |
| 39 | +``` |
| 40 | + |
| 41 | +Allowed types: |
| 42 | + |
| 43 | +| Type | When to use | |
| 44 | +|------|-------------| |
| 45 | +| `feat` | A new feature | |
| 46 | +| `fix` | A bug fix | |
| 47 | +| `docs` | Documentation only changes | |
| 48 | +| `style` | Code style changes (formatting, missing semicolons, etc.) | |
| 49 | +| `refactor` | Code change that is neither a fix nor a feature | |
| 50 | +| `perf` | A code change that improves performance | |
| 51 | +| `test` | Adding or fixing tests | |
| 52 | +| `build` | Changes to build system or dependencies | |
| 53 | +| `ci` | Changes to CI configuration files and scripts | |
| 54 | +| `chore` | Other changes that don't modify source or test files | |
| 55 | + |
| 56 | +**Examples:** |
| 57 | +``` |
| 58 | +feat(auth): add GitHub OAuth login |
| 59 | +fix(markdown): handle missing homepage field gracefully |
| 60 | +docs: update README with uvx usage |
| 61 | +``` |
| 62 | + |
| 63 | +You can use `uv run cz commit` as an interactive guided commit helper instead of `git commit`. |
| 64 | + |
| 65 | +## 🏷️ Release Cycle |
| 66 | + |
| 67 | +Releases are managed by [Commitizen](https://commitizen-tools.github.io/commitizen/), which automatically: |
| 68 | + |
| 69 | +- Determines the next semantic version from the commit history (`feat` → minor bump, `fix` → patch bump, `feat!` or `BREAKING CHANGE` → major bump). |
| 70 | +- Updates the version in `pyproject.toml` and `src/edit_python_pe/__version__.py`. |
| 71 | +- Generates or appends to `CHANGELOG.md`. |
| 72 | +- Creates a git tag `v<version>`. |
| 73 | + |
| 74 | +### Performing a Release |
| 75 | + |
| 76 | +> **Only maintainers** should run this command on the `main` branch. |
12 | 77 |
|
13 | 78 | ```bash |
14 | | -uv sync |
| 79 | +uv run poe release |
15 | 80 | ``` |
16 | 81 |
|
17 | | -1. Install pre-commit hook: |
| 82 | +This runs `cz bump --changelog` under the hood. After the tag is created, push both the commit and the tag: |
18 | 83 |
|
19 | 84 | ```bash |
20 | | -uv run pre-commit install |
| 85 | +git push && git push --tags |
21 | 86 | ``` |
22 | 87 |
|
23 | | -1. Make your changes. |
24 | | -1. Cover your changes with tests. |
25 | | -1. Run the test coverage: |
| 88 | +### Previewing the Changelog |
| 89 | + |
| 90 | +To regenerate or preview the full changelog without bumping the version: |
| 91 | + |
| 92 | +```bash |
| 93 | +uv run poe release:changelog |
| 94 | +``` |
| 95 | + |
| 96 | +## 🌐 Translation Workflow |
| 97 | + |
| 98 | +This project uses `pybabel` for translations, completely managed through `poe` tasks. The translation files are packaged internally within `src/edit_python_pe/locale/` so they are automatically included in PyPI wheel distributions. |
| 99 | + |
| 100 | +### 1. Generating or Updating `.po` files |
| 101 | + |
| 102 | +When you add new `_("...")` strings in the source code, run: |
| 103 | + |
| 104 | +```bash |
| 105 | +uv run poe messages:update |
| 106 | +``` |
| 107 | + |
| 108 | +This automatically extracts all translation strings from `src/edit_python_pe/` into `messages.pot` and **updates all existing locales** (e.g. `es`, `fr`, etc.) with the new strings, keeping existing translations intact. |
| 109 | + |
| 110 | +If you only want to extract strings to `messages.pot` without updating the language files, run: |
26 | 111 |
|
27 | 112 | ```bash |
28 | | -uv run poe test |
| 113 | +uv run poe messages:extract |
29 | 114 | ``` |
30 | 115 |
|
31 | | -1. Run the auto-translations: |
| 116 | +> **Note:** We have removed automated machine translation scripts. Automatic tools often miss context-specific terminology (for example, translating "Save" as "Ahorro" instead of "Guardar"). You **must** review the `.po` files one by one and translate them manually, ensuring the correct context for the application. |
| 117 | +
|
| 118 | +### 2. Compiling `.mo` files |
| 119 | + |
| 120 | +After you finish manually translating the `.po` files, you must compile them into the binary `.mo` format so the application can read them. |
32 | 121 |
|
33 | 122 | ```bash |
34 | | -uv run poe makemessages |
| 123 | +uv run poe messages:compile |
35 | 124 | ``` |
36 | 125 |
|
37 | | -1. Commit your changes, if the pre-commit hook fails, run `uv run poe test` to |
38 | | - know which test failed. |
39 | | -1. If the last step was your last commit on this issue, run this command: |
| 126 | +This command compiles all languages in the `locale` directory simultaneously. |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +### Adding a New Language |
| 131 | + |
| 132 | +If you want to add an entirely new language (for example, German `de`), use the `messages:init` command: |
40 | 133 |
|
41 | 134 | ```bash |
42 | | -uv run poe version:update NEW_VERSION |
| 135 | +uv run poe messages:init --lang de |
43 | 136 | ``` |
44 | 137 |
|
45 | | -1. Push your changes to the forked repository. |
46 | | -1. Open a pull request on [GitHub](https://github.com/python.pe/edit-python.pe/pulls). |
| 138 | +This extracts the strings and initializes the completely new directory `src/edit_python_pe/locale/de/LC_MESSAGES/messages.po`. |
0 commit comments