mirror of
https://github.com/frappe/bench.git
synced 2024-11-13 16:56:33 +00:00
Merge pull request #1028 from Thunderbottom/declarative-setup-bench
feat: add declarative config support for bench
This commit is contained in:
commit
fbe285f832
44
bench/app.py
44
bench/app.py
@ -11,6 +11,7 @@ import sys
|
|||||||
|
|
||||||
# imports - third party imports
|
# imports - third party imports
|
||||||
import click
|
import click
|
||||||
|
from setuptools.config import read_configuration
|
||||||
|
|
||||||
# imports - module imports
|
# imports - module imports
|
||||||
import bench
|
import bench
|
||||||
@ -137,15 +138,25 @@ Do you want to continue and overwrite it?'''.format(repo_name)):
|
|||||||
|
|
||||||
|
|
||||||
def get_app_name(bench_path, repo_name):
|
def get_app_name(bench_path, repo_name):
|
||||||
# retrieves app name from setup.py
|
app_name = None
|
||||||
app_path = os.path.join(bench_path, 'apps', repo_name, 'setup.py')
|
apps_path = os.path.join(os.path.abspath(bench_path), 'apps')
|
||||||
with open(app_path, 'rb') as f:
|
config_path = os.path.join(apps_path, repo_name, 'setup.cfg')
|
||||||
app_name = re.search(r'name\s*=\s*[\'"](.*)[\'"]', f.read().decode('utf-8')).group(1)
|
if os.path.exists(config_path):
|
||||||
if repo_name != app_name:
|
config = read_configuration(config_path)
|
||||||
apps_path = os.path.join(os.path.abspath(bench_path), 'apps')
|
app_name = config.get('metadata', {}).get('name')
|
||||||
os.rename(os.path.join(apps_path, repo_name), os.path.join(apps_path, app_name))
|
|
||||||
|
if not app_name:
|
||||||
|
# retrieve app name from setup.py as fallback
|
||||||
|
app_path = os.path.join(apps_path, repo_name, 'setup.py')
|
||||||
|
with open(app_path, 'rb') as f:
|
||||||
|
app_name = re.search(r'name\s*=\s*[\'"](.*)[\'"]', f.read().decode('utf-8')).group(1)
|
||||||
|
|
||||||
|
if app_name and repo_name != app_name:
|
||||||
|
os.rename(os.path.join(apps_path, repo_name), os.path.join(apps_path, app_name))
|
||||||
return app_name
|
return app_name
|
||||||
|
|
||||||
|
return repo_name
|
||||||
|
|
||||||
|
|
||||||
def new_app(app, bench_path='.'):
|
def new_app(app, bench_path='.'):
|
||||||
# For backwards compatibility
|
# For backwards compatibility
|
||||||
@ -323,15 +334,26 @@ def fetch_upstream(app, bench_path='.'):
|
|||||||
return subprocess.call(["git", "fetch", "upstream"], cwd=repo_dir)
|
return subprocess.call(["git", "fetch", "upstream"], cwd=repo_dir)
|
||||||
|
|
||||||
def get_current_version(app, bench_path='.'):
|
def get_current_version(app, bench_path='.'):
|
||||||
|
current_version = None
|
||||||
repo_dir = get_repo_dir(app, bench_path=bench_path)
|
repo_dir = get_repo_dir(app, bench_path=bench_path)
|
||||||
|
config_path = os.path.join(repo_dir, "setup.cfg")
|
||||||
|
init_path = os.path.join(repo_dir, os.path.basename(repo_dir), '__init__.py')
|
||||||
|
setup_path = os.path.join(repo_dir, 'setup.py')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(repo_dir, os.path.basename(repo_dir), '__init__.py')) as f:
|
if os.path.exists(config_path):
|
||||||
return get_version_from_string(f.read())
|
config = read_configuration(config_path)
|
||||||
|
current_version = config.get("metadata", {}).get("version")
|
||||||
|
if not current_version:
|
||||||
|
with open(init_path) as f:
|
||||||
|
current_version = get_version_from_string(f.read())
|
||||||
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# backward compatibility
|
# backward compatibility
|
||||||
with open(os.path.join(repo_dir, 'setup.py')) as f:
|
with open(setup_path) as f:
|
||||||
return get_version_from_string(f.read(), field='version')
|
current_version = get_version_from_string(f.read(), field='version')
|
||||||
|
|
||||||
|
return current_version
|
||||||
|
|
||||||
def get_develop_version(app, bench_path='.'):
|
def get_develop_version(app, bench_path='.'):
|
||||||
repo_dir = get_repo_dir(app, bench_path=bench_path)
|
repo_dir = get_repo_dir(app, bench_path=bench_path)
|
||||||
|
Loading…
Reference in New Issue
Block a user