Skip to content

Commit

Permalink
Move sorting package names to GUI related code
Browse files Browse the repository at this point in the history
This commit reduces set->list->set ping-pong by sorting package lists
just before displaying them in quick panels.
  • Loading branch information
deathaxe committed Apr 1, 2023
1 parent f7cd712 commit 4edd2a7
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
8 changes: 4 additions & 4 deletions package_control/commands/disable_package_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def list_packages(self, manager):
A list of package names to add to the quick panel
"""

packages = manager.list_all_packages()
ignored = PackageDisabler.ignored_packages()
ignored.add('Package Control')
return sorted(set(packages) - ignored, key=lambda s: s.lower())
return sorted(
manager.list_all_packages() - PackageDisabler.ignored_packages() - {'Package Control'},
key=lambda s: s.lower()
)

def on_done(self, manager, package_name):
"""
Expand Down
2 changes: 1 addition & 1 deletion package_control/commands/existing_packages_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run(self):
url_pattern = re.compile(r'^https?://')

package_list = []
for package in self.list_packages(manager):
for package in sorted(self.list_packages(manager), key=lambda s: s.lower()):
if package in default_packages:
description = 'Bundled Sublime Text Package'
installed_version = default_version
Expand Down
2 changes: 1 addition & 1 deletion package_control/commands/list_packages_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def list_packages(self, manager):
A list of package names to add to the quick panel
"""

return manager.list_packages()
return sorted(manager.list_packages(), key=lambda s: s.lower())

def on_done(self, manager, package_name):
"""
Expand Down
3 changes: 2 additions & 1 deletion package_control/commands/list_unmanaged_packages_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ def list_packages(self, manager):
ignored_packages = load_list_setting(settings, 'unmanaged_packages_ignore')
ignored_packages |= load_list_setting(settings, 'installed_packages')

return sorted(set(manager.list_packages()) - ignored_packages, key=lambda s: s.lower())
packages = manager.list_packages() - ignored_packages
return sorted(packages, key=lambda s: s.lower())
4 changes: 2 additions & 2 deletions package_control/package_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run(self):

# Remove non-existing packages from ignored_packages list.
orphaned_ignored_packages = self.ignored_packages() - found_packages \
- set(self.manager.list_default_packages())
- self.manager.list_default_packages()

if in_process or orphaned_ignored_packages:
self.reenable_packages({self.ENABLE: in_process | orphaned_ignored_packages})
Expand Down Expand Up @@ -398,7 +398,7 @@ def install_missing_packages(self, found_packages):

# Drop remaining missing packages, which seem no longer available upstream,
# to avoid trying again and again each time ST starts.
missing_packages = installed_packages - set(self.manager.list_packages())
missing_packages = installed_packages - self.manager.list_packages()
if missing_packages:
self.manager.update_installed_packages(remove=missing_packages)

Expand Down
2 changes: 1 addition & 1 deletion package_control/package_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def run(self):
Shows a list of packages that can be turned into a .sublime-package file
"""

self.packages = self.manager.list_packages(unpacked_only=True)
self.packages = sorted(self.manager.list_packages(unpacked_only=True), key=lambda s: s.lower())
if not self.packages:
show_message('There are no packages available to be packaged')
return
Expand Down
12 changes: 6 additions & 6 deletions package_control/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def list_packages(self, ignored_packages=None, unpacked_only=False):
Only list packages that are not inside of .sublime-package files
:return:
A list of all installed, non-default, non-library, package names
A set of all installed, non-default, non-library, package names
"""

packages = set(list_sublime_package_dirs(sys_path.packages_path()))
Expand All @@ -766,33 +766,33 @@ def list_packages(self, ignored_packages=None, unpacked_only=False):
packages -= ignored_packages
packages -= set(list_sublime_package_files(sys_path.default_packages_path()))
packages -= {'Binary', 'Default', 'Text', 'User'}
return sorted(packages, key=lambda s: s.lower())
return packages

def list_default_packages(self):
"""
Lists all builtin packages shipped with ST
:return:
A list of default package names
A set of default package names
"""

packages = set(list_sublime_package_files(sys_path.default_packages_path()))
packages -= {'Binary', 'Default', 'Text', 'User'}
return sorted(packages, key=lambda s: s.lower())
return packages

def list_all_packages(self):
"""
Lists all packages on the machine
:return:
A list of all package names, including default packages
A set of all package names, including default packages
"""

packages = set(list_sublime_package_dirs(sys_path.packages_path()))
packages |= set(list_sublime_package_files(sys_path.installed_packages_path()))
packages |= set(list_sublime_package_files(sys_path.default_packages_path()))
packages -= {'Binary', 'Default', 'Text', 'User'}
return sorted(packages, key=lambda s: s.lower())
return packages

def predefined_packages(self):
"""
Expand Down

0 comments on commit 4edd2a7

Please sign in to comment.