Skip to content

Commit c8c942b

Browse files
authored
RHOAIENG-11216: Add script to automate the creation of a new Python-based image from an existing one (#672)
* Add script to automate the creation of a new Python-based image from an existing one * Add type annotations to function args * Add missing folders to blocklist * Removing redundant comment * Use dataclass in the Args class * Use context manager for logged_execution * Set encoding prop on subprocess.run * Improve log level help message * Return non-zero code for non-happy scenarios * Add type annotations to function return * Final adjustments * Code review request
1 parent d46ea66 commit c8c942b

File tree

2 files changed

+589
-0
lines changed

2 files changed

+589
-0
lines changed

scripts/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,32 @@ Update the `pandas` library to version `2.2.2` in all files under `./myproject`
1818
./update_library_version.sh ./myproject pandas 2.2.2 'include|this' 'exclude|that' false
1919
```
2020

21+
## new_python_based_image.py
22+
23+
This Python script generates a new folder structure for a Python-based project by copying an existing one and updating Python version references. It performs the following steps:
24+
25+
1. Copy Folder: Duplicates the specified folder structure.
26+
1. Update Python Versions: Replaces occurrences of the source Python version with the target version throughout the folder.
27+
1. Update Lock Files: Executes `pipenv lock` to regenerate lock files based on the new Python version.
28+
29+
If `pipenv lock` encounters errors, manual intervention is required to resolve compatibility issues between dependencies. Review the errors reported by `pipenv` and adjust the dependencies as needed.
30+
31+
### Examples
32+
33+
Create a Python 3.12 version based on the Python 3.9 version for each one that is in the `./base` directory:
34+
35+
```sh
36+
python scripts/new_python_based_image.py --context-dir . --source 3.9 --target 3.12 --match ./base
37+
```
38+
39+
Create a Python 3.11 version based on the Python 3.9 versions for each one that is in the `./jupyter/rocm` directory:
40+
41+
```sh
42+
python scripts/new_python_based_image.py --context-dir . --source 3.9 --target 3.11 --match ./jupyter/rocm
43+
```
44+
45+
Create a Python 3.11 version based on the Python 3.9 version for each one in the repository with `DEBUG` logs enabled:
46+
47+
```sh
48+
python scripts/new_python_based_image.py --context-dir . --source 3.9 --target 3.11 --match ./ --log-level DEBUG
49+
```

0 commit comments

Comments
 (0)