Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve backwards configshell-fb compatibility #82

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ debian/tmp/
*.pyc
rtslib-*
venv/
.venv/
.idea
*egg-info/
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.6.4
rev: v0.7.1
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-case-conflict
- id: check-ast
Expand Down
6 changes: 2 additions & 4 deletions configshell/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,10 +1243,8 @@ def ui_command_bookmarks(self, action, bookmark=None):
if not self.shell.prefs['bookmarks']:
bookmarks += "No bookmarks yet.\n"
else:
for (bookmark, path) \
in self.shell.prefs['bookmarks'].items():
if len(bookmark) == 1:
bookmark += '\0'
for (_bookmark, path) in self.shell.prefs['bookmarks'].items():
bookmark = _bookmark if len(_bookmark) != 1 else _bookmark + '\0'
underline = ''.ljust(len(bookmark), '-')
bookmarks += f"{bookmark}\n{underline}\n{path}\n\n"
self.shell.con.epy_write(bookmarks)
Expand Down
18 changes: 7 additions & 11 deletions configshell/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,11 @@ def _complete_token_pparam(self, text, path, command, pparams, kparams):
target = self._current_node.get_node(path)
cmd_params, free_pparams, free_kparams = \
target.get_command_signature(command)
current_parameters = {}
for index in range(len(pparams)):
if index < len(cmd_params):
current_parameters[cmd_params[index]] = pparams[index]
for key, value in kparams.items():
current_parameters[key] = value
current_parameters = {
cmd_params[index]: pparams[index]
for index in range(min(len(pparams), len(cmd_params)))
}
current_parameters.update(kparams)
self._completion_help_topic = command
completion_method = target.get_completion_method(command)
self.log.debug(f"Command {command} accepts parameters {cmd_params}.")
Expand Down Expand Up @@ -544,11 +543,8 @@ def _complete_token_kparam(self, text, path, command, pparams, kparams):
self.log.debug(f"Completing '{current_value}' for kparam {keyword}")

self._current_parameter = keyword
current_parameters = {}
for index in range(len(pparams)):
current_parameters[cmd_params[index]] = pparams[index]
for key, value in kparams.items():
current_parameters[key] = value
current_parameters = {cmd_params[index]: pparams[index] for index in range(len(pparams))}
current_parameters.update(dict(kparams.items()))
completion_method = target.get_completion_method(command)
if completion_method:
completions = completion_method(
Expand Down
33 changes: 21 additions & 12 deletions configshell_fb.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# Providing backwards compatibility for modules importing 'configshell_fb'

from configshell import ConfigNode, ConfigShell, Console, ExecutionError, Log, Prefs

__all__ = [
'Console',
'Log',
'ConfigNode',
'ExecutionError',
'Prefs',
'ConfigShell',
]
"""
configshell_fb.py - Backwards compatibility module for configshell

This module provides backwards compatibility for code that imports 'configshell_fb'.
It re-exports all public names from the 'configshell' module.

Usage:
from configshell_fb import ConfigNode, Log, Console # etc.

Note: This compatibility layer may be deprecated in future versions.
Please consider updating your imports to use 'configshell' directly.
"""

import configshell
from configshell import * # noqa: F403

# Explicitly import and re-export submodules
from configshell import console, log, node, prefs, shell # noqa: F401

# Re-export all public names from configshell
__all__ = configshell.__all__
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ ignore = [
"B904", # raise-without-from-inside-except
"PLR09", # Too many branches/statements/arguments
"S105", # Possible hardcoded password assigned
"S605", # TODO Starting a process with a shell
"S607", # TODO Starting a process with a partial executable path
"RET505", # Unnecessary `else` after `return` statement
"PLW2901", # TODO `for` loop variable overwritten by assignment target
"UP031", # TODO Use format specifiers instead of percent format
Expand Down
Loading