File: remote/instance.py
Issue: The connect() function was using the wrong config key name when retrieving the SSH key path from configuration:
- Line 415 used
config_manager.get_value("ssh_key")(incorrect) - The valid config key defined in
remote/config.pyis"ssh_key_path"
This caused the SSH key configuration to fail silently - users who set ssh_key_path in their config would not have the key applied when connecting via SSH.
Changes:
- Fixed line 415: Changed
"ssh_key"to"ssh_key_path"inget_value()call - Fixed line 329: Updated help text to reference
ssh_key_pathinstead ofssh_key
File: remote/utils.py
Issue: The get_instance_name() function had an unused parameter cfg: ConfigParser | None = None. The docstring mentioned it was for "backward compatibility" but:
- The parameter was never used inside the function
- All callers (8 call sites across instance.py, ami.py, snapshot.py, volume.py) called the function without arguments
Changes:
- Removed the unused
cfgparameter from the function signature - Removed the corresponding parameter documentation from the docstring
- Removed the now-unused
from configparser import ConfigParserimport
File: remote/instance.py
Issue: The file imported builtins and used builtins.list[dict[str, str]] for a type annotation on line 742. This is unnecessary because:
- In Python 3.9+,
listcan be used directly in type annotations without importing frombuiltins - The
builtinsmodule was only used for this single type annotation - Using
listdirectly is more idiomatic and readable
Changes:
- Removed the
import builtinsstatement from line 1 - Changed
builtins.list[dict[str, str]]tolist[dict[str, str]]in thetagsvariable annotation
File: remote/utils.py
Issue: Line 33 defined app = typer.Typer() but this app instance was never used anywhere in the codebase:
- No commands were registered to this app
- No other modules imported this app
- The
utils.pymodule is a utility module, not a CLI entrypoint
The typer import itself is still needed for other uses in the file (typer.Exit, typer.secho, typer.colors).
Changes:
- Removed the unused
app = typer.Typer()line
File: remote/utils.py
Issue: The get_sts_client() function (lines 46-55) was defined as a cached client factory but was never used. The get_account_id() function at line 86 created a new STS client directly with boto3.client("sts") instead of using the cached get_sts_client() function.
This was inconsistent with the pattern used for EC2 clients, where get_ec2_client() is consistently used throughout the codebase.
Changes:
- Changed line 86 from
boto3.client("sts").get_caller_identity()toget_sts_client().get_caller_identity() - This makes the code consistent with the EC2 client pattern and utilizes the caching provided by
@lru_cache
File: remote/utils.py
Issue: The get_instance_ids() function at line 390 used enumerate() to iterate over instances:
for _i, reservation in enumerate(instances):The loop index _i was never used in the function body. The underscore prefix conventionally indicates an unused variable, but in this case the enumerate() call itself was unnecessary.
Changes:
- Changed from
for _i, reservation in enumerate(instances):tofor reservation in instances: - Removes dead code and improves clarity by eliminating unused variable
File: remote/utils.py
Issue: The get_instance_info() function had an unused parameter drop_nameless: bool = False:
- The parameter was defined in the function signature and documented in the docstring
- However, the function body always skips instances without a Name tag (lines 336-338), regardless of the parameter value
- No callers in the codebase ever passed this parameter
The parameter was misleading because:
- Default value
Falseimplied nameless instances would be included by default - But the actual behavior always excluded them (as if
drop_nameless=True)
Changes:
- Removed the
drop_namelessparameter from the function signature - Removed the parameter documentation from the docstring
- Added a "Note" section to the docstring clarifying that instances without a Name tag are automatically excluded
File: remote/utils.py
Issue: The module contained deprecated backwards compatibility code for accessing ec2_client as a module-level attribute:
- Lines 59-62 had a comment indicating the deprecated attribute "will be removed in v0.5.0"
- Lines 65-74 defined a
__getattr__function providing lazy access toec2_clientfor backwards compatibility - The
Anytype was imported solely for this__getattr__function's return type
After scanning the entire codebase, no code was found using the deprecated ec2_client attribute:
- All modules use
get_ec2_client()function directly - All test files use local mock variables named
mock_ec2_client, not the deprecated module attribute
Changes:
- Removed the deprecation comment block (lines 59-62)
- Removed the
__getattr__function (lines 65-74)
File: remote/ecs.py
Issue: The module contained dead code for backwards compatibility access to ecs_client as a module-level attribute:
- Lines 29-30 had a comment about backwards compatibility
- Lines 33-37 defined a
__getattr__function providing lazy access toecs_client - The
Anytype was imported solely for this__getattr__function's return type
After scanning the entire codebase, no code was found using the deprecated ecs_client attribute:
- All ECS functions use
get_ecs_client()function directly (lines 72, 106, 136) - All test files mock
get_ecs_client, not the deprecated module attribute - No imports of
ecs_clientexist anywhere in the codebase
This is similar to the ec2_client shim that was removed from utils.py in a previous refactor.
Changes:
- Removed the
Anytype from imports (no longer needed) - Removed the backwards compatibility comment (lines 29-30)
- Removed the
__getattr__function (lines 33-37)
File: remote/config.py
Issue: Line 30 defined ENV_PREFIX = "REMOTE_" but this constant was never used anywhere in the codebase:
- The actual environment prefix is hardcoded in
RemoteConfig.model_configasenv_prefix="REMOTE_"(line 52) - No other code references
ENV_PREFIX - The constant was misleading since it appeared to be the source of truth but wasn't actually used
Changes:
- Removed the unused
ENV_PREFIX = "REMOTE_"constant - Removed the associated comment "Environment variable mapping for config values"
File: remote/instance.py
Issue: The stop() function used parameter name in_duration while the start() function used stop_in for the same purpose (scheduling automatic shutdown). This inconsistency created cognitive overhead when working with both functions:
start()(line 375): parameterstop_inwith CLI flag--stop-instop()(line 601): parameterin_durationwith CLI flag--in
Both parameters serve the same purpose: specifying a duration after which the instance should be stopped.
Changes:
- Renamed
in_durationtostop_inin thestop()function signature (line 601) - Updated all references to
in_durationwithin the function body (lines 641, 649) - The CLI flag
--inremains unchanged for backwards compatibility
File: remote/instance.py
Issue: The type() command function and its type parameter shadowed the Python built-in type. This is problematic because:
- The function name
typeshadows the built-intype()function at module scope - The parameter
typeshadows the built-in within the function body - This prevents using the built-in
type()for any introspection within this function - It's a code smell that can cause subtle bugs and confuses static analysis tools
Changes:
- Renamed function from
typetoinstance_typewith@app.command("type")decorator to preserve CLI command name - Renamed parameter from
typetonew_typeto avoid shadowing the built-in - Updated all references within the function body to use
new_type - Changed the else branch's reassignment from
type = get_instance_type(...)tocurrent_instance_type = get_instance_type(...)to avoid confusion
File: remote/config.py
Issue: The module-level console initialization on line 18 was inconsistent with all other modules:
config.pyused:Console(force_terminal=True)(missing width)- All other modules used:
Console(force_terminal=True, width=200)
Affected modules with consistent pattern:
utils.py:32:Console(force_terminal=True, width=200)snapshot.py:13:Console(force_terminal=True, width=200)ecs.py:30:Console(force_terminal=True, width=200)volume.py:13:Console(force_terminal=True, width=200)instance.py:44:Console(force_terminal=True, width=200)ami.py:24:Console(force_terminal=True, width=200)
This inconsistency could cause different output formatting in config.py commands compared to other modules.
Changes:
- Changed line 18 from
Console(force_terminal=True)toConsole(force_terminal=True, width=200)
File: remote/utils.py
Issue: The is_instance_stopped() function (lines 424-460) was defined but never called anywhere in the production codebase:
- The function checked if an EC2 instance was in "stopped" state
- It was only referenced in test files (
tests/test_utils.py) - No production code in the
remote/directory ever called this function - The similar function
is_instance_running()is actively used, butis_instance_stopped()was dead code
Changes:
- Removed the
is_instance_stopped()function fromremote/utils.py - Removed the import of
is_instance_stoppedfromtests/test_utils.py - Removed the two associated test functions
test_is_instance_stopped_true()andtest_is_instance_stopped_false()fromtests/test_utils.py
File: remote/instance.py
Issue: The list_launch_templates() function (lines 922-952) was duplicated in both instance.py and ami.py:
instance.pyversion: Simple implementation with basic table displayami.pyversion: Feature-rich implementation with--filterand--detailsoptions
The duplicate in instance.py was:
- A subset of the
ami.pyfunctionality - Inconsistent with DRY (Don't Repeat Yourself) principle
- Creating maintenance burden for similar functionality in two places
Users can use remote ami list-templates which provides the same functionality plus additional features like filtering and detailed output.
Changes:
- Removed the
list_launch_templates()function fromremote/instance.py - Removed the corresponding test
test_list_launch_templates_command()fromtests/test_instance.py
File: remote/exceptions.py
Issue: The ConfigurationError exception class (lines 132-142) was defined but never used anywhere in the codebase:
- No code raised this exception
- No code caught this exception
- No tests referenced this exception class
- The class was complete dead code adding unnecessary lines to the module
The exception was designed for configuration-related errors but was never integrated into the config handling code.
Changes:
- Removed the
ConfigurationErrorclass definition fromremote/exceptions.py
File: remote/exceptions.py
Issue: The InvalidInstanceStateError exception class (lines 51-65) was defined but never raised anywhere in the codebase:
- No code raised this exception - grep search for
InvalidInstanceStateErrorin theremote/directory only found the class definition itself - The exception was designed for instance state validation errors but was never integrated
- Tests existed for the class (
tests/test_exceptions.pylines 90-118) but only tested that the class worked correctly, not that it was actually used - Similar to
ConfigurationErrorwhich was removed in commit 50886f1
Changes:
- Removed the
InvalidInstanceStateErrorclass definition fromremote/exceptions.py - Removed the import and test class
TestInvalidInstanceStateErrorfromtests/test_exceptions.py
File: remote/instance.py
Issue: The SSH argument building code was duplicated in two functions:
_schedule_shutdown()(lines 486-494) - built SSH args for scheduling shutdown_cancel_scheduled_shutdown()(lines 552-560) - built identical SSH args for cancelling shutdown
Both functions contained the exact same SSH argument list:
ssh_args = [
"ssh",
"-o",
"StrictHostKeyChecking=accept-new",
"-o",
"BatchMode=yes",
"-o",
"ConnectTimeout=10",
]
if key:
ssh_args.extend(["-i", key])
ssh_args.append(f"{user}@{dns}")This duplication meant any changes to SSH options (e.g., adding new options, changing timeout) would need to be made in multiple places.
Changes:
- Added new helper function
_build_ssh_command(dns, key, user)that returns the base SSH command arguments - Updated
_schedule_shutdown()to use the new helper - Updated
_cancel_scheduled_shutdown()to use the new helper - Reduced code duplication by ~14 lines
File: remote/instance.py
Issue: The datetime module was imported inconsistently in three different locations inside functions rather than at the module level:
- Line 68:
from datetime import timezone(inside_get_raw_launch_times) - Line 159:
from datetime import datetime, timezone(insidelist_instances) - Line 498:
from datetime import datetime, timedelta, timezone(inside_schedule_shutdown)
This pattern is inconsistent with other modules like utils.py which imports datetime at the module level (line 2). Inline imports inside functions:
- Reduce code readability
- Make it harder to see all module dependencies at a glance
- Create slight performance overhead from repeated imports (though Python caches them)
Changes:
- Added
from datetime import datetime, timedelta, timezoneat the module level (after line 4) - Removed the three inline imports from
_get_raw_launch_times,list_instances, and_schedule_shutdownfunctions
Issue: Duplicated console = Console(force_terminal=True, width=200) initialization across 7 modules:
remote/utils.py:32remote/ami.py:24remote/config.py:18remote/ecs.py:30remote/instance.py:45remote/snapshot.py:13remote/volume.py:13
This duplication meant any changes to console configuration would need to be made in 7 places. It also increased the risk of inconsistency (as seen in the previous config.py fix where width=200 was missing).
Changes:
- Kept the single console instance in
remote/utils.py - Updated all other modules to import
consolefromremote.utilsinstead of creating their own instances - Removed redundant
from rich.console import Consoleimports where Console was only used for the module-level instance
Files Modified:
remote/ami.py- Import console from utils, remove Console importremote/config.py- Import console from utils, remove Console importremote/ecs.py- Import console from utils, remove Console importremote/instance.py- Import console from utils (kept Console import for local use in_watch_status)remote/snapshot.py- Import console from utils, remove Console importremote/volume.py- Import console from utils, remove Console import
Note: remote/instance.py still imports Console from rich.console because the _watch_status function creates a separate Console instance for its Live display functionality.
File: remote/instance.py
Issue: The _watch_status() function created a new Console() instance on line 305:
watch_console = Console()This was redundant because:
- The module already imports
consolefromremote.utils(centralized console instance) - The local
watch_consoleduplicated functionality already available - This was noted as an exception in the previous refactor, but there's no reason not to reuse the shared console
Changes:
- Removed the
watch_console = Console()line from_watch_status() - Changed
Live(console=watch_console, ...)toLive(console=console, ...) - Changed
watch_console.print(...)toconsole.print(...) - Removed the now-unused
from rich.console import Consoleimport
This completes the console centralization refactor - all modules now use the shared console instance from remote/utils.py.