Skip to content

Commit

Permalink
Merge branch 'staging' into v5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Aug 2, 2022
2 parents c6f158a + 57a4773 commit 46aa3d1
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 178 deletions.
122 changes: 122 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: 'CI'

on:
pull_request:
workflow_dispatch:
push:
branches: [ develop ]

permissions:
contents: read

jobs:
base_setup:
runs-on: ubuntu-latest
timeout-minutes: 60

strategy:
matrix:
python-version: [ '3.7', '3.8', '3.9', '3.10' ]

name: Base (${{ matrix.python-version }})

services:
mariadb:
image: mariadb:10.6
env:
MARIADB_ROOT_PASSWORD: travis
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/setup-node@v3
with:
node-version: 14
- run: |
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb;
sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb;
sudo apt install redis-server
python -m pip install -U --no-cache-dir --force-reinstall urllib3 pyOpenSSL ndg-httpsclient pyasn1 wheel setuptools pip;
python -m pip install -U -e ${GITHUB_WORKSPACE};
- run: python ${GITHUB_WORKSPACE}/bench/tests/test_init.py TestBenchInit.basic

production_setup:
runs-on: ubuntu-latest
timeout-minutes: 60

strategy:
matrix:
python-version: [ '3.7', '3.10' ]

name: Production (${{ matrix.python-version }})

services:
mariadb:
image: mariadb:10.6
env:
MARIADB_ROOT_PASSWORD: travis
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/setup-node@v3
with:
node-version: 14
- run: |
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb;
sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb;
sudo apt install redis-server
python -m pip install -U --no-cache-dir --force-reinstall urllib3 pyOpenSSL ndg-httpsclient pyasn1 wheel setuptools pip;
python -m pip install -U -e ${GITHUB_WORKSPACE};
- run: python bench/tests/test_setup_production.py TestSetupProduction.production

tests:
runs-on: ubuntu-latest
timeout-minutes: 60

strategy:
matrix:
python-version: [ '3.7', '3.10' ]

name: Tests (${{ matrix.python-version }})

services:
mariadb:
image: mariadb:10.6
env:
MARIADB_ROOT_PASSWORD: travis
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/setup-node@v3
with:
node-version: 14
- run: |
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb;
sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb;
sudo apt install redis-server
python -m pip install -U --no-cache-dir --force-reinstall urllib3 pyOpenSSL ndg-httpsclient pyasn1 wheel setuptools pip;
python -m pip install -U -e ${GITHUB_WORKSPACE};
- run: python -m unittest -v bench.tests.test_utils && python -m unittest -v bench.tests.test_init
39 changes: 39 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Linters

on:
pull_request:
workflow_dispatch:
push:
branches: [ develop ]

permissions:
contents: read

jobs:
linter:
name: 'Pre Commit Hooks'
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: pre-commit/action@v3.0.0
with:
extra_args: --files 'bench/'

deps-vulnerable-check:
name: 'Vulnerable Dependency Check'
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: actions/checkout@v3
- name: 'Pip Audit'
run: |
pip install pip-audit
pip-audit ${GITHUB_WORKSPACE}
76 changes: 0 additions & 76 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions bench/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# imports - standard imports
import functools
from functools import lru_cache
import json
import logging
import os
Expand Down Expand Up @@ -149,7 +149,7 @@ def get_ssh_url(self):
return f"git@{self.remote_server}:{self.org}/{self.repo}.git"


@functools.lru_cache(maxsize=None)
@lru_cache(maxsize=None)
class App(AppMeta):
def __init__(
self,
Expand Down
24 changes: 12 additions & 12 deletions bench/bench.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# imports - standard imports
import subprocess
import functools
from functools import lru_cache
import os
import shutil
import json
Expand Down Expand Up @@ -30,7 +30,6 @@
restart_process_manager,
remove_backups_crontab,
get_venv_path,
get_virtualenv_path,
get_env_cmd,
)
from bench.utils.render import job, step
Expand All @@ -55,7 +54,7 @@ def validate_app_uninstall(self, app):
validate_app_installed_on_sites(app, bench_path=self.name)


@functools.lru_cache(maxsize=None)
@lru_cache(maxsize=None)
class Bench(Base, Validator):
def __init__(self, path):
self.name = path
Expand All @@ -71,7 +70,7 @@ def __init__(self, path):

@property
def python(self) -> str:
return get_env_cmd("python", bench_path=self.name)
return get_env_cmd("python*", bench_path=self.name)

@property
def shallow_clone(self) -> bool:
Expand Down Expand Up @@ -347,20 +346,19 @@ def env(self, python="python3"):
click.secho("Setting Up Environment", fg="yellow")

frappe = os.path.join(self.bench.name, "apps", "frappe")
virtualenv = get_virtualenv_path(verbose=verbose)
quiet_flag = "" if verbose else "--quiet"

if not os.path.exists(self.bench.python):
if virtualenv:
self.run(f"{virtualenv} {quiet_flag} env -p {python}")
else:
venv = get_venv_path(verbose=verbose, python=python)
self.run(f"{venv} env")
venv = get_venv_path(verbose=verbose, python=python)
self.run(f"{venv} env", cwd=self.bench.name)

self.pip()

if os.path.exists(frappe):
self.run(f"{self.bench.python} -m pip install {quiet_flag} --upgrade -e {frappe}")
self.run(
f"{self.bench.python} -m pip install {quiet_flag} --upgrade -e {frappe}",
cwd=self.bench.name,
)

@step(title="Setting Up Bench Config", success="Bench Config Set Up")
def config(self, redis=True, procfile=True):
Expand Down Expand Up @@ -388,7 +386,9 @@ def pip(self, verbose=False):
verbose = bench.cli.verbose or verbose
quiet_flag = "" if verbose else "--quiet"

return self.run(f"{self.bench.python} -m pip install {quiet_flag} --upgrade pip")
return self.run(
f"{self.bench.python} -m pip install {quiet_flag} --upgrade pip", cwd=self.bench.name
)

def logging(self):
from bench.utils import setup_logging
Expand Down
20 changes: 6 additions & 14 deletions bench/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# imports - standard imports
import atexit
from contextlib import contextmanager
import json
from logging import Logger
import os
import pwd
Expand All @@ -16,11 +15,10 @@
from bench.commands import bench_command
from bench.config.common_site_config import get_config
from bench.utils import (
bench_cache_file,
check_latest_version,
drop_privileges,
find_parent_bench,
generate_command_cache,
get_env_frappe_commands,
get_cmd_output,
is_bench_directory,
is_dist_editable,
Expand Down Expand Up @@ -190,33 +188,26 @@ def change_uid():


def app_cmd(bench_path="."):
f = get_env_cmd("python", bench_path=bench_path)
f = get_env_cmd("python*", bench_path=bench_path)
os.chdir(os.path.join(bench_path, "sites"))
os.execv(f, [f] + ["-m", "frappe.utils.bench_helper"] + sys.argv[1:])


def frappe_cmd(bench_path="."):
f = get_env_cmd("python", bench_path=bench_path)
f = get_env_cmd("python*", bench_path=bench_path)
os.chdir(os.path.join(bench_path, "sites"))
os.execv(f, [f] + ["-m", "frappe.utils.bench_helper", "frappe"] + sys.argv[1:])


def get_cached_frappe_commands():
if os.path.exists(bench_cache_file):
command_dump = open(bench_cache_file).read() or "[]"
return set(json.loads(command_dump))
return set()


def get_frappe_commands():
if not is_bench_directory():
return set()

return set(generate_command_cache())
return set(get_env_frappe_commands())


def get_frappe_help(bench_path="."):
python = get_env_cmd("python", bench_path=bench_path)
python = get_env_cmd("python*", bench_path=bench_path)
sites_path = os.path.join(bench_path, "sites")
try:
out = get_cmd_output(
Expand Down Expand Up @@ -245,6 +236,7 @@ def setup_clear_cache():

def _chdir(*args, **kwargs):
Bench.cache_clear()
get_env_cmd.cache_clear()
return f(*args, **kwargs)

os.chdir = _chdir
Loading

0 comments on commit 46aa3d1

Please sign in to comment.