Skip to content

Commit

Permalink
Fix variable scope in EXTENDS management (#2418)
Browse files Browse the repository at this point in the history
quick build
TEST_KEYWORDS=config
  • Loading branch information
nvuillam committed Mar 5, 2023
1 parent 868b6c1 commit 32009e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
7 changes: 4 additions & 3 deletions megalinter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def init_config(workspace=None):
print(f"[config] {CONFIG_SOURCE}")
return
# Search for config file
config_file = None
if "MEGALINTER_CONFIG" in os.environ:
config_file_name = os.environ.get("MEGALINTER_CONFIG")
if config_file_name.startswith("https://"):
Expand Down Expand Up @@ -73,15 +74,15 @@ def init_config(workspace=None):
if "EXTENDS" in runtime_config:
combined_config = {}
CONFIG_SOURCE = combine_config(
workspace, config_file_name, runtime_config, combined_config, CONFIG_SOURCE
workspace, config_file, runtime_config, combined_config, CONFIG_SOURCE
)
runtime_config = combined_config
# Print & set config in cache
print(f"[config] {CONFIG_SOURCE}")
set_config(runtime_config)


def combine_config(workspace, config_file_name, config, combined_config, config_source):
def combine_config(workspace, config_file, config, combined_config, config_source):
extends = config["EXTENDS"]
if isinstance(extends, str):
extends = extends.split(",")
Expand All @@ -90,7 +91,7 @@ def combine_config(workspace, config_file_name, config, combined_config, config_
r = requests.get(extends_item, allow_redirects=True)
assert (
r.status_code == 200
), f"Unable to retrieve EXTENDS config file {config_file_name}"
), f"Unable to retrieve EXTENDS config file {config_file}"
extends_config_data = yaml.safe_load(r.content)
else:
with open(
Expand Down
9 changes: 1 addition & 8 deletions megalinter/tests/test_megalinter/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,7 @@ def test_remote_config_extends_error(self):
os.environ["MEGALINTER_CONFIG"] = remote_config
config.init_config()
except Exception as e:
self.assertRegex(
str(e),
(
"Unable to retrieve EXTENDS config file "
r"https://.*/\.automation/test/mega-linter-config-test/"
r"remote_extends_error/base-error\.mega-linter\.yml"
),
)
self.assertIn("Unable to retrieve EXTENDS config file", str(e)),
finally:
self.restore_branch_in_input_files(changed_files)

Expand Down

0 comments on commit 32009e8

Please sign in to comment.