Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local files with extends #2236

Merged
merged 3 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FILTER_REGEX_INCLUDE: "(base-local)"
SHOW_ELAPSED_TIME: true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EXTENDS: base-error.local.mega-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
EXTENDS: base.local.mega-linter.yml
FILTER_REGEX_INCLUDE: "(local)"
SHOW_ELAPSED_TIME: false
2 changes: 1 addition & 1 deletion megalinter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def init_config(workspace=None):
), f"Unable to retrieve EXTENDS config file {config_file_name}"
extends_config_data = yaml.safe_load(r.content)
else:
with open(extends_item, "r", encoding="utf-8") as f:
with open(workspace + os.path.sep + extends_item, "r", encoding="utf-8") as f:
extends_config_data = yaml.safe_load(f)
combined_config.update(extends_config_data)
CONFIG_SOURCE += f"\n[config] - extends from: {extends_item}"
Expand Down
16 changes: 16 additions & 0 deletions megalinter/tests/test_megalinter/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from megalinter import config
from megalinter.constants import ML_REPO
from megalinter.utils import REPO_HOME_DEFAULT


class config_test(unittest.TestCase):
Expand Down Expand Up @@ -45,6 +46,21 @@ def test_remote_config_error(self):
except Exception as e:
self.assertIn("http", str(e))

def test_local_config_extends_success(self):
local_config = "local.mega-linter.yml"
os.environ["MEGALINTER_CONFIG"] = local_config
config.init_config(REPO_HOME_DEFAULT + os.path.sep + ".automation" + os.path.sep + "test" + os.path.sep + "mega-linter-config-test")
self.assertEqual("(local)", config.get("FILTER_REGEX_INCLUDE"))
self.assertEqual("false", config.get("SHOW_ELAPSED_TIME"))

def test_local_config_extends_error(self):
local_config = "local-error.mega-linter.yml"
os.environ["MEGALINTER_CONFIG"] = local_config
try:
config.init_config(REPO_HOME_DEFAULT + os.path.sep + ".automation" + os.path.sep + "test" + os.path.sep + "mega-linter-config-test")
except Exception as e:
self.assertIn("No such file or directory", str(e))

def test_remote_config_extends_success(self):
remote_config = self.test_folder + "base.mega-linter.yml"
os.environ["MEGALINTER_CONFIG"] = remote_config
Expand Down