|
| 1 | +# Nushell vs Python: Version Bumping Implementation |
| 2 | + |
| 3 | +This document explains why Nushell was chosen as the primary scripting language for version bumping. |
| 4 | + |
| 5 | +## Comparison |
| 6 | + |
| 7 | +### Native JSON Support |
| 8 | + |
| 9 | +**Python:** |
| 10 | +```python |
| 11 | +import json |
| 12 | + |
| 13 | +with open(json_path, 'r') as f: |
| 14 | + data = json.load(f) |
| 15 | + |
| 16 | +# Modify data |
| 17 | +data['version'] = new_version |
| 18 | + |
| 19 | +with open(json_path, 'w') as f: |
| 20 | + json.dump(data, f, indent=4) |
| 21 | +``` |
| 22 | + |
| 23 | +**Nushell:** |
| 24 | +```nushell |
| 25 | +let data = open $json_path |
| 26 | +let updated_data = ($data | upsert version $new_version) |
| 27 | +$updated_data | to json --indent 4 | save --force $json_path |
| 28 | +``` |
| 29 | + |
| 30 | +### Structured Data Handling |
| 31 | + |
| 32 | +Nushell treats JSON, CSV, and other structured data as first-class citizens, making data manipulation more natural and less error-prone. |
| 33 | + |
| 34 | +### Type Safety |
| 35 | + |
| 36 | +**Python:** |
| 37 | +- Dynamic typing with potential runtime errors |
| 38 | +- Manual type checking needed |
| 39 | +- Error handling via try/except |
| 40 | + |
| 41 | +**Nushell:** |
| 42 | +- Strongly typed with better compile-time checks |
| 43 | +- Built-in error handling with `error make` |
| 44 | +- Type coercion with `into int`, `into string`, etc. |
| 45 | + |
| 46 | +### Error Messages |
| 47 | + |
| 48 | +**Python:** |
| 49 | +``` |
| 50 | +Traceback (most recent call last): |
| 51 | + File "bump-version.py", line 59 |
| 52 | + data = json.load(f) |
| 53 | +json.decoder.JSONDecodeError: ... |
| 54 | +``` |
| 55 | + |
| 56 | +**Nushell:** |
| 57 | +``` |
| 58 | +Error: nu::shell::error |
| 59 | + × Error: Invalid JSON in file |
| 60 | + ╭─[bump-version.nu:50:13] |
| 61 | + 50 │ let data = try { |
| 62 | + · ─┬─ |
| 63 | + · ╰── originates from here |
| 64 | +``` |
| 65 | + |
| 66 | +Nushell provides clearer, more actionable error messages with line numbers and context. |
| 67 | + |
| 68 | +## Benefits of Nushell for This Project |
| 69 | + |
| 70 | +1. **Native JSON Support**: No external libraries needed for JSON parsing |
| 71 | +2. **Concise Syntax**: Less boilerplate code (155 lines in Python vs ~150 in Nushell) |
| 72 | +3. **Better Error Handling**: More informative error messages |
| 73 | +4. **Type Safety**: Fewer runtime errors |
| 74 | +5. **Modern Shell**: Better integration with command-line workflows |
| 75 | +6. **Performance**: Efficient structured data processing |
| 76 | +7. **Maintainability**: Cleaner, more readable code |
| 77 | + |
| 78 | +## Note on `inc` Command |
| 79 | + |
| 80 | +Nushell's `inc` functionality for incrementing semantic version strings is now available as an official plugin: `nu_plugin_inc`. |
| 81 | + |
| 82 | +**Our implementation uses a hybrid approach:** |
| 83 | +1. First attempts to use `nu_plugin_inc` if installed |
| 84 | +2. Falls back to custom implementation if plugin is not available |
| 85 | + |
| 86 | +This provides the best of both worlds: |
| 87 | +- Uses official plugin when available (recommended) |
| 88 | +- Guarantees functionality even without the plugin |
| 89 | +- No manual configuration needed |
| 90 | + |
| 91 | +**To install the plugin:** |
| 92 | +```bash |
| 93 | +cargo install nu_plugin_inc |
| 94 | +nu -c "plugin add ~/.cargo/bin/nu_plugin_inc" |
| 95 | +``` |
| 96 | + |
| 97 | +See [NUSHELL_INC_COMMAND.md](./NUSHELL_INC_COMMAND.md) for complete details on plugin installation and usage. |
| 98 | + |
| 99 | +## Installation |
| 100 | + |
| 101 | +Nushell can be installed via: |
| 102 | +- Snap: `sudo snap install nushell --classic` |
| 103 | +- Cargo: `cargo install nu` |
| 104 | +- Package managers: See https://www.nushell.sh/book/installation.html |
| 105 | + |
| 106 | +## Compatibility |
| 107 | + |
| 108 | +Both Python and Nushell versions are maintained: |
| 109 | +- **Nushell** (`bump-version.nu`): Primary, recommended version |
| 110 | +- **Python** (`bump-version.py`): Legacy version for compatibility |
| 111 | + |
| 112 | +Both produce identical results and follow the same API. |
0 commit comments