Skip to content

Commit 3390b5d

Browse files
committed
Support apigee-cli-info.json with fallback to apigee-cli.info; fix global vars
1 parent 10483cd commit 3390b5d

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

apigee/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
APIGEE_CLI_DIRECTORY, "exceptions.log")
2727
APIGEE_CLI_IS_MACHINE_USER = utils_init.is_truthy_envvar(
2828
getenv("APIGEE_CLI_IS_MACHINE_USER"))
29+
APIGEE_CLI_PLUGIN_INFO_FILE = "apigee-cli-info.json"
30+
APIGEE_CLI_PLUGIN_INFO_FILE_LEGACY = "apigee-cli.info"
2931
APIGEE_CLI_PLUGINS_CONFIG_FILE = utils_init.join_path_components(
3032
APIGEE_CLI_PLUGINS_DIRECTORY, "config")
3133
APIGEE_CLI_PLUGINS_PATH = utils_init.join_path_components(

apigee/plugins/commands.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import click
1010
from click_option_group import MutuallyExclusiveOptionGroup, optgroup
1111

12-
from apigee import (APIGEE_CLI_PLUGINS_CONFIG_FILE,
12+
from apigee import (APIGEE_CLI_PLUGIN_INFO_FILE,
13+
APIGEE_CLI_PLUGIN_INFO_FILE_LEGACY,
14+
APIGEE_CLI_PLUGINS_CONFIG_FILE,
1315
APIGEE_CLI_PLUGINS_DIRECTORY, APIGEE_CLI_PLUGINS_PATH,
1416
console)
1517
from apigee.silent import common_silent_options
@@ -19,18 +21,17 @@
1921
from apigee.verbose import common_verbose_options
2022

2123
# ---- Global Variables ----
22-
is_git_installed = False
23-
plugins_command_help = (
24+
IS_GIT_INSTALLED = False
25+
PLUGINS_COMMAND_HELP = (
2426
"Originally meant to help Darumatic clients automate Apigee and API-related "
2527
"tasks, but available for anyone to use. Refer to "
26-
"https://github.com/mdelotavo/apigee-cli-plugins to learn how."
27-
)
28+
"https://github.com/mdelotavo/apigee-cli-plugins to learn how.")
2829

2930
try:
3031
from git import Repo
31-
is_git_installed = True
32+
IS_GIT_INSTALLED = True
3233
except ImportError:
33-
plugins_command_help = (
34+
PLUGINS_COMMAND_HELP = (
3435
"Simple plugins manager for distributing commands. "
3536
"[Warning: Git must be installed to use plugin commands]")
3637

@@ -54,7 +55,7 @@ class GitUtils:
5455

5556
@staticmethod
5657
def exit_if_not_installed():
57-
if not is_git_installed:
58+
if not IS_GIT_INSTALLED:
5859
sys.exit(0)
5960

6061

@@ -119,9 +120,8 @@ def _func(path_):
119120
except Exception as e:
120121
console.echo(e)
121122

122-
return execute_function_on_directory_files(APIGEE_CLI_PLUGINS_DIRECTORY,
123-
_func,
124-
glob="[!.][!__]*")
123+
return execute_function_on_directory_files(
124+
APIGEE_CLI_PLUGINS_DIRECTORY, _func, glob="[!.][!__]*")
125125

126126
@staticmethod
127127
def update_repositories():
@@ -141,9 +141,8 @@ def _func(path_):
141141
except Exception as e:
142142
console.echo(e)
143143

144-
return execute_function_on_directory_files(APIGEE_CLI_PLUGINS_DIRECTORY,
145-
_func,
146-
glob="[!.][!__]*")
144+
return execute_function_on_directory_files(
145+
APIGEE_CLI_PLUGINS_DIRECTORY, _func, glob="[!.][!__]*")
147146

148147
@staticmethod
149148
def list_sources(section="sources"):
@@ -154,7 +153,10 @@ def list_sources(section="sources"):
154153
@staticmethod
155154
def get_plugin_info(name):
156155
"""Return the parsed plugin info JSON or None if file missing."""
157-
info_file = Path(APIGEE_CLI_PLUGINS_DIRECTORY) / name / "apigee-cli.info"
156+
plugin_directory = Path(APIGEE_CLI_PLUGINS_DIRECTORY) / name
157+
info_json = plugin_directory / APIGEE_CLI_PLUGIN_INFO_FILE
158+
info_legacy = plugin_directory / APIGEE_CLI_PLUGIN_INFO_FILE_LEGACY
159+
info_file = info_json if info_json.exists() else info_legacy
158160
if not is_regular_file(info_file):
159161
return None
160162
return read_file_content(info_file, type="json")
@@ -184,7 +186,7 @@ def print_full_info(plugins_info):
184186

185187

186188
# ---- CLI Commands ----
187-
@click.group(help=plugins_command_help)
189+
@click.group(help=PLUGINS_COMMAND_HELP)
188190
def plugins():
189191
pass
190192

@@ -207,9 +209,9 @@ def configure(silent, verbose, apply_changes):
207209
PluginManager.clone_repositories()
208210
PluginManager.prune_unused_directories()
209211
else:
210-
console.echo("\n Run `apigee plugins update` to apply any changes,")
211-
console.echo(" or rerun `apigee plugins configure` with `-a`")
212-
console.echo(" to apply changes automatically.\n")
212+
console.echo("\n Run `apigee plugins update` to apply any changes, "
213+
"or rerun `apigee plugins configure` with `-a` "
214+
"to apply changes automatically.\n")
213215

214216

215217
@plugins.command(help="Update or install plugins.")

0 commit comments

Comments
 (0)