Skip to content

Commit 74b0d97

Browse files
Merge pull request #20 from microsoft/psl-fix-linting
fix: pylint
2 parents bc55534 + 3994b89 commit 74b0d97

7 files changed

Lines changed: 424 additions & 709 deletions

File tree

.flake8

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[flake8]
2+
max-line-length = 88
3+
extend-ignore =
4+
# Docstring warnings (D-series) - these are style preferences
5+
D100, D101, D102, D103, D107, D400, D401
6+
# Type annotation warnings (ANN-series) - gradually add these
7+
ANN001, ANN101, ANN201, ANN202, ANN204, ANN205
8+
# Import order warnings (I-series) - handled by isort
9+
I100, I101, I201, I202
10+
# Whitespace in blank lines
11+
W293
12+
# F-string without placeholders (often intentional for consistency)
13+
F541
14+
exclude =
15+
.git,
16+
__pycache__,
17+
.venv,
18+
venv,
19+
*.egg-info,
20+
.tox,
21+
.eggs
22+
per-file-ignores =
23+
__init__.py:F401

src/azd_env_loader.py

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
"""Azure Developer CLI (AZD) environment loader utility."""
12

23
import json
34
import os
45
from pathlib import Path
6+
from typing import Optional
7+
58

69
class AZDEnvironmentLoader:
7-
def __init__(self, directory: str = None, required: bool = False, log_events: bool = True):
10+
"""Loads and manages Azure Developer CLI environment variables."""
811

12+
def __init__(
13+
self,
14+
directory: Optional[str] = None,
15+
required: bool = False,
16+
log_events: bool = True
17+
) -> None:
18+
"""Initialize the AZD environment loader."""
919
if directory is None:
1020
curr_script_path = Path(__file__)
1121
project_root = curr_script_path.parent
@@ -26,39 +36,46 @@ def __init__(self, directory: str = None, required: bool = False, log_events: bo
2636
azure_dir = azure_dir / '.azure'
2737

2838
config_file = azure_dir / 'config.json'
29-
39+
3040
if not config_file.exists():
3141
self._handle_invalid_env("AZD config.json file not found")
3242
return
33-
43+
3444
with open(config_file, 'r') as f:
3545
config = json.load(f)
36-
46+
3747
self.default_env = config.get('defaultEnvironment')
3848
if not self.default_env:
39-
self._handle_invalid_env("No defaultEnvironment set in AZD config.json")
49+
msg = "No defaultEnvironment set in AZD config.json"
50+
self._handle_invalid_env(msg)
4051
return
41-
52+
4253
env_dir = azure_dir / self.default_env
4354
self.env_file = env_dir / '.env'
4455

45-
def _log(self, message: str):
56+
def _log(self, message: str) -> None:
57+
"""Log a message if logging is enabled."""
4658
if self.log_events:
4759
print(message)
4860

49-
def _handle_invalid_env(self, message: str):
61+
def _handle_invalid_env(self, message: str) -> None:
62+
"""Handle invalid environment configuration."""
5063
if self.required:
5164
raise EnvironmentError(f"❌ Error: {message}.")
5265
else:
5366
self._log(f"⚠️ Warning: {message}.")
5467

55-
def set_env_vars(self):
56-
"""Load environment variables from AZD environment if not already set."""
57-
try:
68+
def set_env_vars(self) -> None:
69+
"""Load environment variables from AZD environment."""
70+
try:
5871
if not self.env_file or not self.env_file.exists():
59-
self._handle_invalid_env(f"No .env file found for the default environment '{self.default_env}'")
72+
msg = (
73+
f"No .env file found for the default environment "
74+
f"'{self.default_env}'"
75+
)
76+
self._handle_invalid_env(msg)
6077
return
61-
78+
6279
with open(self.env_file, 'r') as f:
6380
for line in f:
6481
line = line.strip()
@@ -67,12 +84,22 @@ def set_env_vars(self):
6784
key = key.strip()
6885
value = value.strip().strip('"').strip("'")
6986
if key and not os.getenv(key):
70-
self._log(f"Setting environment variable: {key}")
87+
self._log(
88+
f"Setting environment variable: {key}"
89+
)
7190
os.environ[key] = value
7291

73-
self._log(f"✅ Loaded AZD environment variables from: {self.default_env}")
92+
msg = (
93+
f"✅ Loaded AZD environment variables from: "
94+
f"{self.default_env}"
95+
)
96+
self._log(msg)
7497
except Exception as e:
7598
if self.required:
7699
raise e
77100
else:
78-
self._log(f"⚠️ Warning: Failed to load AZD environment variables. {str(e)}")
101+
msg = (
102+
f"⚠️ Warning: Failed to load AZD environment "
103+
f"variables. {str(e)}"
104+
)
105+
self._log(msg)

0 commit comments

Comments
 (0)