def test_glob_resources(self): self.assertEqual( ResourcePath.glob_resources("Packages/test_package/*.txt"), [ ResourcePath("Packages/test_package/helloworld.txt"), ResourcePath("Packages/test_package/UTF-8-test.txt"), ]) self.assertEqual(ResourcePath.glob_resources("ks27jArEz4"), []) self.assertEqual(ResourcePath.glob_resources("*ks27jArEz4"), [ ResourcePath( 'Packages/sublime_lib/tests/uniquely_named_file_ks27jArEz4') ])
def _load_package_schemas(self) -> List[Any]: global_preferences_schemas = [] resources = ResourcePath.glob_resources('sublime-package.json') for resource in resources: schema = self._parse_schema(resource) if not schema: continue settings = schema.get('contributions').get('settings') for s in settings: i = len(self._schema_uri_to_content) file_patterns = s.get('file_patterns') schema_content = s.get('schema') uri = schema_content.get( '$id') or 'sublime://settings/{}'.format(i) self._schema_uri_to_content[uri] = sublime.encode_value( schema_content, pretty=False) self._register_schemas([{ 'fileMatch': file_patterns, 'uri': uri }]) if file_patterns: for pattern in file_patterns: if pattern == '/Preferences.sublime-settings': global_preferences_schemas.append(schema_content) return global_preferences_schemas
def get_extensions(path): arguments = (yield).context ret = [] for file_path in ResourcePath.glob_resources(path): if arguments.get(file_path.stem) not in (None, False): ret.append((yield from include_resource(str(file_path)))) return ret
def test_glob_resources(self): self.assertEqual( ResourcePath.glob_resources("Packages/test_package/*.txt"), [ ResourcePath("Packages/test_package/helloworld.txt"), ResourcePath("Packages/test_package/UTF-8-test.txt"), ] )
def get_scheme_path(view, setting_name): # Be lazy here and don't consider invalid values scheme_setting = view.settings().get(setting_name, DEFAULT_CS) if scheme_setting == 'auto': return 'auto' elif "/" not in scheme_setting: return ResourcePath.glob_resources(scheme_setting)[0] else: return ResourcePath(scheme_setting)
def run(self): view = self.window.active_view() if not view: return # Be lazy here and don't consider invalid values scheme_setting = view.settings().get('color_scheme') if '/' not in scheme_setting: scheme_path = ResourcePath.glob_resources(scheme_setting)[0] else: scheme_path = ResourcePath(scheme_setting) self.window.run_command( 'edit_settings', { "base_file": '/'.join(("${packages}", ) + scheme_path.parts[1:]), "user_file": "${packages}/User/" + scheme_path.stem + '.sublime-color-scheme', "default": SCHEME_TEMPLATE, }, )
def _theme_completions(key, default): """Create completions of all visible themes. default (string): The default `theme` value. The set will not include color schemes matching at least one entry of `"settings.exclude_theme_patterns": []` setting. Returns: {(trigger, contents), ...} A set of all completions. - trigger (string): base file name of the theme - contents (string): the file name to commit to the settings """ hidden = get_setting('settings.exclude_theme_patterns') or [] if int(sublime.version()) >= 4095 and key == 'theme': yield format_completion_item(value="auto", annotation="dark-/light switching") for theme_path in ResourcePath.glob_resources("*.sublime-theme"): if not any(hide in theme_path.name for hide in hidden): yield format_completion_item( value=theme_path.name, default=default, annotation="theme" )
def _theme_completions(default): """Create completions of all visible themes. default (string): The default `theme` value. The set will not include color schemes matching at least one entry of `"settings.exclude_theme_patterns": []` setting. Returns: {(trigger, contents), ...} A set of all completions. - trigger (string): base file name of the theme - contents (string): the file name to commit to the settings """ hidden = get_setting('settings.exclude_theme_patterns') or [] completions = set() for theme_path in ResourcePath.glob_resources("*.sublime-theme"): if not any(hide in theme_path.name for hide in hidden): completions.add( format_completion_item(value=theme_path.name, default=default, description="theme")) return completions
def get_templates(): return [ TemplateDefinition(path, *parse_yaml_body(path.read_text())) for path in ResourcePath.glob_resources('*.sublime-template') ]