This bash script automates the process of creating a Python module, including the module structure and necessary files. The script allows the user to define the module name, target directory, and additional directory imports using Zenity dialogs.
- Zenity (for dialog prompts)
- Python 3
-
Ensure Zenity is installed on your system. If not, install it using the package manager for your distribution. For example, on Ubuntu, you can use
sudo apt-get install zenity
. -
Save the provided bash script to a file, e.g.,
create_module.sh
. -
Make the script executable by running
chmod +x create_module.sh
. -
Run the script using
./create_module.sh
. Follow the prompts to define the module name, target directory, and additional directory imports (if any).
-
Checks if Zenity is installed. If not, it displays an error message and exits.
-
Asks the user for the module name using a Zenity dialog.
-
Prompts the user to choose the target directory for the module using a Zenity file selection dialog.
-
Creates the module structure, including the main module file,
__init__.py
,components
directory, andall_functions
directory. -
Asks the user if they want to add additional directory imports. If yes, it prompts the user to select the directories using Zenity file selection dialogs.
-
Generates the main module file (
<module_name>.py
), which includes a function to import all modules from a folder, import components, import additional directories (if specified), save function lists, and find duplicate functions. -
Generates a
setup.py
file for the module, including the package name, version, and entry points. -
Changes to the module directory and runs
python3 setup.py develop --user
to install the module in development mode.
The script creates a Python module with the following structure:
<target_dir>/
<module_name>/
__init__.py
<module_name>.py
setup.py
components/
all_functions/
all_modules.json
all_functions.json
all_function_duplicates.json
The generated module can be imported and used in other Python projects.