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

{CI} azdev style: Use azdev config files when .flake8 and pylintrc are not found in azure cli/ext repo. #442

Merged
merged 5 commits into from
Apr 3, 2024
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
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Release History
===============
0.1.66
++++++
* `azdev style`: Use azdev config files when .flake8 and pylintrc are not found in azure cli/ext repo.

0.1.65
++++++
* `azdev command-change meta-diff`: Add diff support for deprecate_info in subgroup, cmd, parameters and options.
Expand Down
2 changes: 1 addition & 1 deletion azdev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# license information.
# -----------------------------------------------------------------------------

__VERSION__ = '0.1.65'
__VERSION__ = '0.1.66'
12 changes: 12 additions & 0 deletions azdev/operations/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ def _config_file_path(style_type="pylint"):

if cli_repo_path:
cli_config_path = os.path.join(cli_repo_path, config_file_mapping[style_type])
if not os.path.exists(cli_config_path):
cli_config_path = os.path.join(
get_azdev_config_dir(),
"config_files",
default_config_file_mapping["cli"][style_type],
)
else:
cli_config_path = os.path.join(
get_azdev_config_dir(),
Expand All @@ -231,6 +237,12 @@ def _config_file_path(style_type="pylint"):

if ext_repo_path:
ext_config_path = os.path.join(ext_repo_path, config_file_mapping[style_type])
if not os.path.exists(ext_config_path):
ext_config_path = os.path.join(
get_azdev_config_dir(),
"config_files",
default_config_file_mapping["ext"][style_type],
)
else:
ext_config_path = os.path.join(
get_azdev_config_dir(),
Expand Down
33 changes: 25 additions & 8 deletions azdev/operations/tests/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_pylint_config_without_setup(self):
self.assertTrue(r[1].endswith("/config_files/ext_pylintrc"))

def test_pylint_config_with_partially_setup(self):
cli_repo_path = "~/Azure/azure-cli"
cli_repo_path = "/mnt/vss/_work/1/s/azure-cli"
mocked_config = configparser.ConfigParser()
mocked_config.add_section("cli")
mocked_config.set("cli", "repo_path", cli_repo_path)
Expand All @@ -42,8 +42,8 @@ def test_pylint_config_with_partially_setup(self):
self.assertTrue(r[1].endswith("/config_files/ext_pylintrc"))

def test_pylint_config_with_all_setup(self):
cli_repo_path = "~/Azure/azure-cli"
ext_repo_path = "~/Azure/azure-cli-extensions"
cli_repo_path = "/mnt/vss/_work/1/s/azure-cli"
ext_repo_path = "/mnt/vss/_work/1/s/azure-cli-extensions"
mocked_config = configparser.ConfigParser()
mocked_config.add_section("cli")
mocked_config.set("cli", "repo_path", cli_repo_path)
Expand All @@ -53,7 +53,7 @@ def test_pylint_config_with_all_setup(self):
with mock.patch("azdev.operations.style.get_azdev_config", return_value=mocked_config):
r = _config_file_path()
self.assertEqual(r[0], cli_repo_path + "/pylintrc")
self.assertTrue(r[1], "/pylintrc")
self.assertEqual(r[1], ext_repo_path + "/pylintrc")

def test_flake8_config_wihtout_setup(self):
mocked_config = configparser.ConfigParser()
Expand All @@ -68,7 +68,7 @@ def test_flake8_config_wihtout_setup(self):
self.assertTrue(r[1].endswith("/config_files/ext.flake8"))

def test_flake8_config_with_partially_setup(self):
ext_repo_path = "~/Azure/azure-cli-extensions"
ext_repo_path = "/mnt/vss/_work/1/s/azure-cli-extensions"

mocked_config = configparser.ConfigParser()
mocked_config.add_section("cli")
Expand All @@ -81,9 +81,9 @@ def test_flake8_config_with_partially_setup(self):
self.assertTrue(r[0].endswith("/config_files/cli.flake8"))
self.assertTrue(r[1].endswith(ext_repo_path + "/.flake8"))

def test_flake9_config_with_all_setup(self):
cli_repo_path = "~/Azure/azure-cli"
ext_repo_path = "~/Azure/azure-cli-extensions"
def test_flake8_config_with_all_setup(self):
cli_repo_path = "/mnt/vss/_work/1/s/azure-cli"
ext_repo_path = "/mnt/vss/_work/1/s/azure-cli-extensions"

mocked_config = configparser.ConfigParser()
mocked_config.add_section("cli")
Expand All @@ -95,3 +95,20 @@ def test_flake9_config_with_all_setup(self):
r = _config_file_path(style_type="flake8")
self.assertTrue(r[0].endswith(cli_repo_path + "/.flake8"))
self.assertTrue(r[1].endswith(ext_repo_path + "/.flake8"))

def test_style_with_all_setup_but_not_exist(self):
cli_repo_path = "/fake/azure-cli"
ext_repo_path = "/fake/azure-cli-extensions"
mocked_config = configparser.ConfigParser()
mocked_config.add_section("cli")
mocked_config.set("cli", "repo_path", cli_repo_path)
mocked_config.add_section("ext")
mocked_config.set("ext", "repo_paths", ext_repo_path)

with mock.patch("azdev.operations.style.get_azdev_config", return_value=mocked_config):
r1 = _config_file_path(style_type="flake8")
r2 = _config_file_path(style_type="pylint")
self.assertTrue(r1[0].endswith("/config_files/cli.flake8"))
self.assertTrue(r1[1].endswith("/config_files/ext.flake8"))
self.assertTrue(r2[0].endswith("/config_files/cli_pylintrc"))
self.assertTrue(r2[1].endswith("/config_files/ext_pylintrc"))