Skip to content

Commit

Permalink
RHOAIENG-11216: Add script to automate the creation of a new Python-b…
Browse files Browse the repository at this point in the history
…ased 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
  • Loading branch information
caponetto authored Aug 15, 2024
1 parent d46ea66 commit c8c942b
Show file tree
Hide file tree
Showing 2 changed files with 589 additions and 0 deletions.
29 changes: 29 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,32 @@ Update the `pandas` library to version `2.2.2` in all files under `./myproject`
./update_library_version.sh ./myproject pandas 2.2.2 'include|this' 'exclude|that' false
```

## new_python_based_image.py

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:

1. Copy Folder: Duplicates the specified folder structure.
1. Update Python Versions: Replaces occurrences of the source Python version with the target version throughout the folder.
1. Update Lock Files: Executes `pipenv lock` to regenerate lock files based on the new Python version.

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.

### Examples

Create a Python 3.12 version based on the Python 3.9 version for each one that is in the `./base` directory:

```sh
python scripts/new_python_based_image.py --context-dir . --source 3.9 --target 3.12 --match ./base
```

Create a Python 3.11 version based on the Python 3.9 versions for each one that is in the `./jupyter/rocm` directory:

```sh
python scripts/new_python_based_image.py --context-dir . --source 3.9 --target 3.11 --match ./jupyter/rocm
```

Create a Python 3.11 version based on the Python 3.9 version for each one in the repository with `DEBUG` logs enabled:

```sh
python scripts/new_python_based_image.py --context-dir . --source 3.9 --target 3.11 --match ./ --log-level DEBUG
```
Loading

0 comments on commit c8c942b

Please sign in to comment.