Skip to content

Commit 1d62783

Browse files
authored
Restructure README contents (#225)
* Restructure README contents * Fix format * Fix URL to demo
1 parent dc36b2a commit 1d62783

File tree

2 files changed

+161
-30
lines changed

2 files changed

+161
-30
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@
5050
- [ ] The code change is tested and works locally.
5151
- [ ] Local tests pass.
5252
- [ ] There is no commented out code in this PR.
53-
- [ ] The code has been formatted using Black (`make black`)
53+
- [ ] The code has been formatted using Black (`make lint`)
5454
- [ ] Tests have been added to verify that the new code works.
5555

README.md

Lines changed: 160 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,88 +48,216 @@ print(AwesomeVersion("1.2.0").in_range("1.2.1", "1.3"))
4848

4949
</details>
5050

51-
## Example usage
51+
<details>
52+
<summary><code>AwesomeVersion.diff</code></summary>
5253

53-
These are some examples of what you can do, more examples can be found in the `tests` directory.
54+
This is a helper method to get the difference between two versions.
55+
This method takes one argument which is the version to compare against, and returns a `AwesomeVersionDiff` object.
56+
57+
> **Note** This method is the same as doing `AwesomeVersion - version`
58+
59+
Example:
5460

5561
```python
5662
from awesomeversion import AwesomeVersion
63+
> print(AwesomeVersion("1.0").diff("2.1"))
64+
AwesomeVersionDiff(major=True, minor=True, patch=False, modifier=False, strategy=False)
65+
```
5766

58-
current = AwesomeVersion("1.2.2")
59-
upstream = AwesomeVersion("1.2.3")
67+
</details>
6068

61-
print(upstream > current)
62-
> True
69+
70+
<details>
71+
<summary><code>AwesomeVersion.section</code></summary>
72+
73+
This is a helper method to get a section of the version.
74+
This method takes one argument which is the section to get, and returns an integer representing it (or 0 if it does not exist).
75+
76+
Example:
77+
78+
```python
79+
from awesomeversion import AwesomeVersion
80+
> print(AwesomeVersion("1.0").section(0))
81+
1
6382
```
6483

84+
</details>
85+
86+
87+
## AwesomeVersion properties
88+
89+
Argument | Description
90+
--- | ---
91+
`alpha` | This is a boolean representing if the version is an alpha version.
92+
`beta` | This is a boolean representing if the version is a beta version.
93+
`dev` | This is a boolean representing if the version is a dev version.
94+
`major` | This is an `AwesomeVersion` object representing the major version or `None` if not present.
95+
`micro` | This is an `AwesomeVersion` object representing the micro version or `None` if not present.
96+
`minor` | This is an `AwesomeVersion` object representing the minor version or `None` if not present.
97+
`modifier_type` | This is a string representing the modifier type of the version or `None` if not present.
98+
`modifier` | This is a string representing the modifier of the version or `None` if not present.
99+
`patch` | This is an `AwesomeVersion` object representing the patch version or `None` if not present.
100+
`prefix` | This is the prefix of the version or `None` if not present.
101+
`release_candidate` | This is a boolean representing if the version is a release candidate version.
102+
`simple` | This is a boolean representing if the version is a simple version.
103+
`strategy_description` | This is a `AwesomeVersionStrategyDescription` object representing the strategy description of the version.
104+
`strategy` | This is a `AwesomeVersionStrategy` object representing the strategy of the version.
105+
`string` | This is the string representation of the version (without the v prefix if present).
106+
`valid` | This is a boolean representing if the version is valid (not unknown strategy).
107+
`year` | This is alias to `major`, and is an `AwesomeVersion` object representing the year.
108+
109+
110+
## Example usage
111+
112+
Here are some examples of how you can use this package, more examples can be found in the `tests` directory.
113+
114+
<details>
115+
<summary><code>Basic compare</code></summary>
116+
65117
```python
66118
from awesomeversion import AwesomeVersion
67119

68-
version = AwesomeVersion("1.2.3b0")
120+
current = AwesomeVersion("1.2.2")
121+
upstream = AwesomeVersion("1.2.3")
69122

70-
print(version.beta)
123+
print(upstream > current)
71124
> True
72125
```
73126

127+
</details>
128+
129+
<details>
130+
<summary><code>Compare beta version</code></summary>
131+
74132
```python
75133
from awesomeversion import AwesomeVersion
76134

77135
current = AwesomeVersion("2021.1.0")
78136
upstream = AwesomeVersion("2021.1.0b2")
79137

80-
print(upstream > current)
81-
> False
138+
print(current > upstream)
139+
> True
82140
```
83141

142+
</details>
143+
144+
<details>
145+
<summary><code>Check if version is a beta version</code></summary>
146+
84147
```python
85148
from awesomeversion import AwesomeVersion
86149

87-
current = AwesomeVersion("latest")
88-
upstream = AwesomeVersion("2021.1.0")
150+
print(AwesomeVersion("1.2.3b0").beta)
151+
> True
89152

90-
print(upstream > current)
153+
print(AwesomeVersion("1.2.3").beta)
91154
> False
92155
```
93156

157+
</details>
158+
159+
<details>
160+
<summary>Use <code>AwesomeVersion</code> with <code>with ...</code></summary>
161+
94162
```python
95163
from awesomeversion import AwesomeVersion
96164

97-
current = AwesomeVersion("latest")
98-
upstream = AwesomeVersion("dev")
99-
100-
print(upstream > current)
165+
with AwesomeVersion("20.12.0") as current:
166+
with AwesomeVersion("20.12.1") as upstream:
167+
print(upstream > current)
101168
> True
102169
```
103170

171+
</details>
172+
173+
<details>
174+
<summary>Compare <code>AwesomeVersion</code> with other non-<code>AwesomeVersion</code> formats</summary>
175+
104176
```python
105177
from awesomeversion import AwesomeVersion
106178

107-
with AwesomeVersion("20.12.0") as current:
108-
with AwesomeVersion("20.12.1") as upstream:
109-
print(upstream > current)
179+
base = AwesomeVersion("20.12.0")
180+
181+
print(base > "20.12.1")
182+
> False
183+
184+
print(base > "19")
185+
> True
186+
187+
print(base > 5)
110188
> True
111189
```
112190

191+
</details>
192+
193+
194+
## General behavior
195+
196+
You can test your versions on the [demo page][awesomeversion_demo].
197+
198+
### Modifiers
199+
200+
When comparing versions with modifiers, if the base version is the same the modifier will be used to determine the order.
201+
If one of the versions do not have a modifier, the one without will be considered newer.
202+
203+
The order of the modifiers are:
204+
- No modifier
205+
- RC
206+
- Beta
207+
- Alpha
208+
- Dev
209+
210+
<details>
211+
<summary>Examples</summary>
212+
113213
```python
114214
from awesomeversion import AwesomeVersion
115215

116-
with AwesomeVersion("20.12.0") as current:
117-
print("2020.12.1" > current)
216+
print(AwesomeVersion("1.0.0") > AwesomeVersion("1.0.0b6"))
217+
> True
218+
print(AwesomeVersion("1.0.0") > AwesomeVersion("1.0.0.dev6"))
118219
> True
220+
print(AwesomeVersion("1.0.0.dev19") > AwesomeVersion("1.0.0b4"))
221+
> False
119222
```
120223

224+
</details>
225+
226+
227+
### Special versions (container)
228+
229+
There are some special versions for container that are handled differently than typical version formats.
230+
The special versions are in the following order:
231+
- `dev` (newest)
232+
- `latest`
233+
- `beta`
234+
- `stable` (oldest)
235+
236+
If only the first version is this special version, it will be considered newer.
237+
If only the second version is this special version, it will be considered older.
238+
239+
240+
<details>
241+
<summary>Examples</summary>
242+
121243
```python
122244
from awesomeversion import AwesomeVersion
123245

124-
version = AwesomeVersion("2.12.0")
125-
print(version.major)
126-
> 2
127-
print(version.minor)
128-
> 12
129-
print(version.patch)
130-
> 0
246+
print(AwesomeVersion("latest") > AwesomeVersion("1.0.0b6"))
247+
> True
248+
print(AwesomeVersion("1.0.0") > AwesomeVersion("latest"))
249+
> False
250+
print(AwesomeVersion("stable") > AwesomeVersion("latest"))
251+
> False
252+
print(AwesomeVersion("beta") > AwesomeVersion("dev"))
253+
> False
131254
```
132255

256+
</details>
257+
258+
259+
260+
133261
## Contribute
134262

135263
**All** contributions are welcome!
@@ -142,3 +270,6 @@ print(version.patch)
142270
6. Ensure 100% coverage with `make coverage`
143271
7. Commit your work, and push it to GitHub
144272
8. Create a PR against the `main` branch
273+
274+
275+
[awesomeversion_demo]: https://ludeeus.github.io/awesomeversion/

0 commit comments

Comments
 (0)