Skip to content

Commit d770f9a

Browse files
authored
Merge pull request #21 from mpowelson/feature/update_os
Updates for 22.04
2 parents aba9483 + cd92cf9 commit d770f9a

File tree

5 files changed

+153
-6
lines changed

5 files changed

+153
-6
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ To run the tests:
6868
```bash
6969
python -m pytest
7070
```
71+
### Git hooks (pre-commit)
72+
73+
This repository includes a `.pre-commit-config.yaml` to enforce code style and basic quality checks locally.
74+
75+
```bash
76+
# Install the pre-commit framework in your development environment
77+
pip install pre-commit
78+
79+
# Register the Git hooks for this repository
80+
pre-commit install
81+
82+
# (Optional) Run against all files once
83+
pre-commit run --all-files
84+
```
7185
### Troubleshooting
7286

7387
- If editable install fails, ensure you have a modern toolchain:

arm_cli/container/container.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import subprocess
2+
import sys
23

34
import click
45
import docker
@@ -17,8 +18,24 @@ def container():
1718

1819
def get_running_containers():
1920
"""Retrieve a list of running Docker containers"""
20-
client = docker.from_env()
21-
return client.containers.list(filters={"status": "running"})
21+
try:
22+
client = docker.from_env()
23+
return client.containers.list(filters={"status": "running"})
24+
except docker.errors.DockerException as e:
25+
error_msg = str(e)
26+
print("Error: Unable to connect to Docker daemon.", file=sys.stderr)
27+
print(f"Details: {error_msg}", file=sys.stderr)
28+
print("\nPossible solutions:", file=sys.stderr)
29+
print(" 1. Ensure Docker daemon is running: sudo systemctl start docker", file=sys.stderr)
30+
print(
31+
" 2. Add your user to the docker group: sudo usermod -aG docker $USER", file=sys.stderr
32+
)
33+
print(" (You'll need to log out and back in for this to take effect)", file=sys.stderr)
34+
print(" 3. Check Docker socket permissions: ls -la /var/run/docker.sock", file=sys.stderr)
35+
sys.exit(1)
36+
except Exception as e:
37+
print(f"Error: Unexpected error connecting to Docker: {e}", file=sys.stderr)
38+
sys.exit(1)
2239

2340

2441
@container.command("list")
@@ -116,6 +133,9 @@ def restart_container(ctx):
116133
container = client.containers.get(selected_container_name)
117134
container.restart()
118135
print(f"Container {selected_container_name} restarted successfully.")
136+
except docker.errors.DockerException as e:
137+
print(f"Error: Unable to connect to Docker daemon: {e}", file=sys.stderr)
138+
sys.exit(1)
119139
except docker.errors.NotFound:
120140
print(f"Error: Container {selected_container_name} not found.")
121141
except docker.errors.APIError as e:
@@ -156,6 +176,9 @@ def stop_container(ctx):
156176
container = client.containers.get(selected_container_name)
157177
container.stop()
158178
print(f"Container {selected_container_name} stopped successfully.")
179+
except docker.errors.DockerException as e:
180+
print(f"Error: Unable to connect to Docker daemon: {e}", file=sys.stderr)
181+
sys.exit(1)
159182
except docker.errors.NotFound:
160183
print(f"Error: Container {selected_container_name} not found.")
161184
except docker.errors.APIError as e:

arm_cli/self/self.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,45 @@ def update(ctx, source, force):
5454
safe_run(["python", "-c", "import importlib; importlib.invalidate_caches()"])
5555

5656
# Install from the provided source path
57-
safe_run([sys.executable, "-m", "pip", "install", "-e", source], check=True)
58-
print(f"arm-cli installed from source at {source} successfully!")
57+
try:
58+
# Prefer editable install for developer workflows
59+
safe_run([sys.executable, "-m", "pip", "install", "-e", source], check=True)
60+
print(f"arm-cli installed from source (editable) at {source} successfully!")
61+
except subprocess.CalledProcessError:
62+
# Any failure on editable install: fall back to a standard install
63+
print("Editable install failed. Falling back to a standard install...")
64+
try:
65+
safe_run([sys.executable, "-m", "pip", "install", source], check=True)
66+
print(f"arm-cli installed from source (standard) at {source} successfully!")
67+
except subprocess.CalledProcessError:
68+
# Provide guidance without mutating the user's environment
69+
print(
70+
"Standard install also failed. This is typically due to outdated build tooling "
71+
"being pulled during build isolation (e.g., old setuptools).",
72+
file=sys.stderr,
73+
)
74+
print(
75+
"You can resolve this by upgrading build tools, then retrying:",
76+
file=sys.stderr,
77+
)
78+
print(
79+
" python -m pip install --upgrade pip setuptools wheel build setuptools-scm",
80+
file=sys.stderr,
81+
)
82+
print(
83+
" python -m pip install . # or: python -m pip install -e .",
84+
file=sys.stderr,
85+
)
86+
print(
87+
"Alternatively, if you already upgraded tools in this environment, you can bypass "
88+
"build isolation:",
89+
file=sys.stderr,
90+
)
91+
print(
92+
" PIP_NO_BUILD_ISOLATION=1 python -m pip install .",
93+
file=sys.stderr,
94+
)
95+
raise
5996
else:
6097
print("Updating arm-cli from PyPI...")
6198

arm_cli/system/setup_utils.py

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import shutil
23
import stat
34
import subprocess
45
import sys
@@ -263,7 +264,79 @@ def setup_shell(force=False):
263264
bashrc_path = os.path.expanduser("~/.bashrc")
264265

265266
line = f"source {get_current_shell_addins()}"
266-
if not is_line_in_file(line, bashrc_path):
267+
# Detect any existing sourcing of shell_addins.sh (even from old paths)
268+
existing_lines = []
269+
try:
270+
with open(bashrc_path, "r") as f:
271+
for file_line in f:
272+
stripped = file_line.strip()
273+
if (
274+
stripped.startswith("source")
275+
and "/arm_cli/system/shell_scripts/shell_addins.sh" in stripped
276+
):
277+
existing_lines.append(stripped)
278+
except FileNotFoundError:
279+
existing_lines = []
280+
281+
# If there are old references that don't match the current path, warn the user
282+
outdated_lines = [old_line for old_line in existing_lines if old_line != line]
283+
if outdated_lines:
284+
click.secho(
285+
"Warning: Found old shell addins entries in ~/.bashrc that reference a previous Python/site-packages path.",
286+
fg="yellow",
287+
err=True,
288+
)
289+
for old in outdated_lines:
290+
click.secho(f" - {old}", fg="yellow", err=True)
291+
click.secho(
292+
"It is recommended to remove these old lines to avoid duplicate sourcing.",
293+
fg="yellow",
294+
err=True,
295+
)
296+
297+
# Offer to update outdated entries in-place to the current path
298+
if force or click.confirm(
299+
"Do you want me to update these outdated entries to the current path now? "
300+
"A backup will be saved to /tmp/.bashrc_backup."
301+
):
302+
try:
303+
# Backup current ~/.bashrc
304+
shutil.copyfile(bashrc_path, "/tmp/.bashrc_backup")
305+
with open(bashrc_path, "r") as f:
306+
contents = f.readlines()
307+
new_contents = []
308+
for file_line in contents:
309+
if (
310+
file_line.strip().startswith("source")
311+
and "/arm_cli/system/shell_scripts/shell_addins.sh" in file_line
312+
and file_line.strip() != line
313+
):
314+
new_contents.append(line + "\n")
315+
else:
316+
new_contents.append(file_line)
317+
with open(bashrc_path, "w") as f:
318+
f.writelines(new_contents)
319+
# Refresh existing_lines state after modification
320+
existing_lines = []
321+
for file_line in new_contents:
322+
stripped = file_line.strip()
323+
if (
324+
stripped.startswith("source")
325+
and "/arm_cli/system/shell_scripts/shell_addins.sh" in stripped
326+
):
327+
existing_lines.append(stripped)
328+
print(
329+
"Updated outdated shell addins entries in ~/.bashrc (backup at /tmp/.bashrc_backup)"
330+
)
331+
except Exception as e:
332+
click.secho(
333+
f"Failed to update ~/.bashrc automatically: {e}",
334+
fg="yellow",
335+
err=True,
336+
)
337+
338+
# If the current line is not present, append it
339+
if line not in existing_lines:
267340
print(f'Adding \n"{line}"\nto {bashrc_path}')
268341
if not force:
269342
if not click.confirm("Do you want to add shell autocomplete to ~/.bashrc?"):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies = [
1515
"beartype",
1616
"click",
1717
"click-completion",
18-
"docker",
18+
"docker>=7.0.0",
1919
"inquirer",
2020
"pydantic",
2121
]

0 commit comments

Comments
 (0)