prop-cli 1.0.2__tar.gz → 1.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,256 @@
1
+ Metadata-Version: 2.4
2
+ Name: prop-cli
3
+ Version: 1.1.0
4
+ Summary: A command-line tool to solve proportions using the rule of three
5
+ Author-email: "Domenico Bruno \"Lobkowitz\"" <blobkowitz@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Lobko/prop-cli
8
+ Project-URL: Issues, https://github.com/Lobko/prop-cli/issues
9
+ Project-URL: Changelog, https://github.com/Lobko/prop-cli/blob/main/CHANGELOG.md
10
+ Keywords: proportion,rule of three,cross-multiplication,math,cli
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Education
14
+ Classifier: Intended Audience :: End Users/Desktop
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
24
+ Classifier: Topic :: Utilities
25
+ Requires-Python: >=3.10
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Dynamic: license-file
29
+
30
+ # prop-cli
31
+
32
+ [![PyPI version](https://img.shields.io/pypi/v/prop-cli)](https://pypi.org/project/prop-cli/)
33
+ [![Python Version](https://img.shields.io/pypi/pyversions/prop-cli)](https://pypi.org/project/prop-cli/)
34
+ [![License](https://img.shields.io/pypi/l/prop-cli)](https://github.com/Lobko/prop-cli/blob/main/LICENSE)
35
+ [![Downloads](https://img.shields.io/pypi/dm/prop-cli)](https://pypi.org/project/prop-cli/)
36
+ [![Tests](https://github.com/Lobko/prop-cli/actions/workflows/test.yml/badge.svg)](https://github.com/Lobko/prop-cli/actions/workflows/test.yml)
37
+ [![Lint](https://github.com/Lobko/prop-cli/actions/workflows/lint.yml/badge.svg)](https://github.com/Lobko/prop-cli/actions/workflows/lint.yml)
38
+ [![Build](https://github.com/Lobko/prop-cli/actions/workflows/build.yml/badge.svg)](https://github.com/Lobko/prop-cli/actions/workflows/build.yml)
39
+
40
+ A small command-line tool that solves proportions of the form
41
+
42
+ ```
43
+ a : b = c : d
44
+ ```
45
+
46
+ where one of the four terms is the unknown `x`.
47
+ It uses classic **cross-multiplication**, also known as the **rule of three**.
48
+
49
+ ```
50
+ $ prop-cli 10 12 x 30
51
+ Proportion: 10:12 = 25:30
52
+ x = 25
53
+ ```
54
+
55
+ ---
56
+
57
+ ## Installation
58
+
59
+ Requires Python 3.10 or newer. No other dependencies.
60
+
61
+ ```
62
+ pip install prop-cli
63
+ ```
64
+
65
+ or, to keep it isolated from your other Python packages:
66
+
67
+ ```
68
+ pipx install prop-cli
69
+ ```
70
+
71
+ Both install the `prop-cli` command.
72
+
73
+ ### Installing from source
74
+
75
+ ```
76
+ git clone https://github.com/Lobko/prop-cli
77
+ cd prop-cli
78
+ pip install .
79
+ ```
80
+
81
+ Use `pip install -e .` instead for an editable (development) install, so changes
82
+ to the source code take effect immediately without reinstalling.
83
+
84
+ ---
85
+
86
+ ## Usage
87
+
88
+ ```
89
+ prop-cli <a> <b> <c> <d>
90
+ prop-cli --help # or -h
91
+ prop-cli --version # or -V
92
+ ```
93
+
94
+ Write `x` (or `X`) for the unknown term. It can be in any position:
95
+
96
+ ```
97
+ prop-cli x 5 6 12 # x = 2.5
98
+ prop-cli 2 x 4 8 # x = 4
99
+ prop-cli 10 12 x 30 # x = 25
100
+ prop-cli 4 5 0.1 x # x = 0.125
101
+ ```
102
+
103
+ More examples:
104
+
105
+ ```
106
+ prop-cli 5 20 x 120 # x = 30
107
+ prop-cli x 4 12 48 # x = 1
108
+ prop-cli 3 x 9 15 # x = 5
109
+ prop-cli -4 2 x 3 # x = -6 (negative numbers work)
110
+ prop-cli 1e3 2 x 4 # x = 2000 (so does scientific notation)
111
+ ```
112
+
113
+ Results are shown in plain decimal notation (never `1e-05`), rounded to
114
+ 15 significant digits, so tiny floating-point errors disappear:
115
+
116
+ ```
117
+ prop-cli 1 3 x 1 # x = 0.333333333333333
118
+ prop-cli 0.1 1 x 3 # x = 0.3
119
+ ```
120
+
121
+ ### Errors and exit codes
122
+
123
+ Error messages are printed to **stderr**, so they don't mix with the result if
124
+ you redirect or pipe the output.
125
+
126
+ | Exit code | Meaning |
127
+ |-----------|------------------------------------------------------|
128
+ | `0` | Success (also for `--help` and `--version`) |
129
+ | `1` | The input is not a solvable proportion (see below) |
130
+ | `2` | Wrong number of arguments (the usage text is shown) |
131
+
132
+ Inputs that are rejected:
133
+
134
+ ```
135
+ prop-cli 1 2 3 4 # no 'x'
136
+ prop-cli x x 3 4 # more than one 'x'
137
+ prop-cli x abc 3 4 # not a number
138
+ prop-cli x 1 inf 4 # infinity / nan are not allowed
139
+ prop-cli x 0 3 2 # b = 0: a ratio like a:0 is undefined
140
+ prop-cli 1 2 x 0 # d = 0: same reason
141
+ prop-cli 1 x 0 5 # c = 0: no unique solution (division by zero)
142
+ prop-cli 0 2 3 x # a = 0: no unique solution (division by zero)
143
+ ```
144
+
145
+ ---
146
+
147
+ ## How cross-multiplication works
148
+
149
+ A proportion says that two ratios are equal:
150
+
151
+ ```
152
+ a c
153
+ ─ = ─
154
+ b d
155
+ ```
156
+
157
+ In `a : b = c : d`, the outer terms `a` and `d` are called the **extremes**
158
+ and the inner terms `b` and `c` are the **means**:
159
+
160
+ ```
161
+ ┌──── extremes ─────┐
162
+ a : b = c : d
163
+ └─means─┘
164
+ ```
165
+
166
+ **Rule:** the product of the extremes equals the product of the means.
167
+
168
+ ```
169
+ a × d = b × c
170
+ ```
171
+
172
+ Solving this equation for the unknown gives one formula per position:
173
+
174
+ | Unknown | Proportion | Formula |
175
+ |---------|-----------------|---------------------|
176
+ | `a` | `x : b = c : d` | `x = (b × c) / d` |
177
+ | `b` | `a : x = c : d` | `x = (a × d) / c` |
178
+ | `c` | `a : b = x : d` | `x = (a × d) / b` |
179
+ | `d` | `a : b = c : x` | `x = (b × c) / a` |
180
+
181
+ Worked example, `10 : 12 = x : 30`:
182
+
183
+ ```
184
+ x = (10 × 30) / 12 = 300 / 12 = 25
185
+ ```
186
+
187
+ ---
188
+
189
+ ## Using it from Python
190
+
191
+ The solver can also be imported:
192
+
193
+ ```python
194
+ from proportion_calculator.cli import ProportionError, solve
195
+
196
+ solve(["10", "12", "x", "30"]) # -> [10.0, 12.0, 25.0, 30.0]
197
+
198
+ try:
199
+ solve(["x", "0", "3", "2"])
200
+ except ProportionError as error:
201
+ print(error) # b cannot be 0: ...
202
+ ```
203
+
204
+ ---
205
+
206
+ ## Development
207
+
208
+ ```
209
+ git clone https://github.com/Lobko/prop-cli
210
+ cd prop-cli
211
+ pip install -e . pytest flake8
212
+
213
+ pytest # run the tests
214
+ flake8 proportion_calculator tests # run the linter
215
+ ```
216
+
217
+ The version number is kept only in `proportion_calculator/__init__.py`.
218
+ The packaging reads it from there.
219
+
220
+ GitHub Actions runs the tests on Python 3.10–3.14, plus the linter and a
221
+ package build check, on every push and pull request.
222
+
223
+ ### Project structure
224
+
225
+ ```
226
+ prop-cli/
227
+ ├── proportion_calculator/
228
+ │ ├── __init__.py # package version
229
+ │ └── cli.py # solver and command-line interface
230
+ ├── tests/
231
+ │ └── test_cli.py
232
+ ├── .github/workflows/
233
+ │ ├── test.yml
234
+ │ ├── lint.yml
235
+ │ └── build.yml
236
+ ├── pyproject.toml
237
+ ├── CHANGELOG.md
238
+ ├── LICENSE
239
+ └── README.md
240
+ ```
241
+
242
+ ---
243
+
244
+ ## Contributing
245
+
246
+ 1. Fork the repository
247
+ 2. Create a feature branch
248
+ 3. Commit your changes (with tests)
249
+ 4. Push the branch
250
+ 5. Open a Pull Request
251
+
252
+ ---
253
+
254
+ ## License
255
+
256
+ [MIT](https://github.com/Lobko/prop-cli/blob/main/LICENSE) © Domenico Bruno "Lobkowitz"
@@ -0,0 +1,227 @@
1
+ # prop-cli
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/prop-cli)](https://pypi.org/project/prop-cli/)
4
+ [![Python Version](https://img.shields.io/pypi/pyversions/prop-cli)](https://pypi.org/project/prop-cli/)
5
+ [![License](https://img.shields.io/pypi/l/prop-cli)](https://github.com/Lobko/prop-cli/blob/main/LICENSE)
6
+ [![Downloads](https://img.shields.io/pypi/dm/prop-cli)](https://pypi.org/project/prop-cli/)
7
+ [![Tests](https://github.com/Lobko/prop-cli/actions/workflows/test.yml/badge.svg)](https://github.com/Lobko/prop-cli/actions/workflows/test.yml)
8
+ [![Lint](https://github.com/Lobko/prop-cli/actions/workflows/lint.yml/badge.svg)](https://github.com/Lobko/prop-cli/actions/workflows/lint.yml)
9
+ [![Build](https://github.com/Lobko/prop-cli/actions/workflows/build.yml/badge.svg)](https://github.com/Lobko/prop-cli/actions/workflows/build.yml)
10
+
11
+ A small command-line tool that solves proportions of the form
12
+
13
+ ```
14
+ a : b = c : d
15
+ ```
16
+
17
+ where one of the four terms is the unknown `x`.
18
+ It uses classic **cross-multiplication**, also known as the **rule of three**.
19
+
20
+ ```
21
+ $ prop-cli 10 12 x 30
22
+ Proportion: 10:12 = 25:30
23
+ x = 25
24
+ ```
25
+
26
+ ---
27
+
28
+ ## Installation
29
+
30
+ Requires Python 3.10 or newer. No other dependencies.
31
+
32
+ ```
33
+ pip install prop-cli
34
+ ```
35
+
36
+ or, to keep it isolated from your other Python packages:
37
+
38
+ ```
39
+ pipx install prop-cli
40
+ ```
41
+
42
+ Both install the `prop-cli` command.
43
+
44
+ ### Installing from source
45
+
46
+ ```
47
+ git clone https://github.com/Lobko/prop-cli
48
+ cd prop-cli
49
+ pip install .
50
+ ```
51
+
52
+ Use `pip install -e .` instead for an editable (development) install, so changes
53
+ to the source code take effect immediately without reinstalling.
54
+
55
+ ---
56
+
57
+ ## Usage
58
+
59
+ ```
60
+ prop-cli <a> <b> <c> <d>
61
+ prop-cli --help # or -h
62
+ prop-cli --version # or -V
63
+ ```
64
+
65
+ Write `x` (or `X`) for the unknown term. It can be in any position:
66
+
67
+ ```
68
+ prop-cli x 5 6 12 # x = 2.5
69
+ prop-cli 2 x 4 8 # x = 4
70
+ prop-cli 10 12 x 30 # x = 25
71
+ prop-cli 4 5 0.1 x # x = 0.125
72
+ ```
73
+
74
+ More examples:
75
+
76
+ ```
77
+ prop-cli 5 20 x 120 # x = 30
78
+ prop-cli x 4 12 48 # x = 1
79
+ prop-cli 3 x 9 15 # x = 5
80
+ prop-cli -4 2 x 3 # x = -6 (negative numbers work)
81
+ prop-cli 1e3 2 x 4 # x = 2000 (so does scientific notation)
82
+ ```
83
+
84
+ Results are shown in plain decimal notation (never `1e-05`), rounded to
85
+ 15 significant digits, so tiny floating-point errors disappear:
86
+
87
+ ```
88
+ prop-cli 1 3 x 1 # x = 0.333333333333333
89
+ prop-cli 0.1 1 x 3 # x = 0.3
90
+ ```
91
+
92
+ ### Errors and exit codes
93
+
94
+ Error messages are printed to **stderr**, so they don't mix with the result if
95
+ you redirect or pipe the output.
96
+
97
+ | Exit code | Meaning |
98
+ |-----------|------------------------------------------------------|
99
+ | `0` | Success (also for `--help` and `--version`) |
100
+ | `1` | The input is not a solvable proportion (see below) |
101
+ | `2` | Wrong number of arguments (the usage text is shown) |
102
+
103
+ Inputs that are rejected:
104
+
105
+ ```
106
+ prop-cli 1 2 3 4 # no 'x'
107
+ prop-cli x x 3 4 # more than one 'x'
108
+ prop-cli x abc 3 4 # not a number
109
+ prop-cli x 1 inf 4 # infinity / nan are not allowed
110
+ prop-cli x 0 3 2 # b = 0: a ratio like a:0 is undefined
111
+ prop-cli 1 2 x 0 # d = 0: same reason
112
+ prop-cli 1 x 0 5 # c = 0: no unique solution (division by zero)
113
+ prop-cli 0 2 3 x # a = 0: no unique solution (division by zero)
114
+ ```
115
+
116
+ ---
117
+
118
+ ## How cross-multiplication works
119
+
120
+ A proportion says that two ratios are equal:
121
+
122
+ ```
123
+ a c
124
+ ─ = ─
125
+ b d
126
+ ```
127
+
128
+ In `a : b = c : d`, the outer terms `a` and `d` are called the **extremes**
129
+ and the inner terms `b` and `c` are the **means**:
130
+
131
+ ```
132
+ ┌──── extremes ─────┐
133
+ a : b = c : d
134
+ └─means─┘
135
+ ```
136
+
137
+ **Rule:** the product of the extremes equals the product of the means.
138
+
139
+ ```
140
+ a × d = b × c
141
+ ```
142
+
143
+ Solving this equation for the unknown gives one formula per position:
144
+
145
+ | Unknown | Proportion | Formula |
146
+ |---------|-----------------|---------------------|
147
+ | `a` | `x : b = c : d` | `x = (b × c) / d` |
148
+ | `b` | `a : x = c : d` | `x = (a × d) / c` |
149
+ | `c` | `a : b = x : d` | `x = (a × d) / b` |
150
+ | `d` | `a : b = c : x` | `x = (b × c) / a` |
151
+
152
+ Worked example, `10 : 12 = x : 30`:
153
+
154
+ ```
155
+ x = (10 × 30) / 12 = 300 / 12 = 25
156
+ ```
157
+
158
+ ---
159
+
160
+ ## Using it from Python
161
+
162
+ The solver can also be imported:
163
+
164
+ ```python
165
+ from proportion_calculator.cli import ProportionError, solve
166
+
167
+ solve(["10", "12", "x", "30"]) # -> [10.0, 12.0, 25.0, 30.0]
168
+
169
+ try:
170
+ solve(["x", "0", "3", "2"])
171
+ except ProportionError as error:
172
+ print(error) # b cannot be 0: ...
173
+ ```
174
+
175
+ ---
176
+
177
+ ## Development
178
+
179
+ ```
180
+ git clone https://github.com/Lobko/prop-cli
181
+ cd prop-cli
182
+ pip install -e . pytest flake8
183
+
184
+ pytest # run the tests
185
+ flake8 proportion_calculator tests # run the linter
186
+ ```
187
+
188
+ The version number is kept only in `proportion_calculator/__init__.py`.
189
+ The packaging reads it from there.
190
+
191
+ GitHub Actions runs the tests on Python 3.10–3.14, plus the linter and a
192
+ package build check, on every push and pull request.
193
+
194
+ ### Project structure
195
+
196
+ ```
197
+ prop-cli/
198
+ ├── proportion_calculator/
199
+ │ ├── __init__.py # package version
200
+ │ └── cli.py # solver and command-line interface
201
+ ├── tests/
202
+ │ └── test_cli.py
203
+ ├── .github/workflows/
204
+ │ ├── test.yml
205
+ │ ├── lint.yml
206
+ │ └── build.yml
207
+ ├── pyproject.toml
208
+ ├── CHANGELOG.md
209
+ ├── LICENSE
210
+ └── README.md
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Contributing
216
+
217
+ 1. Fork the repository
218
+ 2. Create a feature branch
219
+ 3. Commit your changes (with tests)
220
+ 4. Push the branch
221
+ 5. Open a Pull Request
222
+
223
+ ---
224
+
225
+ ## License
226
+
227
+ [MIT](https://github.com/Lobko/prop-cli/blob/main/LICENSE) © Domenico Bruno "Lobkowitz"