def test_from_file_path_default_packages_root(self): self.assertEqual( ResourcePath.from_file_path( Path(sublime.executable_path()).parent / 'Packages' ), ResourcePath("Packages") )
def test_from_file_path_installed_packages(self): self.assertEqual( ResourcePath.from_file_path( Path(sublime.installed_packages_path(), 'test_package.sublime-package', 'foo.py') ), ResourcePath("Packages/test_package/foo.py") )
def run(self, **kwargs): # plugin settings self.package_dir = ResourcePath.from_file_path(__file__).parent self.plugin_name = 'C++ Classhelper' self.template_dir_name = 'templates' # self.template_dir = "{}/{}/".format(self.package_dir, self.template_dir_name) self.template_dir = self.package_dir / self.template_dir_name # global settings self.settings = sublime.load_settings( "C++ Classhelper.sublime-settings") self.vars = self.window.extract_variables() self.view = self.window.active_view() self.header_file_extension = self.settings.get('header_file_extension') # directory where files will be created print(self.vars) if not "file_path" in self.vars: self.create_directory = self.vars['folder'] else: self.create_directory = self.vars['file_path'] # get folder from sidebar if "paths" in kwargs: self.create_directory = kwargs['paths'][0] # user enter a class name to create the class self.window.show_input_panel("Enter class name: ", "", self.create_class, None, None)
def test_from_file_path_default_packages(self): self.assertEqual( ResourcePath.from_file_path( Path(sublime.executable_path()).parent.joinpath( 'Packages', 'test_package.sublime-package', 'foo.py' ) ), ResourcePath("Packages/test_package/foo.py") )
def extends_completions(self): resources = sublime.find_resources("*.sublime-theme") resources += sublime.find_resources("*.hidden-theme") names = {res.rsplit("/", 1)[-1] for res in resources} if self.view.file_name(): names -= {ResourcePath.from_file_path(self.view.file_name()).name} sorted_names = sorted(names) logger.debug("Found %d themes to complete: %r", len(names), sorted_names) return [("{}\ttheme".format(name), name) for name in sorted_names]
def get_package_modules( package_names: Container[str] ) -> Iterable[Tuple[ModuleType, ResourcePath]]: for module in sys.modules.values(): for file_path in module_paths(module): try: path = ResourcePath.from_file_path(file_path) except ValueError: continue else: if path.package in package_names: # type: ignore yield module, path break
def plugin_loaded(): global PACKAGE_NAME PACKAGE_NAME = ResourcePath.from_file_path(__file__).package global UNSUBSCRIBE UNSUBSCRIBE = get_settings().subscribe(get_configurations, auto_build) if events.install(PACKAGE_NAME): ensure_dependencies_loaded() print('JS Custom: New installation. Building all syntaxes.') sublime.active_window().run_command('build_js_custom_syntaxes') elif events.post_upgrade(PACKAGE_NAME): ensure_dependencies_loaded() print('JS Custom: Installation upgraded. Rebuilding all syntaxes.') sublime.active_window().run_command('build_js_custom_syntaxes')
def extends_completions(self): resources = sublime.find_resources("*.sublime-theme") resources += sublime.find_resources("*.hidden-theme") names = {res.rsplit("/", 1)[-1] for res in resources} if self.view.file_name(): names -= {ResourcePath.from_file_path(self.view.file_name()).name} sorted_names = sorted(names) logger.debug("Found %d themes to complete: %r", len(names), sorted_names) return [ sublime.CompletionItem( trigger=name, completion=name, kind=KIND_THEME, ) for name in sorted_names ]
def _inherited_variables(self): """Wraps _collect_inherited_variables for the current view.""" name, extends, excludes = None, OrderedDict(), set() if self.view.file_name(): this_resource = ResourcePath.from_file_path(self.view.file_name()) name = this_resource.name excludes.add(str(this_resource)) extends_regions = self.view.find_by_selector( "meta.extends.sublime-theme") if extends_regions: extended_name = sublime.decode_value( self.view.substr(extends_regions.pop())) extends[extended_name] = True if extends_regions: logger.warning('Found more than 1 "extends" key for theme') return set(_collect_inherited_variables(name, extends, excludes))
def test_from_file_path_relative(self): with self.assertRaises(ValueError): ResourcePath.from_file_path(Path('test_package')),
def test_from_file_path_installed_packages_root(self): self.assertEqual( ResourcePath.from_file_path(Path(sublime.installed_packages_path())), ResourcePath("Packages") )
def test_from_file_path_installed_packages_not_installed(self): with self.assertRaises(ValueError): ResourcePath.from_file_path( Path(sublime.installed_packages_path(), 'test_package', 'foo.py') ),
def test_from_file_path_cache(self): self.assertEqual( ResourcePath.from_file_path(Path(sublime.cache_path(), 'test_package')), ResourcePath("Cache/test_package") )
def test_from_file_path_packages(self): self.assertEqual( ResourcePath.from_file_path(Path(sublime.packages_path(), 'test_package')), ResourcePath("Packages/test_package") )
from importlib import import_module from unittest import TestCase from sublime_lib import ResourcePath from package_util import reload_packages, TemporaryPackage FIXTURES_PATH = ResourcePath.from_file_path(__file__).parent / 'fixtures' def package_fixture(fixture): return TemporaryPackage(prefix=fixture, copy_from=FIXTURES_PATH / fixture) class TestReload(TestCase): def test_reload_a(self): with package_fixture('ReloadTest') as path: module = import_module(path.package + '.src.foo') self.assertEqual(module.FOO, 1) self.assertEqual(module.BAR, 1) for filename in ['foo.py', 'xyzzy.py']: file_path = path.joinpath('src', filename).file_path() file_path.with_name(filename + '.after_1').replace(file_path) reload_packages({path.package}) self.assertEqual(module.FOO, 2) self.assertEqual(module.BAR, 2) def test_remove_module(self):