Extract Version
Python module for extracting version from the string or directory name. Could make use for creating an inventory of installed versions of a particular application or finding the latest installed version.
The module offers the following functionality:
- Fetching version string from the string or name of the directory
- Validating version string
- Sorting config and application directories that contain versions in its name
Installation
The package can be installed from pip
pip install extract-version
There are archives of previous releases available on Github with the mirror on AWS
Examples:
- We fetch version
2020.1.0from stringPyCharm-2020.1.0, or version1.0frommy_program_v1.0
AppVersion.Major.Minorversion format
extract_version(version_string="PyCharm-2020.1.0")
> "2020.1.0"
Major.Minorversion format
extract_version(version_string="my_program_v1.0")
> "1.0"
- Sort directories by the version of application
sort_versions(["PyCharm-2018.1.2", "PyCharm-2018.2.0", "PyCharm-2020.1.0"])
> ["PyCharm-2018.1.2", "PyCharm-2018.2.0", "PyCharm-2020.1.0"]
- In edge cases with more than one pattern present, e.g.
PyCharm-2018.1.2-windows-10.0, we should provide a clue where the version should be extracted from, in a form of a pattern-regex, e.g.PyCharm-(.*)-windows-10.0The call of such function may look like this:
extract_version(version_string='PyCharm-2018.1.2-windows-10.0', pattern='PyCharm-(.*)-windows-10.0')
> "2018.1.2"
- Create an inventory of installed versions of a particular application
application_path = "C:/Users/user/AppData/Local/JetBrains/PyCharm"
pycharm_versions = available_versions(versions_path=application_path)
> {"2018.1.2": "PyCharm-2018.1.2", "2018.2.0": "PyCharm-2018.2.0", "2020.1.0": "PyCharm-2020.1.0"}
Command line
Installing the package also provides an extract-version command (equivalently, python -m extract_version)
exposing the same functionality from the shell. Every subcommand also reads its input from stdin when no
arguments are given, so it composes with tools like ls/find.
extract-version extract "PyCharm-2020.1.0"
> 2020.1.0
extract-version extract "PyCharm-2018.1.2-windows-10.0" --pattern "PyCharm-(.*)-windows-10.0"
> 2018.1.2
extract-version sort 2018.1.2 2018.2.0 2020.1.0
> 2018.1.2
> 2018.2.0
> 2020.1.0
ls "C:/Users/user/AppData/Local/JetBrains/PyCharm" | extract-version last-version --pattern "PyCharm-(.*)"
> PyCharm-2020.1.0
extract-version available --path "C:/Users/user/AppData/Local/JetBrains/PyCharm" --json
> {"2018.1.2": "PyCharm-2018.1.2", "2018.2.0": "PyCharm-2018.2.0", "2020.1.0": "PyCharm-2020.1.0"}
Run extract-version --help or extract-version <subcommand> --help for the full option list.
Releasing
release_package.py builds and installs the wheel locally, and can optionally publish it via
--upload-s3, --create-release (GitHub), and --publish-pypi. Each of those needs its own
external tool and credentials, installed and configured beforehand:
| Flag | Tool | Credentials |
|---|---|---|
--upload-s3 |
aws |
aws configure (or an AWS_PROFILE/instance role) |
--create-release |
gh |
gh auth login |
--publish-pypi |
twine |
a PyPI API token in ~/.pypirc |
Run python scripts/install_deps.py to install aws, gh, and twine (cross-platform:
pip-installs awscli/twine everywhere, and uses Homebrew/winget/apt for gh where available).
It does not set up credentials — do that with the commands in the table above.
If a tool or its credentials aren't ready when release_package.py reaches that step, the step
reports itself unavailable and the run rolls back every step already completed (deletes the S3
object, the git tag, and/or the GitHub release, in that order) before exiting — see
ReleaseStep/run_release_pipeline() in release_package.py.
Metadata
Release files for extract-version 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| extract_version-1.2.0.tar.gz | 10.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| extract_version-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.5 kB
Release files / extract_version-1.2.0.tar.gz
| Download URL | extract_version-1.2.0.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26ced557b0c59fa6012c35bfbe6bfce365edde39b2800fa4da4acf19b415d23a
|
|
BLAKE2b-256 checksum How to use checksums |
2ad894177ddd6a481d89dd4e56a07198219e2b67d34ecb845ee208ae67487283
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / extract_version-1.2.0-py3-none-any.whl
| Download URL | extract_version-1.2.0-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
549ae52495c604b00f145889defd68db16d26809cdd71a2f5435b96b9a3bdc2d
|
|
BLAKE2b-256 checksum How to use checksums |
a41f740c396ca9a93e83baca45ffda2a3bf40affe0a3cc5b6c9157a6eae7ffe3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for extract-version 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.