mirror of
https://github.com/frappe/bench.git
synced 2025-01-09 16:36:25 +00:00
fix: Cleanup import hell (contd)
This commit is contained in:
parent
e2fd9de921
commit
d2fba5fe52
@ -10,7 +10,8 @@ import unittest
|
||||
|
||||
# imports - module imports
|
||||
import bench
|
||||
import bench.utils
|
||||
from bench.utils import paths_in_bench, exec_cmd
|
||||
from bench.utils.system import init
|
||||
from bench.bench import Bench
|
||||
|
||||
if sys.version_info.major == 2:
|
||||
@ -35,7 +36,7 @@ class TestBenchBase(unittest.TestCase):
|
||||
shutil.rmtree(bench_path, ignore_errors=True)
|
||||
|
||||
def assert_folders(self, bench_name):
|
||||
for folder in bench.utils.paths_in_bench:
|
||||
for folder in paths_in_bench:
|
||||
self.assert_exists(bench_name, folder)
|
||||
self.assert_exists(bench_name, "apps", "frappe")
|
||||
|
||||
@ -83,7 +84,7 @@ class TestBenchBase(unittest.TestCase):
|
||||
frappe_tmp_path = "/tmp/frappe"
|
||||
|
||||
if not os.path.exists(frappe_tmp_path):
|
||||
bench.utils.exec_cmd(f"git clone https://github.com/frappe/frappe -b {FRAPPE_BRANCH} --depth 1 --origin upstream {frappe_tmp_path}")
|
||||
exec_cmd(f"git clone https://github.com/frappe/frappe -b {FRAPPE_BRANCH} --depth 1 --origin upstream {frappe_tmp_path}")
|
||||
|
||||
kwargs.update(dict(
|
||||
python=sys.executable,
|
||||
@ -93,8 +94,8 @@ class TestBenchBase(unittest.TestCase):
|
||||
))
|
||||
|
||||
if not os.path.exists(os.path.join(self.benches_path, bench_name)):
|
||||
bench.utils.init(bench_name, **kwargs)
|
||||
bench.utils.exec_cmd("git remote set-url upstream https://github.com/frappe/frappe", cwd=os.path.join(self.benches_path, bench_name, "apps", "frappe"))
|
||||
init(bench_name, **kwargs)
|
||||
exec_cmd("git remote set-url upstream https://github.com/frappe/frappe", cwd=os.path.join(self.benches_path, bench_name, "apps", "frappe"))
|
||||
|
||||
def file_exists(self, path):
|
||||
if os.environ.get("CI"):
|
||||
|
@ -8,9 +8,7 @@ import unittest
|
||||
import git
|
||||
|
||||
# imports - module imports
|
||||
import bench
|
||||
import bench.cli
|
||||
import bench.utils
|
||||
from bench.utils import exec_cmd
|
||||
from bench.release import get_bumped_version
|
||||
from bench.tests.test_base import FRAPPE_BRANCH, TestBenchBase
|
||||
|
||||
@ -80,7 +78,7 @@ class TestBenchInit(TestBenchBase):
|
||||
site_config_path = os.path.join(site_path, "site_config.json")
|
||||
|
||||
self.init_bench(bench_name)
|
||||
bench.utils.exec_cmd("bench setup requirements --node", cwd=bench_path)
|
||||
exec_cmd("bench setup requirements --node", cwd=bench_path)
|
||||
self.new_site(site_name, bench_name)
|
||||
|
||||
self.assertTrue(os.path.exists(site_path))
|
||||
@ -99,7 +97,7 @@ class TestBenchInit(TestBenchBase):
|
||||
def test_get_app(self):
|
||||
self.init_bench("test-bench")
|
||||
bench_path = os.path.join(self.benches_path, "test-bench")
|
||||
bench.utils.exec_cmd(f"bench get-app {TEST_FRAPPE_APP}", cwd=bench_path)
|
||||
exec_cmd(f"bench get-app {TEST_FRAPPE_APP}", cwd=bench_path)
|
||||
self.assertTrue(os.path.exists(os.path.join(bench_path, "apps", TEST_FRAPPE_APP)))
|
||||
app_installed_in_env = TEST_FRAPPE_APP in subprocess.check_output(["bench", "pip", "freeze"], cwd=bench_path).decode('utf8')
|
||||
self.assertTrue(app_installed_in_env)
|
||||
@ -111,9 +109,9 @@ class TestBenchInit(TestBenchBase):
|
||||
bench_path = os.path.join(self.benches_path, "test-bench")
|
||||
|
||||
self.init_bench(bench_name)
|
||||
bench.utils.exec_cmd("bench setup requirements --node", cwd=bench_path)
|
||||
bench.utils.exec_cmd("bench build", cwd=bench_path)
|
||||
bench.utils.exec_cmd(f"bench get-app {TEST_FRAPPE_APP} --branch master", cwd=bench_path)
|
||||
exec_cmd("bench setup requirements --node", cwd=bench_path)
|
||||
exec_cmd("bench build", cwd=bench_path)
|
||||
exec_cmd(f"bench get-app {TEST_FRAPPE_APP} --branch master", cwd=bench_path)
|
||||
|
||||
self.assertTrue(os.path.exists(os.path.join(bench_path, "apps", TEST_FRAPPE_APP)))
|
||||
|
||||
@ -123,7 +121,7 @@ class TestBenchInit(TestBenchBase):
|
||||
|
||||
# create and install app on site
|
||||
self.new_site(site_name, bench_name)
|
||||
installed_app = not bench.utils.exec_cmd(f"bench --site {site_name} install-app {TEST_FRAPPE_APP}", cwd=bench_path)
|
||||
installed_app = not exec_cmd(f"bench --site {site_name} install-app {TEST_FRAPPE_APP}", cwd=bench_path)
|
||||
|
||||
app_installed_on_site = subprocess.check_output(["bench", "--site", site_name, "list-apps"], cwd=bench_path).decode('utf8')
|
||||
|
||||
@ -135,9 +133,9 @@ class TestBenchInit(TestBenchBase):
|
||||
self.init_bench("test-bench")
|
||||
bench_path = os.path.join(self.benches_path, "test-bench")
|
||||
|
||||
bench.utils.exec_cmd("bench setup requirements --node", cwd=bench_path)
|
||||
bench.utils.exec_cmd(f"bench get-app {TEST_FRAPPE_APP} --branch master --overwrite", cwd=bench_path)
|
||||
bench.utils.exec_cmd(f"bench remove-app {TEST_FRAPPE_APP}", cwd=bench_path)
|
||||
exec_cmd("bench setup requirements --node", cwd=bench_path)
|
||||
exec_cmd(f"bench get-app {TEST_FRAPPE_APP} --branch master --overwrite", cwd=bench_path)
|
||||
exec_cmd(f"bench remove-app {TEST_FRAPPE_APP}", cwd=bench_path)
|
||||
|
||||
with open(os.path.join(bench_path, "sites", "apps.txt")) as f:
|
||||
self.assertFalse(TEST_FRAPPE_APP in f.read())
|
||||
@ -150,12 +148,12 @@ class TestBenchInit(TestBenchBase):
|
||||
bench_path = os.path.join(self.benches_path, "test-bench")
|
||||
app_path = os.path.join(bench_path, "apps", "frappe")
|
||||
|
||||
successful_switch = not bench.utils.exec_cmd("bench switch-to-branch version-13 frappe --upgrade", cwd=bench_path)
|
||||
successful_switch = not exec_cmd("bench switch-to-branch version-13 frappe --upgrade", cwd=bench_path)
|
||||
app_branch_after_switch = str(git.Repo(path=app_path).active_branch)
|
||||
if successful_switch:
|
||||
self.assertEqual("version-13", app_branch_after_switch)
|
||||
|
||||
successful_switch = not bench.utils.exec_cmd("bench switch-to-branch develop frappe --upgrade", cwd=bench_path)
|
||||
successful_switch = not exec_cmd("bench switch-to-branch develop frappe --upgrade", cwd=bench_path)
|
||||
app_branch_after_second_switch = str(git.Repo(path=app_path).active_branch)
|
||||
if successful_switch:
|
||||
self.assertEqual("develop", app_branch_after_second_switch)
|
||||
|
@ -7,7 +7,7 @@ import time
|
||||
import unittest
|
||||
|
||||
# imports - module imports
|
||||
import bench.utils
|
||||
from bench.utils import exec_cmd, get_cmd_output, which
|
||||
from bench.config.production_setup import get_supervisor_confdir
|
||||
from bench.tests.test_base import TestBenchBase
|
||||
|
||||
@ -19,18 +19,18 @@ class TestSetupProduction(TestBenchBase):
|
||||
for bench_name in ("test-bench-1", "test-bench-2"):
|
||||
bench_path = os.path.join(os.path.abspath(self.benches_path), bench_name)
|
||||
self.init_bench(bench_name)
|
||||
bench.utils.exec_cmd(f"sudo bench setup production {user} --yes", cwd=bench_path)
|
||||
exec_cmd(f"sudo bench setup production {user} --yes", cwd=bench_path)
|
||||
self.assert_nginx_config(bench_name)
|
||||
self.assert_supervisor_config(bench_name)
|
||||
self.assert_supervisor_process(bench_name)
|
||||
|
||||
self.assert_nginx_process()
|
||||
bench.utils.exec_cmd(f"sudo bench setup sudoers {user}")
|
||||
exec_cmd(f"sudo bench setup sudoers {user}")
|
||||
self.assert_sudoers(user)
|
||||
|
||||
for bench_name in self.benches:
|
||||
bench_path = os.path.join(os.path.abspath(self.benches_path), bench_name)
|
||||
bench.utils.exec_cmd("sudo bench disable-production", cwd=bench_path)
|
||||
exec_cmd("sudo bench disable-production", cwd=bench_path)
|
||||
|
||||
|
||||
def production(self):
|
||||
@ -62,14 +62,14 @@ class TestSetupProduction(TestBenchBase):
|
||||
|
||||
|
||||
def assert_nginx_process(self):
|
||||
out = bench.utils.get_cmd_output("sudo nginx -t 2>&1")
|
||||
out = get_cmd_output("sudo nginx -t 2>&1")
|
||||
self.assertTrue("nginx: configuration file /etc/nginx/nginx.conf test is successful" in out)
|
||||
|
||||
|
||||
def assert_sudoers(self, user):
|
||||
sudoers_file = '/etc/sudoers.d/frappe'
|
||||
service = bench.utils.which("service")
|
||||
nginx = bench.utils.which("nginx")
|
||||
service = which("service")
|
||||
nginx = which("nginx")
|
||||
|
||||
self.assertTrue(self.file_exists(sudoers_file))
|
||||
|
||||
@ -133,12 +133,12 @@ class TestSetupProduction(TestBenchBase):
|
||||
|
||||
|
||||
def assert_supervisor_process(self, bench_name, use_rq=True, disable_production=False):
|
||||
out = bench.utils.get_cmd_output("supervisorctl status")
|
||||
out = get_cmd_output("supervisorctl status")
|
||||
|
||||
while "STARTING" in out:
|
||||
print ("Waiting for all processes to start...")
|
||||
time.sleep(10)
|
||||
out = bench.utils.get_cmd_output("supervisorctl status")
|
||||
out = get_cmd_output("supervisorctl status")
|
||||
|
||||
tests = [
|
||||
"{bench_name}-web:{bench_name}-frappe-web[\s]+RUNNING",
|
||||
|
@ -256,6 +256,8 @@ def set_git_remote_url(git_url, bench_path='.'):
|
||||
|
||||
|
||||
def run_playbook(playbook_name, extra_vars=None, tag=None):
|
||||
import bench
|
||||
|
||||
if not which('ansible'):
|
||||
print("Ansible is needed to run this command, please install it using 'pip install ansible'")
|
||||
sys.exit(1)
|
||||
@ -326,6 +328,7 @@ def generate_command_cache(bench_path='.'):
|
||||
"""Caches all available commands (even custom apps) via Frappe
|
||||
Default caching behaviour: generated the first time any command (for a specific bench directory)
|
||||
"""
|
||||
from bench.utils.bench import get_env_cmd
|
||||
|
||||
python = get_env_cmd('python', bench_path=bench_path)
|
||||
sites_path = os.path.join(bench_path, 'sites')
|
||||
|
@ -130,6 +130,7 @@ def get_current_frappe_version(bench_path='.'):
|
||||
return 0
|
||||
|
||||
def get_current_branch(app, bench_path='.'):
|
||||
from bench.utils import get_cmd_output
|
||||
repo_dir = get_repo_dir(app, bench_path=bench_path)
|
||||
return get_cmd_output("basename $(git symbolic-ref -q HEAD)", cwd=repo_dir)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user