Skip to content

Commit

Permalink
Merge pull request #23 from Never-Over/more-flexible-python-build
Browse files Browse the repository at this point in the history
Support poetry, Pipenv dependencies
  • Loading branch information
emdoyle committed Apr 16, 2024
2 parents 23df158 + b60b117 commit ba020d2
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 5 deletions.
35 changes: 35 additions & 0 deletions bridge/cli/init/install_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# [Generated by Bridge]
import os
import subprocess


def install_dependencies():
# Check for requirements.txt and install using pip
if os.path.exists("requirements.txt"):
print("requirements.txt found. Installing dependencies...")
subprocess.run(["pip", "install", "-r", "requirements.txt"], check=True)

# Check for Pipfile.lock and install using Pipenv
elif os.path.exists("Pipfile.lock"):
print("Pipfile.lock found. Installing Pipenv and dependencies...")
subprocess.run(["pip", "install", "pipx"], check=True)
subprocess.run(["pipx", "install", "pipenv"], check=True)
subprocess.run(["pipenv", "sync"], check=True)

# Check for poetry.lock and install using Poetry
elif os.path.exists("poetry.lock"):
print("poetry.lock found. Installing Poetry and dependencies...")
subprocess.run(["pip", "install", "pipx"], check=True)
subprocess.run(["pipx", "install", "poetry"], check=True)
subprocess.run(["poetry", "install"], check=True)

else:
print(
"No dependency file found."
" Please make sure you have a"
" requirements.txt, Pipfile.lock, or poetry.lock file in the root of your project"
)


if __name__ == "__main__":
install_dependencies()
11 changes: 11 additions & 0 deletions bridge/cli/init/render.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil
from abc import ABC, abstractmethod
from importlib.util import find_spec
from pathlib import Path
Expand Down Expand Up @@ -251,7 +252,17 @@ def add_deploy_render_button_to_readme():
f.write(deploy_to_render_button_template())


def add_install_deps_script(config: RenderPlatformInitConfig):
# Assuming 'install_deps.py' is in the same directory as this file
src_path = Path(__file__).parent / "install_deps.py"
if not src_path.exists():
raise FileNotFoundError("install_deps.py not found in the expected location.")
dst_path = Path(config.script_dir) / "install_deps.py"
shutil.copyfile(src_path, dst_path)


def initialize_render_platform(config: RenderPlatformInitConfig):
add_deploy_render_button_to_readme()
add_install_deps_script(config)
for file in TEMPLATED_FILES:
file.write(config)
8 changes: 6 additions & 2 deletions bridge/cli/init/templates/build__sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
# Exit on error
set -o errexit
# Modify this line as needed for your package manager (pip, poetry, etc.)
pip install -r requirements.txt
# Get the directory of the current script.
DIR=$(dirname "$0")
# Use our Python script to install dependencies
INSTALL_DEPS_SCRIPT="$DIR/install_deps.py"
python "$INSTALL_DEPS_SCRIPT"
# Install additional dependencies
pip install gunicorn uvicorn psycopg-binary whitenoise[brotli]
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Bridge assumes the following project structure:
│ ├── [wsgi.py | asgi.py]
│ ├── ...
├── manage.py
├── [requirements.txt | pyproject.toml | setup.py]
├── [requirements.txt | poetry.lock | Pipfile.lock]
├── ...
```

Expand Down
8 changes: 6 additions & 2 deletions tests/django/django_bridge/bridge-django-render/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
# Exit on error
set -o errexit

# Modify this line as needed for your package manager (pip, poetry, etc.)
pip install -r requirements.txt
# Get the directory of the current script.
DIR=$(dirname "$0")

# Use our Python script to install dependencies
INSTALL_DEPS_SCRIPT="$DIR/install_deps.py"
python "$INSTALL_DEPS_SCRIPT"

# Install additional dependencies
pip install gunicorn uvicorn psycopg-binary whitenoise[brotli]
Expand Down
34 changes: 34 additions & 0 deletions tests/django/django_bridge/bridge-django-render/install_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# [Generated by Bridge]
import os
import subprocess


def install_dependencies():
# Check for requirements.txt and install using pip
if os.path.exists("requirements.txt"):
print("requirements.txt found. Installing dependencies...")
subprocess.run(["pip", "install", "-r", "requirements.txt"], check=True)

# Check for Pipfile.lock and install using Pipenv
elif os.path.exists("Pipfile.lock"):
print("Pipfile.lock found. Installing Pipenv and dependencies...")
subprocess.run(["pip", "install", "pipx"], check=True)
subprocess.run(["pipx", "install", "pipenv"], check=True)
subprocess.run(["pipenv", "sync"], check=True)

# Check for poetry.lock and install using Poetry
elif os.path.exists("poetry.lock"):
print("poetry.lock found. Installing Poetry and dependencies...")
subprocess.run(["pip", "install", "pipx"], check=True)
subprocess.run(["pipx", "install", "poetry"], check=True)
subprocess.run(["poetry", "install"], check=True)

else:
print(
"No dependency file found."
"Please ensure your dependency file is in the current directory."
)


if __name__ == "__main__":
install_dependencies()

0 comments on commit ba020d2

Please sign in to comment.