I have a large code base that contains many plugins. Each plugin has its own docker file. I have written some shell and python files that iterate through the plugin directories and create docker images for each of them.
Now I have to convert this project into a pip installable Python package. The setup scripts must be executed when the user installs the package via the wheel file.
I have tried using the setup.py file. But, it only gets executed once when the package is packed into a wheel file.
Below is my project structure:
doraemonsay-project$ tree
.
├── doraemonsay
│ ├── doraemon.py
│ ├── __main__.py
│ └── resources
│ └── DORAEMON
├── MANIFEST.in
├── pyproject.toml
└── setup.sh
2 directories, 6 files
pyproject.toml
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
[project]
name = "doraemonsay"
version = "1.0.0"
[project.scripts]
doraemonsays = "doraemonsay.__main__:main"
[tool.setuptools]
include-package-data = true
MANIFEST.in
include doraemonsay/resources/*
setup.sh
echo "Create docker images..."
doraemonsay/doraemon.py
#!/usr/bin/python3
import os
from sys import path as sys_path
import pkg_resources
resource_path = "resources/DORAEMON"
doraemon_path = pkg_resources.resource_filename(__name__, resource_path)
def bubble(message):
bubble_length = len(message) + 3
return f"""
{"_" * bubble_length}
( {message} )
{"‾" * bubble_length}"""
def fetch_message(path):
"""Read text file and return its contents."""
cwd = os.getcwd()
print(f"cwd: {cwd}")
print(f"sys_path: {sys_path}")
with open(path) as f:
return f.read()
def say(message):
DORAEMON = fetch_message(doraemon_path)
message = "Hello Guys, I am doraemon. " + message
print(bubble(message))
print(DORAEMON)
doraemonsay/__main__.py
#!/usr/bin/python3
import sys
from doraemonsay import doraemon
def say():
doraemon.say(" ".join(sys.argv[1:]))
def main():
say()
if __name__ == '__main__':
main()
doraemonsay/resources/DORAEMON
⠀⠀⠀⠀⠀⠀⠀⠀\
⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣤⣤⣴⠶⠶⠶⠶⣶⣶⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀⠀⠀⠀⠀⠀⢀⣠⡤⢴⣿⠿⠯⠤⠤⣤⣀⠀⠀⠀⠀⢀⣴⠟⠛⠉⠙⠛⢿⣛⠦⣤
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\⠀⣠⡴⠖⠋⢉⡴⠋⠁⠀⠀⠀⠀⠀⠉⠳⣄⢀⣼⠋⠀⠀⠀⠀⠀⠀⠀⠙⢧⡀⠉⠓⢶⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡴⠚⠉⠀⠀⢠⡟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠨⣷⠀⠀⠀⠈⠛⢦⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣠⡾⠋⠀⠀⠀⠀⠀⣿⠃⠀⠀⠀⠀⠀⠀⠀⣀⣀⠀⠀⢿⠀⠀⣀⣀⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠙⢷⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢠⡾⠋⠀⠀⠀⠀⠀⠀⢰⡟⠀⠀⠀⠀⠀⠀⠀⢸⣿⠿⣿⠀⣼⡀⢸⣿⠿⣿⠀⠀⠀⠀⠀⠀⢀⣧⡄⠀⠀⠀⠀⠀⠀⠙⢶⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⡼⠋⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⡀⠀⠀⠀⠀⠀⠀⠘⢿⡿⠿⠀⣼⣇⠘⢿⡿⠿⠀⠀⠀⠀⠀⠀⢸⡟⠳⠦⢤⣀⡀⠀⠀⠀⠀⠹⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢀⡾⠃⠀⠀⠀⠀⠀⠀⢀⣠⠶⠒⠛⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣹⣦⡀⠀⠀⠀⠀⠀⠀⠀⣰⠞⠁⠀⠀⠀⠈⠙⠦⣀⠀⠀⠀⠘⢧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⣾⠁⠀⠀⠀⠀⢀⡤⠚⠋⠀⠀⠀⠀⠈⠳⢤⣀⠀⠀⠀⢀⣠⣴⣿⣿⣿⣿⣍⠛⣦⣤⣤⣤⣤⡤⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠈⣳⣤⠄⠀⠈⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⣸⠁⠀⠀⠀⠀⡴⠿⠦⣄⣀⡀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠉⠉⠁⣸⠇⢸⣿⣿⡿⠀⠈⣇ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡤⠖⠊⠁⠘⣆⠀⠀⠘⣆⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢀⡏⠀⠀⠀⢠⡞⠀⠀⠀⠀⠈⠙⠓⠦⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣧⠀⠈⠉⠀⠀⣴⡇⠀⠀⠀⠀⠀⠀⢀⣠⡴⠒⠋⠁⠀⠀⠀⠀⠀⠈⢧⠀⠀⢿⠀⠀⠀⠀⠀⠀⠀⠀
⠀⣸⠀⠀⠀⢠⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠳⠦⠄⠀⠀⠀⠀⠙⠿⢤⣤⣤⠿⠋⠀⠀⠀⠀⠀⠠⠞⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣧⠀⢸⡄⠀⠀⠀⠀⠀⠀⠀
⢠⣿⠀⠀⢀⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣸⡆⠀⡇⠀⠀⠀⠀⠀⠀⠀
⢸⡇⠀⠀⣾⠁⡤⠤⠤⠤⠤⠤⠤⠤⠤⣤⣤⣤⣤⣤⣤⠄⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠓⠒⠒⠛⠛⠛⠋⠉⠉⢉⡉⠁⠀⠈⣇⠀⡇⠀⠀⠀⠀⠀⠀⠀
⠸⡇⠀⠀⣯⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠃⠀⠀⠀⡿⠀⡇⠀⠀⠀⠀⠀⠀⠀
⠀⣿⠀⠀⣿⠀⠀⠀⠀⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣀⣀⣀⡀⠀⠀⣰⠃⠀⠀⠀⢀⡇⢀⡇⠀⠀⠀⠀⠀⠀⠀
⠀⢹⠀⠀⣿⠀⠀⠀⠀⠈⢷⡀⠀⠀⢀⣀⣀⣀⠤⠤⠶⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⣹⠟⠛⠛⠛⠛⢻⠁⢸⠇⠀⠀⠀⠀⠀⠀⠀
⠀⠸⡆⠀⢿⡀⠀⢀⣤⣤⠾⢷⣞⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⠋⠀⠀⠀⠀⠀⣾⠀⣼⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠈⣷⠀⠘⡇⠀⠁⠀⠀⠀⠀⠘⢷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡼⠃⠀⠀⠀⠀⠀⢰⡏⢠⡏⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠛⡆⠀⢹⡄⠀⠀⠀⠀⠀⠀⠀⠙⣿⣿⣿⣿⣿⣷⣶⣶⣶⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣤⣶⣶⣶⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⢠⡞⢀⡾⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢻⡀⠀⢳⡀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠞⠁⠀⠀⠀⠀⠀⠀⠀⡼⢃⣼⠃⠀⣠⠤⠒⠲⠤⣄⠀⠀
⠀⠀⠀⠀⢳⡄⠀⢳⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⣼⢃⣾⠃⢀⡞⠁⠀⠀⠀⠀⠈⠳⣆
⠀⠀⠀⠀⠀⠹⣆⠀⠙⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣧⡞⣀⡟⠀⠀⠀⠀⠀⠀ ⠀⢸
⠀⠀⠀⠀⠀⠀⠈⢷⣀⠈⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣷⡿⠾⠋⠉⣇⠀⠀⠀⠀⠀⠀⠀⠀⣴
⠀⠀⠀⠀⠀⠀⠀⠀⠙⢶⡀⠳⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣾⡵⠋⠀⠀⠀⠀⠻⡄⠀⠀⠀⠀⠀⠀ ⠞
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣽⢧⣈⡳⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣀⣀⣤⣤⣤⠶⠿⢺⣷⠀⠀⠀⠀⠀⠀⠙⢲⡤⣀⣀⡤ ⠚⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣄⡉⠉⠉⠉⠓⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⣲⠶⠶⠶⠶⣖⠚⠛⠉⠉⠉⠉⠉⠁⠀⢀⣀⣠⠾⠃⠀⠀⠀⠀⠀⠀⣠⠿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡞⠉⠉⠛⠓⠲⠤⢤⣤⣄⣀⣀⣀⣀⣀⣀⣀⢀⣠⡾ ⣷⣤⣤⡤⢶⡖⠒⠒⠛⠋⠉⠀⠀⠀⠀⠀⠀⠀⢀⣴⠋⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣠⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⣨⠿⠋⠁⠀⠀⠉⠉⢙⣿⠷⠞⠛⠛⠛⠛⠳⠮⣿⠀⠀⠀⠉⠳⡄⠀⠀⠀⠈⣷⠀⠀⠀⢀⣰⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢠⡟⠀⠀⠀⠀⠀⠀⠀⢀⡴⠋⠁⠀⠀⠀⠀⠀⠀⠀⠘⢧⠀⠀⠀⣼⣷⡶ ⡿⠀⠀⠀⠀⠀⠙⣦⠀⠀⠀⢸⠀⠀⣠⠞⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢰⡿⠀⠀⠀⠀⠀⠀⠀⢀⡾⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢧⡀⠀⠀⡟⠀⣠⡞⠀⠀⠀⠀⠀⠀⠀⠈⣧⡀⠀⢸⣦⠞⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⢠⣾ ⠀⠀⠀⢰⠀⠀⠀⣾⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⠒⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣇⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⢸⢻ ⠀⠀⠀⢸⠀⠀⠀⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠘⢾ ⠀⠀⠀⢹⡆⠀⠀⡇⠀⠀⠰⣶⠶⠶⠶⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠚⠋⠉⠉⣿⠀⠀⢸⠇⢸⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠻⣦⠀⠀⢸⠇⠀⠀⡇⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⡼⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠈⠳⣄⣸⡇⠀ ⢿⡀⠀⠀⢻⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠇⠀⢰⡇⠀⣾⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢻⡇⠀⠀⠈⢷⡀⠀⠀⢻⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⠏⠀⢀⡟⠀⢠⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢠⣴⠟⠛⠛⢲⡄⠀⢸⡇⠀⠀⠀⠈⠳⣄⠀⠀⠙⠦⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⠞⠃⠀⣠⠟⠀⠀⣸⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⣾ ⣿⠀⠀⠀⣿⠶⢿⠁⠀⠀⠀⠀⠀⠈⠳⣄⡀⠀⠈⠙⠲⠦⠤⣀⣀⣀⣀⣀⣀⡤⠤⠶⠚⠉⠀⠀⣠⠞⠁⠀⠀⢰⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠙⣿⡀⠀⠀⢀⡟⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠦⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⠴⠚⠁⠀⠀⠀⢀⡞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠈⠙⠛⠛⠉⠀⢀⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠳⠶⠤⠤⢤⡤⠤⠤⠴⠖⠛⠉⠀⠀⠀⠀⠀⠀⠀⣾⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣴⠿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⣽⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢠⣶⠞⠉⠉⠁⠈⠙⢦⣤⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣼⡍⠙⠒⠶⠶⠶⢤⣤⡴⠶⠶⠶⠒⠚⠙⠶⢦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢿⡄ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣻⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠈⠻⣆⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⠶⠻⢦⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⡤⠾⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠈⠙⠳⠶⠦⠤⠤⠤⠤⠤⠤⠤⠤⠶⠶⠚⠛⠋⠉⠀⠀⠀⠀⠀⠀⠉⠉⠉⠉⠙⠛⠛⠛⠛⠋⠉⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀