Skip to content

Commit

Permalink
Add support for idleuserextend
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCat467 committed Oct 17, 2023
1 parent 3f9e654 commit 79881b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ classifiers = [
]
keywords = ["align", "regex", "idle", "extension", "development"]

[project.optional-dependencies]
user = ["idleuserextend~=0.0.0"]

[project.urls]
"Homepage" = "https://github.com/CoolCat467/idlealign"
"Source" = "https://github.com/CoolCat467/idlealign"
Expand Down Expand Up @@ -64,7 +67,6 @@ warn_unused_ignores = true
line-length = 79
target-version = ['py310']


[tool.ruff.isort]
combine-as-imports = true

Expand Down
31 changes: 23 additions & 8 deletions src/idlealign/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ def get_required_config(
def check_installed() -> bool:
"""Make sure extension installed."""
# Get list of system extensions
extensions = list(idleConf.defaultCfg["extensions"])
extensions = set(idleConf.defaultCfg["extensions"])

# Do we have the user extend extension?
has_user = "idleuserextend" in idleConf.GetExtensions(active_only=True)

# If we don't, things get messy and we need to change the root config file
ex_defaults = idleConf.defaultCfg["extensions"].file
if has_user:
# Otherwise, idleuserextend patches IDLE and we only need to modify
# the user config file
ex_defaults = idleConf.userCfg["extensions"].file
extensions |= set(idleConf.userCfg["extensions"])

# Import this extension (this file),
module = __import__(__title__)
Expand Down Expand Up @@ -85,8 +95,10 @@ def check_installed() -> bool:
# Make sure line-breaks will go properly in terminal
add_data = required_config.replace("\n", "\\n")
# Tell them the command
print(f"echo -e '{add_data}' | sudo tee -a {ex_defaults}")
print()
append = "| sudo tee -a"
if has_user:
append = ">>"
print(f"echo -e '{add_data}' {append} {ex_defaults}\n")
else:
print(f"Configuration should be good! (v{__version__})")
return True
Expand Down Expand Up @@ -356,6 +368,9 @@ def ensure_bindings_exist(cls) -> bool:
Return True if need to save.
"""
if not cls.bind_defaults:
return False

need_save = False
section = f"{cls.__name__}_cfgBindings"
if ensure_section_exists(section):
Expand All @@ -379,11 +394,11 @@ def ensure_config_exists(cls) -> bool:

@classmethod
def reload(cls) -> None:
"""Load class variables from the extension settings."""
# # Ensure file default values exist so they appear in settings menu
# save = cls.ensure_config_exists()
# if cls.ensure_bindings_exist() or save:
# idleConf.SaveUserCfgFiles()
"""Load class variables from configuration."""
# Ensure file default values exist so they appear in settings menu
save = cls.ensure_config_exists()
if cls.ensure_bindings_exist() or save:
idleConf.SaveUserCfgFiles()

# Reload configuration file
idleConf.LoadCfgFiles()
Expand Down

0 comments on commit 79881b4

Please sign in to comment.