Skip to content

Commit d5a86f0

Browse files
committed
Install further packages automatically
PC has the notion of "dependent" or additional packages. These are defined in a standard "Package Control.sublime-settings" file, hosted by the package. (I.e. similar to the "dependencies.json".) Installing such a package did not install the additional packages in one go, neither did it notify about the incomplete install. In the end, a restart is enough and required to trigger `install_missing_packages()` to catch up and install everything. We have two options here. (1) to bail out `install_package` with `return None` and a message to tell the user to restart Sublime, or (2) to install the packages in a recursive style. Here we choose (2). We patch `run_install_tasks` to notify about its outcome to fail the parent task if necessary. This way necessary restarts bubble up.
1 parent 904eb36 commit d5a86f0

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

package_control/package_manager.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
regular_file_exists,
4141
zip_file_exists,
4242
)
43+
from .package_tasks import PackageTaskRunner
4344
from .package_version import PackageVersion, version_sort
4445
from .providers import CHANNEL_PROVIDERS, REPOSITORY_PROVIDERS
4546
from .providers.channel_provider import UncachedChannelRepositoryError
@@ -1600,6 +1601,43 @@ def install_package(self, package_name, unattended=False):
16001601
fail_early=False
16011602
)
16021603

1604+
try:
1605+
extra_pc_settings_json = package_zip.read(common_folder + 'Package Control.sublime-settings')
1606+
extra_pc_settings = json.loads(extra_pc_settings_json.decode('utf-8'))
1607+
except (KeyError):
1608+
pass
1609+
except (ValueError):
1610+
console_write(
1611+
'''
1612+
Failed to parse the Package Control.sublime-settings for "%s"
1613+
''',
1614+
package_name
1615+
)
1616+
else:
1617+
wanted_packages = set(extra_pc_settings.get('installed_packages') or [])
1618+
pc_settings = sublime.load_settings(pc_settings_filename())
1619+
in_process_packages = load_list_setting(pc_settings, 'in_process_packages')
1620+
additional_packages = wanted_packages - in_process_packages - self.installed_packages()
1621+
if additional_packages:
1622+
task_runner = PackageTaskRunner(self)
1623+
tasks = task_runner.create_package_tasks(
1624+
actions=(self.INSTALL, self.OVERWRITE),
1625+
include_packages=additional_packages
1626+
)
1627+
if tasks:
1628+
outcome = task_runner.run_install_tasks(
1629+
tasks, unattended=unattended, package_kind='additional'
1630+
)
1631+
if outcome is False:
1632+
console_write(
1633+
'''
1634+
Failed to install %s -
1635+
deferring until next start
1636+
''',
1637+
package_name
1638+
)
1639+
return None
1640+
16031641
if package_name != old_package_name:
16041642
self.rename_package(old_package_name, package_name)
16051643

package_control/package_tasks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ def run_install_tasks(self, tasks, progress=None, unattended=False, package_kind
362362
:param package_kind:
363363
A unicode string with an additional package attribute.
364364
(e.g.: `missing`, ...)
365+
366+
:return:
367+
``True``, if install was completed.
368+
``False``, if a restart is required.
365369
"""
366370

367371
if package_kind:
@@ -384,6 +388,7 @@ def run_install_tasks(self, tasks, progress=None, unattended=False, package_kind
384388

385389
num_success = 0
386390

391+
success = True
387392
try:
388393
for task in tasks:
389394
if progress:
@@ -393,6 +398,7 @@ def run_install_tasks(self, tasks, progress=None, unattended=False, package_kind
393398
num_success += 1
394399
# do not re-enable package if operation is deferred to next start
395400
elif result is None:
401+
success = False
396402
package_names.remove(task.package_name)
397403

398404
if num_packages == 1:
@@ -412,6 +418,8 @@ def run_install_tasks(self, tasks, progress=None, unattended=False, package_kind
412418
time.sleep(0.7)
413419
self.reenable_packages({self.INSTALL: package_names})
414420

421+
return success
422+
415423
def run_upgrade_tasks(self, tasks, progress=None, unattended=False):
416424
"""
417425
Execute specified package update tasks

0 commit comments

Comments
 (0)