Skip to content

Commit 9767acb

Browse files
authored
{CI} azdev style: Use azdev config files when .flake8 and pylintrc are not found in azure cli/ext repo. (#442)
* Update style.py * update * Update test_style.py * Update test_style.py * Update test_style.py
1 parent 202fd8a commit 9767acb

4 files changed

Lines changed: 42 additions & 9 deletions

File tree

HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
33
Release History
44
===============
5+
0.1.66
6+
++++++
7+
* `azdev style`: Use azdev config files when .flake8 and pylintrc are not found in azure cli/ext repo.
8+
59
0.1.65
610
++++++
711
* `azdev command-change meta-diff`: Add diff support for deprecate_info in subgroup, cmd, parameters and options.

azdev/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# license information.
55
# -----------------------------------------------------------------------------
66

7-
__VERSION__ = '0.1.65'
7+
__VERSION__ = '0.1.66'

azdev/operations/style.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ def _config_file_path(style_type="pylint"):
222222

223223
if cli_repo_path:
224224
cli_config_path = os.path.join(cli_repo_path, config_file_mapping[style_type])
225+
if not os.path.exists(cli_config_path):
226+
cli_config_path = os.path.join(
227+
get_azdev_config_dir(),
228+
"config_files",
229+
default_config_file_mapping["cli"][style_type],
230+
)
225231
else:
226232
cli_config_path = os.path.join(
227233
get_azdev_config_dir(),
@@ -231,6 +237,12 @@ def _config_file_path(style_type="pylint"):
231237

232238
if ext_repo_path:
233239
ext_config_path = os.path.join(ext_repo_path, config_file_mapping[style_type])
240+
if not os.path.exists(ext_config_path):
241+
ext_config_path = os.path.join(
242+
get_azdev_config_dir(),
243+
"config_files",
244+
default_config_file_mapping["ext"][style_type],
245+
)
234246
else:
235247
ext_config_path = os.path.join(
236248
get_azdev_config_dir(),

azdev/operations/tests/test_style.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_pylint_config_without_setup(self):
2929
self.assertTrue(r[1].endswith("/config_files/ext_pylintrc"))
3030

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

4444
def test_pylint_config_with_all_setup(self):
45-
cli_repo_path = "~/Azure/azure-cli"
46-
ext_repo_path = "~/Azure/azure-cli-extensions"
45+
cli_repo_path = "/mnt/vss/_work/1/s/azure-cli"
46+
ext_repo_path = "/mnt/vss/_work/1/s/azure-cli-extensions"
4747
mocked_config = configparser.ConfigParser()
4848
mocked_config.add_section("cli")
4949
mocked_config.set("cli", "repo_path", cli_repo_path)
@@ -53,7 +53,7 @@ def test_pylint_config_with_all_setup(self):
5353
with mock.patch("azdev.operations.style.get_azdev_config", return_value=mocked_config):
5454
r = _config_file_path()
5555
self.assertEqual(r[0], cli_repo_path + "/pylintrc")
56-
self.assertTrue(r[1], "/pylintrc")
56+
self.assertEqual(r[1], ext_repo_path + "/pylintrc")
5757

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

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

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

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

8888
mocked_config = configparser.ConfigParser()
8989
mocked_config.add_section("cli")
@@ -95,3 +95,20 @@ def test_flake9_config_with_all_setup(self):
9595
r = _config_file_path(style_type="flake8")
9696
self.assertTrue(r[0].endswith(cli_repo_path + "/.flake8"))
9797
self.assertTrue(r[1].endswith(ext_repo_path + "/.flake8"))
98+
99+
def test_style_with_all_setup_but_not_exist(self):
100+
cli_repo_path = "/fake/azure-cli"
101+
ext_repo_path = "/fake/azure-cli-extensions"
102+
mocked_config = configparser.ConfigParser()
103+
mocked_config.add_section("cli")
104+
mocked_config.set("cli", "repo_path", cli_repo_path)
105+
mocked_config.add_section("ext")
106+
mocked_config.set("ext", "repo_paths", ext_repo_path)
107+
108+
with mock.patch("azdev.operations.style.get_azdev_config", return_value=mocked_config):
109+
r1 = _config_file_path(style_type="flake8")
110+
r2 = _config_file_path(style_type="pylint")
111+
self.assertTrue(r1[0].endswith("/config_files/cli.flake8"))
112+
self.assertTrue(r1[1].endswith("/config_files/ext.flake8"))
113+
self.assertTrue(r2[0].endswith("/config_files/cli_pylintrc"))
114+
self.assertTrue(r2[1].endswith("/config_files/ext_pylintrc"))

0 commit comments

Comments
 (0)