Skip to content

Commit

Permalink
Merge pull request modoboa#523 from modoboa/dynamic-requirements
Browse files Browse the repository at this point in the history
Fetch requirements dynamically
  • Loading branch information
tonioo authored Oct 20, 2023
2 parents 960d1ad + 6f528c9 commit 4a2e9f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
10 changes: 10 additions & 0 deletions modoboa_installer/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ def install_package_from_repository(name, url, vcs="git", venv=None, **kwargs):
utils.exec_cmd(cmd, **kwargs)


def install_package_from_remote_requirements(url, venv=None, **kwargs):
"""Install a Python package from a file."""
cmd = "{} install {} {}".format(
get_pip_path(venv),
"-r",
url
)
utils.exec_cmd(cmd, **kwargs)


def setup_virtualenv(path, sudo_user=None, python_version=2):
"""Install a virtualenv if needed."""
if os.path.exists(path):
Expand Down
31 changes: 18 additions & 13 deletions modoboa_installer/scripts/modoboa.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,6 @@ def _setup_venv(self):
packages.append("{}{}".format(extension, req_version))
else:
packages.append(extension)
# Temp fix for django-braces
python.install_package(
"django-braces", self.venv_path, upgrade=self.upgrade,
sudo_user=self.user
)
if self.dbengine == "postgres":
packages.append("psycopg2-binary\<2.9")
else:
packages.append("mysqlclient")
if sys.version_info.major == 2 and sys.version_info.micro < 9:
# Add extra packages to fix the SNI issue
packages += ["pyOpenSSL"]
Expand All @@ -114,11 +105,25 @@ def _setup_venv(self):
sudo_user=self.user,
beta=self.config.getboolean("modoboa", "install_beta")
)

# Install version specific modules to the venv
modoboa_version = ".".join(str(i) for i in python.get_package_version(
"modoboa", self.venv_path, sudo_user=self.user
))
# Database:
db_file = "postgresql"
if self.dbengine != "postgres":
db_file = "mysql"
db_file += "-requirements.txt"

python.install_package_from_remote_requirements(
f"https://raw.githubusercontent.com/modoboa/modoboa/{modoboa_version}/{db_file}",
venv=self.venv_path)
# Dev mode:
if self.devmode:
# FIXME: use dev-requirements instead
python.install_packages(
["django-bower", "django-debug-toolbar"], self.venv_path,
upgrade=self.upgrade, sudo_user=self.user)
python.install_package_from_remote_requirements(
f"https://raw.githubusercontent.com/modoboa/modoboa/{modoboa_version}/dev-requirements.txt",
venv=self.venv_path)

def _deploy_instance(self):
"""Deploy Modoboa."""
Expand Down

0 comments on commit 4a2e9f2

Please sign in to comment.