Skip to content

Commit

Permalink
fix: add declarative config support for bench
Browse files Browse the repository at this point in the history
bench will attempt to read name and version from setup.cfg before trying
to access setup.py for details

Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
  • Loading branch information
Thunderbottom committed Jun 23, 2020
1 parent 5e0de6f commit 186ba28
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import requests
import semantic_version
from six.moves import reload_module
from setuptools.config import read_configuration

# imports - module imports
import bench
Expand Down Expand Up @@ -140,14 +141,23 @@ def get_app(git_url, branch=None, bench_path='.', skip_assets=False, verbose=Fal


def get_app_name(bench_path, repo_name):
# retrieves app name from setup.py
app_path = os.path.join(bench_path, 'apps', 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 repo_name != app_name:
apps_path = os.path.join(os.path.abspath(bench_path), 'apps')
os.rename(os.path.join(apps_path, repo_name), os.path.join(apps_path, app_name))
return app_name
app_name = None
apps_path = os.path.join(os.path.abspath(bench_path), 'apps')
config_path = os.path.join(apps_path, repo_name, 'setup.cfg')
if os.path.exists(config_path):
config = read_configuration(config_path)
app_name = config.get('metadata', {}).get('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


def new_app(app, bench_path='.'):
Expand Down Expand Up @@ -325,15 +335,23 @@ def fetch_upstream(app, bench_path='.'):
return subprocess.call(["git", "fetch", "upstream"], cwd=repo_dir)

def get_current_version(app, bench_path='.'):
current_version = None
repo_dir = get_repo_dir(app, bench_path=bench_path)
try:
with open(os.path.join(repo_dir, os.path.basename(repo_dir), '__init__.py')) as f:
return get_version_from_string(f.read())
config_path = os.path.join(repo_dir, "setup.cfg")
if os.path.exists(config_path):
config = read_configuration(config_path)
current_version = config.get("metadata", {}).get("version")
if not current_version:
with open(os.path.join(repo_dir, os.path.basename(repo_dir), '__init__.py')) as f:
current_version = get_version_from_string(f.read())

except AttributeError:
# backward compatibility
with open(os.path.join(repo_dir, 'setup.py')) 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='.'):
repo_dir = get_repo_dir(app, bench_path=bench_path)
Expand Down

0 comments on commit 186ba28

Please sign in to comment.