Skip to content

Commit 7739f6c

Browse files
authored
Merge pull request #6 from ExplorerRay/lint
Ensure pylint Github action pass
2 parents 6efdd38 + e73984e commit 7739f6c

45 files changed

Lines changed: 1682 additions & 1838 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pylint.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
name: Pylint
22

3-
on: [push]
3+
on:
4+
push:
5+
pull_request:
46

57
jobs:
68
build:
79
runs-on: ubuntu-latest
810
strategy:
911
matrix:
10-
python-version: ["3.8", "3.9", "3.10"]
12+
python-version: ["3.9", "3.10"]
1113
steps:
1214
- uses: actions/checkout@v4
15+
1316
- name: Set up Python ${{ matrix.python-version }}
1417
uses: actions/setup-python@v3
1518
with:
1619
python-version: ${{ matrix.python-version }}
20+
21+
- name: Install Poetry
22+
uses: snok/install-poetry@v1
23+
with:
24+
virtualenvs-create: true
25+
virtualenvs-in-project: true
26+
virtualenvs-path: .venv
27+
installer-parallel: true
28+
1729
- name: Install dependencies
1830
run: |
19-
python -m pip install --upgrade pip
20-
pip install pylint
31+
poetry install --no-interaction
32+
2133
- name: Analysing the code with pylint
2234
run: |
35+
source .venv/bin/activate
2336
pylint $(git ls-files '*.py')

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__/

pyproject.toml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ readme = "README.md"
1111
packages = [{include = "kerf", from = "src"}]
1212

1313
[tool.poetry.dependencies]
14-
python = "^3.8"
14+
python = "^3.9"
1515
pylibfdt = "^1.7.0"
1616
click = "^8.0.0"
1717
pyyaml = "^6.0"
@@ -29,10 +29,9 @@ pylint = "^3.0.0"
2929
kerf = "kerf.cli:main"
3030

3131
[tool.pylint.main]
32-
py-version = "3.8"
32+
py-version = "3.9"
3333
jobs = 0
3434
ignore-patterns = ["^\\.#"]
35-
suggestion-mode = true
3635

3736
[tool.pylint.messages_control]
3837
disable = [
@@ -44,7 +43,18 @@ disable = [
4443
"too-many-locals",
4544
"too-many-branches",
4645
"too-many-statements",
47-
"invalid-name",
46+
"line-too-long",
47+
"duplicate-code",
48+
"too-many-nested-blocks",
49+
"too-many-positional-arguments",
50+
"too-many-return-statements",
51+
"too-many-instance-attributes",
52+
"too-many-lines",
53+
"fixme",
54+
"import-outside-toplevel",
55+
"broad-exception-caught",
56+
"no-value-for-parameter",
57+
"redefined-builtin",
4858
]
4959

5060
[tool.pylint.format]

setup.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def run_command(cmd, description):
2626
"""Run a command and handle errors."""
2727
print(f"Running: {description}")
2828
try:
29-
result = subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True)
29+
subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True)
3030
print(f"✓ {description} completed successfully")
3131
return True
3232
except subprocess.CalledProcessError as e:
@@ -43,46 +43,47 @@ def main():
4343
"""Set up the development environment."""
4444
print("Setting up kerf development environment...")
4545
print("=" * 50)
46-
46+
4747
# Check if we're in the right directory
4848
if not Path("pyproject.toml").exists():
4949
print("Error: pyproject.toml not found. Please run this script from the project root.")
5050
return 1
51-
51+
5252
# Install dependencies
5353
print("\n1. Installing dependencies...")
5454
if not run_command("pip install -e .", "Installing kerf in development mode"):
5555
return 1
56-
56+
5757
# Install development dependencies
5858
print("\n2. Installing development dependencies...")
59-
if not run_command("pip install pytest pytest-cov black flake8 mypy", "Installing dev dependencies"):
59+
cmd = "pip install pytest pytest-cov black flake8 mypy"
60+
if not run_command(cmd, "Installing dev dependencies"):
6061
return 1
61-
62+
6263
# Run tests
6364
print("\n3. Running tests...")
6465
if not run_command("python -m pytest tests/", "Running test suite"):
6566
return 1
66-
67+
6768
# Check code formatting
6869
print("\n4. Checking code formatting...")
6970
if not run_command("black --check src/kerf/", "Checking code formatting"):
7071
print(" Note: Run 'black src/kerf/' to fix formatting issues")
71-
72+
7273
# Run linting
7374
print("\n5. Running linting...")
7475
if not run_command("flake8 src/kerf/", "Running flake8 linting"):
7576
print(" Note: Fix linting issues before committing")
76-
77+
7778
print("\n" + "=" * 50)
7879
print("✓ Development environment setup complete!")
7980
print("\nNext steps:")
8081
print("1. Run 'python -m pytest tests/' to test the implementation")
8182
print("2. Run 'kerf --help' to see available commands")
8283
print("3. Try: kerf dtc --input=examples/system.dts --output-dir=build/")
83-
84+
8485
return 0
8586

8687

87-
if __name__ == '__main__':
88+
if __name__ == "__main__":
8889
sys.exit(main())

src/kerf/__init__.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"""
1616
kerf: Multikernel Management System
1717
18-
A comprehensive multikernel management system designed to orchestrate and manage multiple kernel instances on a single host.
18+
A comprehensive multikernel management system designed to orchestrate
19+
and manage multiple kernel instances on a single host.
1920
"""
2021

2122
__version__ = "0.1.0"
@@ -48,26 +49,26 @@
4849

4950
__all__ = [
5051
# Core classes
51-
'DeviceTreeManager',
52-
'BaselineManager',
53-
'OverlayGenerator',
52+
"DeviceTreeManager",
53+
"BaselineManager",
54+
"OverlayGenerator",
5455
# Models
55-
'InstanceState',
56+
"InstanceState",
5657
# Exceptions
57-
'KerfError',
58-
'ValidationError',
59-
'ParseError',
60-
'ResourceConflictError',
61-
'ResourceExhaustionError',
62-
'InvalidReferenceError',
63-
'KernelInterfaceError',
64-
'ResourceError',
58+
"KerfError",
59+
"ValidationError",
60+
"ParseError",
61+
"ResourceConflictError",
62+
"ResourceExhaustionError",
63+
"InvalidReferenceError",
64+
"KernelInterfaceError",
65+
"ResourceError",
6566
# Resource utilities
66-
'get_available_cpus',
67-
'get_allocated_cpus',
68-
'get_allocated_memory_regions',
69-
'find_available_memory_base',
70-
'validate_cpu_allocation',
71-
'validate_memory_allocation',
72-
'find_next_instance_id',
67+
"get_available_cpus",
68+
"get_allocated_cpus",
69+
"get_allocated_memory_regions",
70+
"find_available_memory_base",
71+
"validate_cpu_allocation",
72+
"validate_memory_allocation",
73+
"find_next_instance_id",
7374
]

src/kerf/baseline.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ def validate_baseline(self, tree: GlobalDeviceTree) -> None:
8585

8686
# Baseline must contain resources
8787
if not tree.hardware:
88-
raise ValidationError(
89-
"Baseline device tree must contain hardware resources section."
90-
)
88+
raise ValidationError("Baseline device tree must contain hardware resources section.")
9189

9290
# Validate resources structure
9391
if not tree.hardware.cpus:
@@ -124,27 +122,26 @@ def write_baseline(self, tree: GlobalDeviceTree) -> None:
124122
try:
125123
dtb_data = self.extractor.generate_global_dtb(tree)
126124
except Exception as e:
127-
raise KernelInterfaceError(
128-
f"Failed to generate baseline device tree blob: {e}"
129-
) from e
125+
raise KernelInterfaceError(f"Failed to generate baseline device tree blob: {e}") from e
130126

131127
# The kernfs write operation is handled atomically by the kernel
132128
try:
133-
with open(self.baseline_path, 'wb') as f:
129+
with open(self.baseline_path, "wb") as f:
134130
f.write(dtb_data)
135131
f.flush()
136132
os.fsync(f.fileno())
137133

138134
if not self.baseline_path.exists():
139135
raise KernelInterfaceError(
140-
f"Baseline DTB write completed but file does not exist at {self.baseline_path}. "
141-
f"Kernel may have rejected the write operation."
136+
f"Baseline DTB write completed but file does not exist at "
137+
f"{self.baseline_path}. "
138+
"Kernel may have rejected the write operation."
142139
)
143140
file_size = self.baseline_path.stat().st_size
144141
if file_size == 0:
145142
raise KernelInterfaceError(
146-
f"Baseline DTB written but file is empty. "
147-
f"Kernel may have rejected the DTB format."
143+
"Baseline DTB written but file is empty. "
144+
"Kernel may have rejected the DTB format."
148145
)
149146

150147
except OSError as e:
@@ -170,13 +167,12 @@ def read_baseline(self) -> GlobalDeviceTree:
170167
"Initialize it first with 'kerf init'."
171168
)
172169

173-
with open(self.baseline_path, 'rb') as f:
170+
with open(self.baseline_path, "rb") as f:
174171
dtb_data = f.read()
175172

176173
if not dtb_data:
177174
raise KernelInterfaceError(
178-
f"Root device tree is empty. "
179-
"Initialize it first with 'kerf init'."
175+
"Root device tree is empty. Initialize it first with 'kerf init'."
180176
)
181177

182178
tree = self.parser.parse_dtb_from_bytes(dtb_data)
@@ -188,7 +184,4 @@ def read_baseline(self) -> GlobalDeviceTree:
188184
f"Failed to read root device tree from {self.baseline_path}: {e}"
189185
) from e
190186
except ParseError as e:
191-
raise ParseError(
192-
f"Failed to parse root device tree: {e}"
193-
) from e
194-
187+
raise ParseError(f"Failed to parse root device tree: {e}") from e

src/kerf/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030

3131
@click.group()
3232
@click.version_option(version="0.1.0", prog_name="kerf")
33-
@click.option('--debug', is_flag=True, help='Enable debug mode')
33+
@click.option("--debug", is_flag=True, help="Enable debug mode")
3434
@click.pass_context
3535
def main(ctx, debug):
3636
"""kerf: Multikernel Management System - Device Tree Foundation."""
3737
ctx.ensure_object(dict)
38-
ctx.obj['debug'] = debug
38+
ctx.obj["debug"] = debug
3939

4040

4141
# Add subcommands
@@ -50,5 +50,5 @@ def main(ctx, debug):
5050
main.add_command(show)
5151

5252

53-
if __name__ == '__main__':
54-
main()
53+
if __name__ == "__main__":
54+
main()

src/kerf/create/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@
1515
"""
1616
Create kernel instance command.
1717
"""
18-

0 commit comments

Comments
 (0)