-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Download and setup redistributable Python Interpreter from https://github.com/indygreg/python-build-standalone/ if needed ;)
- Loading branch information
Showing
13 changed files
with
877 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: setup-python | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.12", "3.11", "3.10", "3.9"] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: 'Set up Python ${{ matrix.python-version }}' | ||
uses: actions/setup-python@v5 | ||
# https://github.com/marketplace/actions/setup-python | ||
with: | ||
python-version: '${{ matrix.python-version }}' | ||
|
||
- name: 'Just call --help with Python v${{ matrix.python-version }}' | ||
run: | | ||
python3 manageprojects/setup_python.py --help | ||
- name: 'Call setup python script with Python v${{ matrix.python-version }}' | ||
env: | ||
PYTHONUNBUFFERED: 1 | ||
PYTHONWARNINGS: always | ||
run: | | ||
sudo python3 manageprojects/setup_python.py -vv | ||
- name: 'Test the installed interpreter' | ||
run: | | ||
$(python3 manageprojects/setup_python.py) -VV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# Boot Redistributable Python | ||
|
||
This is a standalone script (no dependencies) to download and setup | ||
https://github.com/indygreg/python-build-standalone/ redistributable Python interpreter. | ||
But only if it's needed! | ||
|
||
Minimal version to used this script is Python v3.9. | ||
|
||
The downloaded archive will be verified with the hash checksum. | ||
|
||
The download will be only done, if the system Python is not the same major version as requested | ||
and if the local Python is not up-to-date. | ||
|
||
## CLI | ||
|
||
The CLI interface looks like e.g.: | ||
|
||
```shell | ||
$ python3 setup_python.py --help | ||
|
||
usage: setup_python.py [-h] [-v] [--skip-temp-deletion] [--force-update] [major_version] | ||
|
||
Download and setup redistributable Python Interpreter from https://github.com/indygreg/python-build-standalone/ if | ||
needed ;) | ||
|
||
positional arguments: | ||
major_version Specify the Python version like: 3.10, 3.11, 3.12, ... (default: 3.12) | ||
|
||
options: | ||
-h, --help show this help message and exit | ||
-v, --verbose Increase verbosity level (can be used multiple times, e.g.: -vv) (default: 0) | ||
--skip-temp-deletion Skip deletion of temporary files (default: False) | ||
--force-update Update local Python interpreter, even if it is up-to-date (default: False) | ||
|
||
``` | ||
## Include in own projects | ||
There is a unittest base class to include `setup_python.py` script in your project. | ||
If will check if the file is up2date and if not, it will update it. | ||
Just include `manageprojects` as a dev dependency in your project. | ||
And add a test like this: | ||
```python | ||
class IncludeSetupPythonTestCase(IncludeSetupPythonBaseTestCase): | ||
# Set the path where the `setup_python.py` should be copied to: | ||
DESTINATION_PATH = Path(your_package.__file__).parent) / 'setup_python.py' | ||
# Just call the method in a test, it will pass, if the file is up2date: | ||
def test_setup_python_is_up2date(self): | ||
self.auto_update_setup_python() | ||
``` | ||
Feel free to do it in a completely different way, this is just a suggestion ;) | ||
## Workflow - 1. Check system Python | ||
If the system Python is the same major version as the required Python, we skip the download. | ||
The script just returns the path to the system Python interpreter. | ||
A local installed interpreter (e.g. in "~/.local") will be auto updated. | ||
## Workflow - 2. Collect latest release data | ||
We fetch the latest release data from the GitHub API: | ||
https://raw.githubusercontent.com/indygreg/python-build-standalone/latest-release/latest-release.json | ||
## Workflow - 3. Obtaining optimized Python distribution | ||
See: https://gregoryszorc.com/docs/python-build-standalone/main/running.html | ||
We choose the optimized variant based on the priority list: | ||
1. `pgo+lto` | ||
2. `pgo` | ||
3. `lto` | ||
For `x86-64` Linux we check the CPU flags from `/proc/cpuinfo` to determine the best variant. | ||
The "debug" build are ignored. | ||
## Workflow - 4. Check existing Python | ||
If the latest Python version is already installed, we skip the download. | ||
## Workflow - 4. Download and verify Archive | ||
All downloads will be done with a secure connection (SSL) and server authentication. | ||
If the latest Python version is already installed, we skip the download. | ||
Download will be done in a temporary directory. | ||
We download the archive file and the hash file for verification: | ||
* Archive extension: `.tar.zst` | ||
* Hash extension: `.tar.zst.sha256` | ||
We check the file hash after downloading the archive. | ||
## Workflow - 5. Add info JSON | ||
We add the file `info.json` with all relevant information. | ||
## Workflow - 6. Setup Python | ||
We add a shell script to `~/.local/bin/pythonX.XX` to start the Python interpreter. | ||
We display version information from Python and pip on `stderr`. | ||
The extracted Python will be moved to the final destination in `~/.local/pythonX.XX/`. | ||
The script set's the correct `PYTHONHOME` environment variable. | ||
## Workflow - 7. print the path | ||
If no errors occurred, the path to the Python interpreter will be printed to `stdout`. | ||
So it's usable in shell scripts, like: | ||
```shell | ||
#!/usr/bin/env sh | ||
set -e | ||
PY_313_BIN=$(python3 setup_python.py -v 3.13) | ||
echo "Python 3.13 used from: '${PY_313_BIN}'" | ||
set -x | ||
${PY_313_BIN} -VV | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
Manage Python / Django projects | ||
""" | ||
|
||
__version__ = '0.18.0' | ||
__version__ = '0.19.0' | ||
__author__ = 'Jens Diemer <[email protected]>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.