From 1badfa8da4c9088b564cf2f42d595bdde5364d06 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 27 Jul 2022 16:16:54 +0530 Subject: [PATCH 1/6] ci: Update conditions for FRAPPE_BRANCH --- .travis.yml | 15 ++++----------- bench/tests/test_base.py | 9 ++++----- bench/tests/test_init.py | 4 ++-- bench/tests/test_setup_production.py | 5 ++--- requirements.txt | 2 +- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index f1d8b83f..a3d88ab3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,6 @@ sudo: true git: depth: 1 -cache: - - pip - - npm - - yarn - addons: mariadb: '10.3' @@ -61,20 +56,18 @@ matrix: script: python -m unittest -v bench.tests.test_utils && python -m unittest -v bench.tests.test_init install: - - pip3 install urllib3 pyOpenSSL ndg-httpsclient pyasn1 + - python -m pip install urllib3 pyOpenSSL ndg-httpsclient pyasn1 - if [ $TEST == "bench" ];then - wget -q -O /tmp/wkhtmltox.tar.xz https://github.com/frappe/wkhtmltopdf/raw/master/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz; - tar -xf /tmp/wkhtmltox.tar.xz -C /tmp; - sudo mv /tmp/wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf; - sudo chmod o+x /usr/local/bin/wkhtmltopdf; + 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; nvm install 14; nvm use 14; mkdir -p ~/.bench; cp -r $TRAVIS_BUILD_DIR/* ~/.bench; - pip3 install -q -U -e ~/.bench; + python -m pip install -U -e ~/.bench; mysql -u root -e "SET GLOBAL character_set_server = 'utf8mb4'"; mysql -u root -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"; diff --git a/bench/tests/test_base.py b/bench/tests/test_base.py index cc910f94..9ca23de4 100644 --- a/bench/tests/test_base.py +++ b/bench/tests/test_base.py @@ -17,10 +17,10 @@ PYTHON_VER = sys.version_info FRAPPE_BRANCH = "version-12" if PYTHON_VER.major == 3: - if PYTHON_VER.minor in [6, 7]: - FRAPPE_BRANCH = "version-13" - else: + if PYTHON_VER.minor >= 10: FRAPPE_BRANCH = "develop" + if 7 >= PYTHON_VER.minor >= 9: + FRAPPE_BRANCH = "version-13" class TestBenchBase(unittest.TestCase): @@ -134,5 +134,4 @@ class TestBenchBase(unittest.TestCase): def get_traceback(self): exc_type, exc_value, exc_tb = sys.exc_info() trace_list = traceback.format_exception(exc_type, exc_value, exc_tb) - body = "".join(str(t) for t in trace_list) - return body + return "".join(str(t) for t in trace_list) diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index 685dcf40..61150c83 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -184,15 +184,15 @@ class TestBenchInit(TestBenchBase): successful_switch = not exec_cmd( f"bench switch-to-branch {prevoius_branch} frappe --upgrade", cwd=bench_path ) - app_branch_after_switch = str(git.Repo(path=app_path).active_branch) if successful_switch: + app_branch_after_switch = str(git.Repo(path=app_path).active_branch) self.assertEqual(prevoius_branch, app_branch_after_switch) successful_switch = not exec_cmd( f"bench switch-to-branch {FRAPPE_BRANCH} frappe --upgrade", cwd=bench_path ) - app_branch_after_second_switch = str(git.Repo(path=app_path).active_branch) if successful_switch: + app_branch_after_second_switch = str(git.Repo(path=app_path).active_branch) self.assertEqual(FRAPPE_BRANCH, app_branch_after_second_switch) diff --git a/bench/tests/test_setup_production.py b/bench/tests/test_setup_production.py index 8c7a9100..4dae93c0 100644 --- a/bench/tests/test_setup_production.py +++ b/bench/tests/test_setup_production.py @@ -1,6 +1,7 @@ # imports - standard imports import getpass import os +import pathlib import re import subprocess import time @@ -76,9 +77,7 @@ class TestSetupProduction(TestBenchBase): if os.environ.get("CI"): sudoers = subprocess.check_output(["sudo", "cat", sudoers_file]).decode("utf-8") else: - with open(sudoers_file) as f: - sudoers = f.read() - + sudoers = pathlib.Path(sudoers_file).read_text() self.assertTrue(f"{user} ALL = (root) NOPASSWD: {service} nginx *" in sudoers) self.assertTrue(f"{user} ALL = (root) NOPASSWD: {nginx}" in sudoers) diff --git a/requirements.txt b/requirements.txt index 664c9639..d5b26797 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ Jinja2~=3.0.3 python-crontab~=2.4.0 requests semantic-version~=2.8.2 -setuptools +setuptools>60.0.0 tomli;python_version<"3.11" \ No newline at end of file From 86c3c90fd9d260b001edf1c798df9fbd2af64ab1 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 27 Jul 2022 18:40:17 +0530 Subject: [PATCH 2/6] build: Retire setup.py + reqs.txt to use pyproject.toml --- pyproject.toml | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 9 -------- setup.py | 42 ----------------------------------- 3 files changed, 57 insertions(+), 51 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements.txt delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..190689ea --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,57 @@ +[project] +name = "frappe-bench" +description = "CLI to manage Multi-tenant deployments for Frappe apps" +readme = "README.md" +license = "GPL-3.0-only" +requires-python = ">=3.7" +authors = [ + { name = "Frappe Technologies Pvt Ltd", email = "developers@frappe.io" }, +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Natural Language :: English", + "Operating System :: MacOS", + "Operating System :: OS Independent", + "Topic :: Software Development :: Build Tools", + "Topic :: Software Development :: User Interfaces", + "Topic :: System :: Installation/Setup", +] +dependencies = [ + "Click>=7.0", + "GitPython~=2.1.15", + "honcho", + "Jinja2~=3.0.3", + "python-crontab~=2.4.0", + "requests", + "semantic-version~=2.8.2", + "setuptools>40.9.0", + "tomli;python_version<'3.11'", +] +dynamic = [ + "version", +] + +[project.scripts] +bench = "bench.cli:cli" + +[project.urls] +Changelog = "https://github.com/frappe/bench/releases" +Documentation = "https://frappeframework.com/docs/user/en/bench" +Homepage = "https://frappe.io/bench" +Source = "https://github.com/frappe/bench" + +[build-system] +requires = [ + "hatchling>=1.6.0", +] +build-backend = "hatchling.build" + +[tool.hatch.version] +path = "bench/__init__.py" + +[tool.hatch.build.targets.sdist] +include = [ + "/bench", +] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index d5b26797..00000000 --- a/requirements.txt +++ /dev/null @@ -1,9 +0,0 @@ -Click>=7.0 -GitPython~=2.1.15 -honcho -Jinja2~=3.0.3 -python-crontab~=2.4.0 -requests -semantic-version~=2.8.2 -setuptools>60.0.0 -tomli;python_version<"3.11" \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index 1e648184..00000000 --- a/setup.py +++ /dev/null @@ -1,42 +0,0 @@ -import pathlib - -from setuptools import find_packages, setup - -from bench import PROJECT_NAME, VERSION - -install_requires = pathlib.Path("requirements.txt").read_text().strip().split("\n") -long_description = pathlib.Path("README.md").read_text() - -setup( - name=PROJECT_NAME, - description="CLI to manage Multi-tenant deployments for Frappe apps", - long_description=long_description, - long_description_content_type="text/markdown", - version=VERSION, - license="GPLv3", - author="Frappe Technologies Pvt Ltd", - author_email="developers@frappe.io", - url="https://frappe.io/bench", - project_urls={ - "Documentation": "https://frappeframework.com/docs/user/en/bench", - "Source": "https://github.com/frappe/bench", - "Changelog": "https://github.com/frappe/bench/releases", - }, - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Environment :: Console", - "License :: OSI Approved :: GNU Affero General Public License v3", - "Natural Language :: English", - "Operating System :: MacOS", - "Operating System :: OS Independent", - "Topic :: Software Development :: Build Tools", - "Topic :: Software Development :: User Interfaces", - "Topic :: System :: Installation/Setup", - ], - packages=find_packages(), - python_requires=">=3.7", - zip_safe=False, - include_package_data=True, - install_requires=install_requires, - entry_points={"console_scripts": ["bench=bench.cli:cli"]}, -) From 38fa45607dee5c3e2bd1315c67cec7197817eac7 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 28 Jul 2022 11:24:29 +0530 Subject: [PATCH 3/6] build: Bump python-crontab dependency Package v2.4.2 leads to a build error on PY 3.7, 3.8 ref: https://app.travis-ci.com/github/frappe/bench/jobs/577932789 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 190689ea..55f40a05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ dependencies = [ "GitPython~=2.1.15", "honcho", "Jinja2~=3.0.3", - "python-crontab~=2.4.0", + "python-crontab~=2.6.0", "requests", "semantic-version~=2.8.2", "setuptools>40.9.0", From 5515b0f4ca9d1bc6e7a28cf9ecfe194e70eb6e2d Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 28 Jul 2022 11:37:16 +0530 Subject: [PATCH 4/6] ci: Update pip, wheel, setuptools explicitly in install --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a3d88ab3..780847ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -56,7 +56,7 @@ matrix: script: python -m unittest -v bench.tests.test_utils && python -m unittest -v bench.tests.test_init install: - - python -m pip install urllib3 pyOpenSSL ndg-httpsclient pyasn1 + - python -m pip install -U --no-cache-dir --force-reinstall urllib3 pyOpenSSL ndg-httpsclient pyasn1 wheel setuptools pip - if [ $TEST == "bench" ];then wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb; From 22294fce5bf5949ff9f6401e8708af80b7b3b438 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 28 Jul 2022 11:50:10 +0530 Subject: [PATCH 5/6] ci: Add PY3.10 to runner matrix Reduce existing runners based on lesser variance to breakages --- .travis.yml | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 780847ae..76618d5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,18 +25,18 @@ matrix: env: TEST=bench script: python bench/tests/test_init.py TestBenchInit.basic + - name: "Python 3.10 Basic Setup" + python: "3.10" + env: TEST=bench + script: python bench/tests/test_init.py TestBenchInit.basic + - name: "Python 3.7 Production Setup" python: 3.7 env: TEST=bench script: python bench/tests/test_setup_production.py TestSetupProduction.production - - name: "Python 3.8 Production Setup" - python: 3.8 - env: TEST=bench - script: python bench/tests/test_setup_production.py TestSetupProduction.production - - - name: "Python 3.9 Production Setup" - python: 3.9 + - name: "Python 3.10 Production Setup" + python: "3.10" env: TEST=bench script: python bench/tests/test_setup_production.py TestSetupProduction.production @@ -45,13 +45,8 @@ matrix: env: TEST=bench script: python -m unittest -v bench.tests.test_utils && python -m unittest -v bench.tests.test_init - - name: "Python 3.8 Tests" - python: 3.8 - env: TEST=bench - script: python -m unittest -v bench.tests.test_utils && python -m unittest -v bench.tests.test_init - - - name: "Python 3.9 Tests" - python: 3.9 + - name: "Python 3.10 Tests" + python: "3.10" env: TEST=bench script: python -m unittest -v bench.tests.test_utils && python -m unittest -v bench.tests.test_init From 203f41e405cf7f37ea4dd07b852a988494c2286f Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 28 Jul 2022 13:35:04 +0530 Subject: [PATCH 6/6] test: Skip deps resolution for non develop branches --- bench/tests/test_init.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index 61150c83..1d4e1027 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -106,6 +106,7 @@ class TestBenchInit(TestBenchBase): ).decode("utf8") self.assertTrue(app_installed_in_env) + @unittest.skipIf(FRAPPE_BRANCH != "develop", "only for develop branch") def test_get_app_resolve_deps(self): FRAPPE_APP = "healthcare" self.init_bench("test-bench")