potiuk commented on pull request #21145:
URL: https://github.com/apache/airflow/pull/21145#issuecomment-1025647705
> @potiuk Can you explain to me what's happening in this code part? Couldn't
decipher what this regex part is doing?
Bash and printf magic combined :) (and one reason why we want to get rid of
it because not many people can figure it out.
1) The `${1//[.-]/ }` splits the parameter with "." and "-" separators
* "2.20.1" -> "2" "20" "1"
* "2.2.1" -> "2" "2" "1"
* "2.20.1-azure" -> "2" "20" "1" "azure"
2) `Printf "%03d%03d%03d%.0s"` formats the number to get them into
comparable number, no matter what length the "numbers" are (below 4) and
removes the "string" (the `%.0s` produces empty string always - no matter what
was the argument).
```
printf "%03d%03d%03d%.0s" "2" "20" "1" -> 002020001
printf "%03d%03d%03d%.0s" "2" "2" "1" -> 002002001
printf "%03d%03d%03d%.0s" "2" "20" "1" "azure" -> 002020001
```
This way we can simply compare two versions using bash arithmetics `$(( ver1
< ver2 ))` - because those are properly comparable numbers (2.2.1 < 2.20.1) and
(2.20.1-azure == 2.20.1).
In Python we can I think use `semver` library to make the comparision (but
we have to see if numbers with `-azure` suffix
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]