From 55bb8bc4ec035e6952f9ebca993d7bff0d2e0bee Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 26 Dec 2024 19:19:29 +0100 Subject: [PATCH] Adjust imports --- latextools/auto_label.py | 2 +- latextools/biblatex_name_completions.py | 4 +- latextools/biblatex_snippet_completions.py | 2 +- latextools/biblatex_syntax_listener.py | 2 +- latextools/context_provider.py | 10 +- latextools/delete_temp_files.py | 12 +- latextools/deprecated_command.py | 2 +- latextools/detect_spellcheck.py | 8 +- latextools/jumpto_anywhere.py | 14 +- latextools/jumpto_pdf.py | 19 +- latextools/jumpto_tex_file.py | 12 +- latextools/latex_cite_completions.py | 16 +- latextools/latex_cwl_completions.py | 16 +- latextools/latex_directive_completions.py | 2 +- latextools/latex_doc_viewer.py | 4 +- latextools/latex_env_completions.py | 2 +- latextools/latex_fill_all.py | 16 +- latextools/latex_glossary_completions.py | 8 +- latextools/latex_input_completions.py | 14 +- latextools/latex_installed_packages.py | 6 +- latextools/latex_own_command_completions.py | 8 +- latextools/latex_ref_completions.py | 8 +- latextools/latextools_cache_listener.py | 12 +- latextools/latextools_plugin.py | 276 ++++++++--------- latextools/make_pdf.py | 29 +- latextools/migrate.py | 286 +++++++++--------- latextools/plugin_internal/__init__.py | 93 ------ latextools/preview/__init__.py | 2 + latextools/preview/preview_image.py | 11 +- latextools/preview/preview_math.py | 15 +- latextools/preview/preview_threading.py | 3 +- latextools/preview/preview_utils.py | 23 +- latextools/reveal_folders.py | 10 +- latextools/search_commands.py | 8 +- latextools/smart_paste.py | 6 +- latextools/system_check.py | 32 +- latextools/temp_file_cleanup.py | 2 +- latextools/tex_count.py | 8 +- latextools/tex_syntax_listener.py | 4 +- latextools/toc_quickpanel.py | 8 +- latextools/toggle_settings.py | 4 +- latextools/utils/analysis.py | 4 +- latextools/utils/bibcache.py | 2 +- latextools/utils/cache.py | 3 +- latextools/utils/distro_utils.py | 1 - latextools/utils/external_command.py | 1 - latextools/utils/input_quickpanel.py | 2 +- latextools/utils/internal_types.py | 2 +- latextools/utils/logging.py | 4 +- latextools/utils/output_directory.py | 8 - latextools/utils/settings.py | 3 - latextools/utils/tex_directives.py | 2 +- latextools/utils/tex_log.py | 1 - plugin.py | 174 +++++++++++ plugins/bibliography/new_bibliography.py | 18 +- .../bibliography/traditional_bibliography.py | 8 +- plugins/builder/basic_builder.py | 6 +- plugins/builder/pdf_builder.py | 13 +- plugins/builder/script_builder.py | 6 +- plugins/viewer/base_viewer.py | 8 +- plugins/viewer/command_viewer.py | 6 +- plugins/viewer/evince_viewer.py | 10 +- plugins/viewer/okular_viewer.py | 6 +- plugins/viewer/preview_viewer.py | 2 +- plugins/viewer/skim_viewer.py | 4 +- plugins/viewer/sumatra_viewer.py | 6 +- plugins/viewer/zathura_viewer.py | 8 +- tests/test_context.py | 2 +- tests/test_selectors.py | 2 +- 69 files changed, 680 insertions(+), 651 deletions(-) delete mode 100644 latextools/plugin_internal/__init__.py create mode 100644 latextools/preview/__init__.py create mode 100644 plugin.py diff --git a/latextools/auto_label.py b/latextools/auto_label.py index 05d44cf6a..4a6051644 100644 --- a/latextools/auto_label.py +++ b/latextools/auto_label.py @@ -3,7 +3,7 @@ import sublime import sublime_plugin -from .latextools_utils.settings import get_setting +from .utils.settings import get_setting __all__ = [ "LatextoolsAutoInsertLabelCommand", diff --git a/latextools/biblatex_name_completions.py b/latextools/biblatex_name_completions.py index 469369b3b..83eb2e203 100644 --- a/latextools/biblatex_name_completions.py +++ b/latextools/biblatex_name_completions.py @@ -4,8 +4,8 @@ import sublime import sublime_plugin -from .external.bibtex.names import Name -from .external.bibtex.tex import tokenize_list +from .libs.bibtex.names import Name +from .libs.bibtex.tex import tokenize_list __all__ = ["BiblatexNameCompletions"] diff --git a/latextools/biblatex_snippet_completions.py b/latextools/biblatex_snippet_completions.py index 97ec69666..0d750226b 100644 --- a/latextools/biblatex_snippet_completions.py +++ b/latextools/biblatex_snippet_completions.py @@ -9,7 +9,7 @@ import sublime import sublime_plugin -from .latextools_utils.logging import logger +from .utils.logging import logger __all__ = ["SnippetCompletions"] diff --git a/latextools/biblatex_syntax_listener.py b/latextools/biblatex_syntax_listener.py index ad259026f..c8dedd3b7 100644 --- a/latextools/biblatex_syntax_listener.py +++ b/latextools/biblatex_syntax_listener.py @@ -1,6 +1,6 @@ import sublime_plugin -from .latextools_utils.settings import get_setting +from .utils.settings import get_setting __all__ = ["BibLaTeXSyntaxListener"] diff --git a/latextools/context_provider.py b/latextools/context_provider.py index cad0a2a8b..8e64a4882 100644 --- a/latextools/context_provider.py +++ b/latextools/context_provider.py @@ -5,11 +5,11 @@ from functools import partial -from .latextools_utils import analysis -from .latextools_utils.logging import logger -from .latextools_utils.selectors import build_ast -from .latextools_utils.selectors import match_selector -from .latextools_utils.settings import get_setting +from .utils import analysis +from .utils.logging import logger +from .utils.selectors import build_ast +from .utils.selectors import match_selector +from .utils.settings import get_setting __all__ = ["LatextoolsContextListener"] diff --git a/latextools/delete_temp_files.py b/latextools/delete_temp_files.py index a39111ba8..351cca652 100644 --- a/latextools/delete_temp_files.py +++ b/latextools/delete_temp_files.py @@ -6,12 +6,12 @@ from .deprecated_command import deprecate -from .latextools_utils import cache -from .latextools_utils.logging import logger -from .latextools_utils.output_directory import get_aux_directory -from .latextools_utils.output_directory import get_output_directory -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root +from .utils import cache +from .utils.logging import logger +from .utils.output_directory import get_aux_directory +from .utils.output_directory import get_output_directory +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root __all__ = [ "LatextoolsClearCacheCommand", diff --git a/latextools/deprecated_command.py b/latextools/deprecated_command.py index 1bf18be4a..af33423a3 100644 --- a/latextools/deprecated_command.py +++ b/latextools/deprecated_command.py @@ -1,7 +1,7 @@ import sublime import sublime_plugin -from .latextools_utils.logging import logger +from .utils.logging import logger __all__ = ["deprecate", "LatextoolsFindDeprecatedCommandsCommand"] diff --git a/latextools/detect_spellcheck.py b/latextools/detect_spellcheck.py index ec85b5209..ff03c8999 100644 --- a/latextools/detect_spellcheck.py +++ b/latextools/detect_spellcheck.py @@ -1,10 +1,10 @@ import sublime_plugin from .deprecated_command import deprecate -from .latextools_utils.logging import logger -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root -from .latextools_utils.tex_directives import parse_tex_directives +from .utils.logging import logger +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root +from .utils.tex_directives import parse_tex_directives try: # check whether the dictionaries package is installed import Dictionaries diff --git a/latextools/jumpto_anywhere.py b/latextools/jumpto_anywhere.py index 722900e1a..1c3e933ea 100644 --- a/latextools/jumpto_anywhere.py +++ b/latextools/jumpto_anywhere.py @@ -5,13 +5,13 @@ import sublime_plugin from .deprecated_command import deprecate -from .latextools_utils import analysis -from .latextools_utils import ana_utils -from .latextools_utils import quickpanel -from .latextools_utils import utils -from .latextools_utils.logging import logger -from .latextools_utils.tex_directives import get_tex_root -from .latextools_utils.tex_directives import TEX_DIRECTIVE +from .utils import analysis +from .utils import ana_utils +from .utils import quickpanel +from .utils import utils +from .utils.logging import logger +from .utils.tex_directives import get_tex_root +from .utils.tex_directives import TEX_DIRECTIVE from .latex_cite_completions import NEW_STYLE_CITE_REGEX from .latex_glossary_completions import ACR_LINE_RE from .latex_glossary_completions import GLO_LINE_RE diff --git a/latextools/jumpto_pdf.py b/latextools/jumpto_pdf.py index 75ee8443e..6fa196181 100644 --- a/latextools/jumpto_pdf.py +++ b/latextools/jumpto_pdf.py @@ -7,18 +7,17 @@ from .deprecated_command import deprecate from .latextools_plugin import add_plugin_path -from .latextools_plugin import add_whitelist_module from .latextools_plugin import get_plugin from .latextools_plugin import NoSuchPluginException -from .latextools_utils.is_tex_file import is_tex_file -from .latextools_utils.output_directory import get_jobname -from .latextools_utils.output_directory import get_output_directory -from .latextools_utils.logging import logger -from .latextools_utils.settings import get_setting -from .latextools_utils.sublime_utils import focus_st -from .latextools_utils.tex_directives import get_tex_root - -__all__ = ["LatextoolsJumptoPdfCommand", "LatextoolsViewPdfCommand", "plugin_loaded"] +from .utils.is_tex_file import is_tex_file +from .utils.logging import logger +from .utils.output_directory import get_jobname +from .utils.output_directory import get_output_directory +from .utils.settings import get_setting +from .utils.sublime_utils import focus_st +from .utils.tex_directives import get_tex_root + +__all__ = ["LatextoolsJumptoPdfCommand", "LatextoolsViewPdfCommand"] SUBLIME_VERSION = re.compile(r"Build (\d{4})", re.UNICODE) DEFAULT_VIEWERS = {"linux": "evince", "osx": "skim", "windows": "sumatra"} diff --git a/latextools/jumpto_tex_file.py b/latextools/jumpto_tex_file.py index 5fdcfe03c..0a7af958f 100644 --- a/latextools/jumpto_tex_file.py +++ b/latextools/jumpto_tex_file.py @@ -8,12 +8,12 @@ import sublime_plugin from .deprecated_command import deprecate -from .latextools_utils import analysis -from .latextools_utils import utils -from .latextools_utils.external_command import external_command -from .latextools_utils.logging import logger -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root +from .utils import analysis +from .utils import utils +from .utils.external_command import external_command +from .utils.logging import logger +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root __all__ = ["LatextoolsJumptoFileCommand"] diff --git a/latextools/latex_cite_completions.py b/latextools/latex_cite_completions.py index 0c62f80f5..4b4b91348 100644 --- a/latextools/latex_cite_completions.py +++ b/latextools/latex_cite_completions.py @@ -22,14 +22,14 @@ import traceback from .latex_fill_all import FillAllHelper -from .latextools_utils import analysis -from .latextools_utils import bibformat -from .latextools_utils import cache -from .latextools_utils.external_command import CalledProcessError -from .latextools_utils.external_command import check_output -from .latextools_utils.logging import logger -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root +from .utils import analysis +from .utils import bibformat +from .utils import cache +from .utils.external_command import CalledProcessError +from .utils.external_command import check_output +from .utils.logging import logger +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root from . import latextools_plugin diff --git a/latextools/latex_cwl_completions.py b/latextools/latex_cwl_completions.py index 75a1880c3..65b1ffc68 100644 --- a/latextools/latex_cwl_completions.py +++ b/latextools/latex_cwl_completions.py @@ -15,14 +15,14 @@ from .latex_own_command_completions import get_own_env_completion from .latex_ref_completions import NEW_STYLE_REF_REGEX from .latex_ref_completions import OLD_STYLE_REF_REGEX -from .latextools_utils import analysis -from .latextools_utils import utils -from .latextools_utils.logging import logger -from .latextools_utils.parser_utils import command_to_snippet -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root - -__all__ = ["LatexCwlCompletion", "plugin_loaded"] +from .utils import analysis +from .utils import utils +from .utils.parser_utils import command_to_snippet +from .utils.logging import logger +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root + +__all__ = ["LatexCwlCompletion"] ST_VER = int(sublime.version()) diff --git a/latextools/latex_directive_completions.py b/latextools/latex_directive_completions.py index 3617808a3..51d56adf0 100644 --- a/latextools/latex_directive_completions.py +++ b/latextools/latex_directive_completions.py @@ -6,7 +6,7 @@ from . import detect_spellcheck from .latex_fill_all import FillAllHelper -from .latextools_utils.settings import get_setting +from .utils.settings import get_setting try: installed_locales = sorted(detect_spellcheck._dictionary_mappings.keys()) diff --git a/latextools/latex_doc_viewer.py b/latextools/latex_doc_viewer.py index 3d6a3b6d7..4f485b2fd 100644 --- a/latextools/latex_doc_viewer.py +++ b/latextools/latex_doc_viewer.py @@ -4,8 +4,8 @@ import sublime_plugin from .deprecated_command import deprecate -from .latextools_utils.distro_utils import using_miktex -from .latextools_utils.external_command import external_command +from .utils.distro_utils import using_miktex +from .utils.external_command import external_command __all__ = ["LatextoolsPkgDocCommand", "LatextoolsViewDocCommand"] diff --git a/latextools/latex_env_completions.py b/latextools/latex_env_completions.py index 2e4365795..fda1a13f3 100644 --- a/latextools/latex_env_completions.py +++ b/latextools/latex_env_completions.py @@ -1,5 +1,5 @@ from .latex_fill_all import FillAllHelper -from .latextools_utils.settings import get_setting +from .utils.settings import get_setting from .latex_cwl_completions import BEGIN_END_BEFORE_REGEX from .latex_cwl_completions import get_cwl_completions from .latex_cwl_completions import is_cwl_available diff --git a/latextools/latex_fill_all.py b/latextools/latex_fill_all.py index af9fa1a1a..be64176e5 100644 --- a/latextools/latex_fill_all.py +++ b/latextools/latex_fill_all.py @@ -8,11 +8,17 @@ from .deprecated_command import deprecate from .latextools_plugin import _classname_to_internal_name from .latextools_plugin import get_plugins_by_type -from .latextools_utils.logging import logger -from .latextools_utils.settings import get_setting -from .latextools_utils.internal_types import FillAllHelper -from .latextools_utils.input_quickpanel import show_input_quick_panel - +from .utils.logging import logger +from .utils.settings import get_setting +from .utils.internal_types import FillAllHelper +from .utils.input_quickpanel import show_input_quick_panel + +__all__ = [ + "LatexFillAllEventListener", + "LatextoolsFillAllCommand", + "LatexToolsFillAllCompleteBracket", + "LatexToolsReplaceWord", +] def reraise(tp, value, tb=None): if value is None: diff --git a/latextools/latex_glossary_completions.py b/latextools/latex_glossary_completions.py index 6d89319cc..92abfa77a 100644 --- a/latextools/latex_glossary_completions.py +++ b/latextools/latex_glossary_completions.py @@ -1,10 +1,10 @@ import re from .latex_fill_all import FillAllHelper -from .latextools_utils import analysis -from .latextools_utils import cache -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root +from .utils import analysis +from .utils import cache +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root GLO_LINE_RE = re.compile(r"([^{}\[\]]*)\{*?(?:lp|lobmys)?sl(?:G|g)\\") diff --git a/latextools/latex_input_completions.py b/latextools/latex_input_completions.py index f1f825aab..9fe2d6a45 100644 --- a/latextools/latex_input_completions.py +++ b/latextools/latex_input_completions.py @@ -5,13 +5,13 @@ import sublime from .latex_fill_all import FillAllHelper -from .latextools_utils import analysis -from .latextools_utils.is_tex_file import get_tex_extensions -from .latextools_utils.logging import logger -from .latextools_utils.output_directory import get_aux_directory -from .latextools_utils.output_directory import get_output_directory -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root +from .utils import analysis +from .utils.is_tex_file import get_tex_extensions +from .utils.output_directory import get_aux_directory +from .utils.output_directory import get_output_directory +from .utils.logging import logger +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root def _filter_invalid_entries(entries): diff --git a/latextools/latex_installed_packages.py b/latextools/latex_installed_packages.py index e1ceb1d0f..692f7ae38 100644 --- a/latextools/latex_installed_packages.py +++ b/latextools/latex_installed_packages.py @@ -12,9 +12,9 @@ import sublime_plugin from .deprecated_command import deprecate -from .latextools_utils.external_command import CalledProcessError -from .latextools_utils.external_command import check_output -from .latextools_utils.logging import logger +from .utils.external_command import CalledProcessError +from .utils.external_command import check_output +from .utils.logging import logger __all__ = ["LatextoolsGenPkgCacheCommand"] diff --git a/latextools/latex_own_command_completions.py b/latextools/latex_own_command_completions.py index 31f42a947..72df7043d 100644 --- a/latextools/latex_own_command_completions.py +++ b/latextools/latex_own_command_completions.py @@ -1,7 +1,7 @@ -from .latextools_utils import analysis -from .latextools_utils import cache -from .latextools_utils.parser_utils import command_to_snippet -from .latextools_utils.tex_directives import get_tex_root +from .utils import analysis +from .utils import cache +from .utils.parser_utils import command_to_snippet +from .utils.tex_directives import get_tex_root class NoArgs(Exception): diff --git a/latextools/latex_ref_completions.py b/latextools/latex_ref_completions.py index 26a1ab1a2..dfc762c0c 100644 --- a/latextools/latex_ref_completions.py +++ b/latextools/latex_ref_completions.py @@ -1,8 +1,8 @@ from .latex_fill_all import FillAllHelper -from .latextools_utils import analysis -from .latextools_utils.logging import logger -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root +from .utils import analysis +from .utils.logging import logger +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root import re diff --git a/latextools/latextools_cache_listener.py b/latextools/latextools_cache_listener.py index c7cdcc4c5..6d957d8c2 100644 --- a/latextools/latextools_cache_listener.py +++ b/latextools/latextools_cache_listener.py @@ -8,12 +8,12 @@ from .latex_cite_completions import find_bib_files from .latex_cite_completions import run_plugin_command -from .latextools_utils import analysis -from .latextools_utils.activity_indicator import ActivityIndicator -from .latextools_utils.cache import LocalCache -from .latextools_utils.logging import logger -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root +from .utils import analysis +from .utils.activity_indicator import ActivityIndicator +from .utils.cache import LocalCache +from .utils.logging import logger +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root __all__ = [ "LatextoolsCacheUpdateListener", diff --git a/latextools/latextools_plugin.py b/latextools/latextools_plugin.py index 414aa7ac7..4ce1e1f9d 100644 --- a/latextools/latextools_plugin.py +++ b/latextools/latextools_plugin.py @@ -86,50 +86,45 @@ def do_something(): plugin is the first entry on sys.path, enabling import of any modules located in the same folder, according to standard Python import rules. In addition, the standard modules available to SublimeText are available. In addition, a small -number of modules from LaTeXTools itself can be made available. This list of -modules can be configured either through the `plugins_whitelist` configuration -option in the settings file or by using the `add_whitelist_module()` function -defined in this module. - -Configuration options: - `plugins_whitelist`: - A list of LaTeXTools module names to be made available via sys.modules - when loading plugins. This names do not need to be the fully - qualified name, but should be the name of the module relative to the - LaTeXTools folder (i.e. "latextools_utils" rather than - "LaTeXTools.latextools_utils") as this ensures compatibility between - ST2 and ST3. - -API: - `add_whitelist_module()`: can be used in a manner similar to the - `plugins_whitelist` option described above, i.e. called with the name of a - module to add to the list of modules available in sys.modules when a - LaTeXTools plugin is loaded. The optional argument, `module`, if used - should be a Python module object (normally obtained from `sys.modules`). - This is primarily intended to expose a module that would not otherwise be - available or expose an already available module to plugins under a - different name. +number of modules from LaTeXTools itself can be made available. """ - import glob as _glob import os -import sublime +import re import sys import threading import traceback from contextlib import contextmanager from collections.abc import MutableMapping +from importlib.machinery import PathFinder, SourceFileLoader + +import sublime -from .latextools_utils.logging import logger -from .latextools_utils.settings import get_setting -from . import latextools_plugin_internal as internal +from .utils.logging import logger +from .utils.settings import get_setting -# this is used to load plugins and not interfere with other modules -_MODULE_PREFIX = "_latextools_" +_MODULE_PREFIX = 'LaTeXTools.plugins.' +"""this is used to load plugins and not interfere with other modules""" +_REGISTRY = None + +_REGISTERED_PATHS_TO_LOAD = [] +""" +list of tuples consisting of a path and a glob to load in the plugin_loaded() +method to handle the case where `add_plugin_path` is called before this +module has been fully loaded. +""" + +_REGISTERED_CLASSES_TO_LOAD = [] +""" +list of tuples consisting of names and class objects to load in the +plugin_loaded() method to handle the case where a plugin is defined before +the registry has been created +""" + +# -- Public API -- # -# -- Public API --# # exceptions class LaTeXToolsPluginException(Exception): """ @@ -160,7 +155,42 @@ class InvalidPluginException(LaTeXToolsPluginException): pass -LaTeXToolsPlugin = internal.LaTeXToolsPlugin +class LaTeXToolsPluginMeta(type): + ''' + Metaclass for plugins which will automatically register them with the + plugin registry + ''' + def __init__(cls, name, bases, attrs): + try: + super(LaTeXToolsPluginMeta, cls).__init__(name, bases, attrs) + except TypeError: + # occurs on reload + return + + if cls == LaTeXToolsPluginMeta or cls is None: + return + + try: + if not any( + (True for base in bases if issubclass(base, LaTeXToolsPlugin)) + ): + return + except NameError: + return + + registered_name = _classname_to_internal_name(name) + + _REGISTERED_CLASSES_TO_LOAD.append((registered_name, cls)) + + if _REGISTRY is not None: + _REGISTRY[registered_name] = cls + + +LaTeXToolsPlugin = LaTeXToolsPluginMeta('LaTeXToolsPlugin', (object,), {}) +''' +Base class for LaTeXTools plugins. Implementation details will depend on where +this plugin is supposed to be loaded. See the documentation for details. +''' # methods for consumers @@ -174,67 +204,40 @@ def add_plugin_path(path, glob="*.py"): `glob`, if specified should be a valid Python glob. See the `glob` module. """ - if (path, glob) not in internal._REGISTERED_PATHS_TO_LOAD: - internal._REGISTERED_PATHS_TO_LOAD.append((path, glob)) + if (path, glob) not in _REGISTERED_PATHS_TO_LOAD: + _REGISTERED_PATHS_TO_LOAD.append((path, glob)) # if we are called before `plugin_loaded` - if internal._REGISTRY is None: + if _REGISTRY is None: return - previous_plugins = set(internal._REGISTRY.keys()) + previous_plugins = set(_REGISTRY.keys()) - with _latextools_module_hack(): - if not os.path.exists(path): - return + if not os.path.exists(path): + return - if os.path.isfile(path): - plugin_dir = os.path.dirname(path) - sys.path.insert(0, plugin_dir) + if os.path.isfile(path): + plugin_dir = os.path.dirname(path) + sys.path.insert(0, plugin_dir) - _load_plugin(os.path.basename(path), plugin_dir) + _load_plugin(os.path.basename(path), plugin_dir) - sys.path.pop(0) - else: - for file in _glob.iglob(os.path.join(path, glob)): - plugin_dir = os.path.dirname(file) - sys.path.insert(0, plugin_dir) + sys.path.pop(0) + else: + for file in _glob.iglob(os.path.join(path, glob)): + plugin_dir = os.path.dirname(file) + sys.path.insert(0, plugin_dir) - _load_plugin(os.path.basename(file), plugin_dir) + _load_plugin(os.path.basename(file), plugin_dir) - sys.path.pop(0) + sys.path.pop(0) logger.info( "Loaded plugins %s from path '%s'", - list(set(internal._REGISTRY.keys()) - previous_plugins), + list(set(_REGISTRY.keys()) - previous_plugins), path, ) - -def add_whitelist_module(name, module=None): - """ - API function to ensure that a certain module is made available to any - plugins. - - `name` should be the name of the module as it will be imported in a plugin - `module`, if specified, should be either an actual module object or a - callable that returns the actual module object. - - The `module` mechanism is provided to allow for the import of modules that - might otherwise be unavailable or available in sys.modules only by a - different name. Standard LaTeXTools modules should provide a name only. - - Note that this function *must* be called before add_plugin_path. - """ - for i, (_name, _module) in enumerate(internal._WHITELIST_ADDED): - if _name == name: - if _module == module: - return - internal._WHITELIST_ADDED[i] = (_name, module) - return - - internal._WHITELIST_ADDED.append((name, module)) - - def get_plugin(name): """ This is intended to be the main entry-point used by consumers (not @@ -250,30 +253,27 @@ def get_plugin(name): For example, 'biblatex' will get the plugin named 'BibLaTeX', etc. """ - if internal._REGISTRY is None: + if _REGISTRY is None: raise NoSuchPluginException( "Could not load plugin {0} because the registry either hasn't " + "been loaded or has just been unloaded.".format(name) ) - return internal._REGISTRY[name] + return _REGISTRY[name] def get_plugins_by_type(cls): - if internal._REGISTRY is None: + if _REGISTRY is None: raise NoSuchPluginException( "No plugins could be loaded because the registry either hasn't " "been loaded or has been unloaded" ) - plugins = [plugin for _, plugin in internal._REGISTRY.items() if issubclass(plugin, cls)] + plugins = [plugin for _, plugin in _REGISTRY.items() if issubclass(plugin, cls)] return plugins # -- Private API --# -from importlib.machinery import PathFinder, SourceFileLoader -from . import latextools_plugin_internal as internal - # WARNING: # imp module is deprecated in 3.x, unfortunately, importlib does not seem @@ -326,7 +326,7 @@ def __getitem__(self, key): ) def __setitem__(self, key, value): - if not isinstance(value, internal.LaTeXToolsPluginMeta): + if not isinstance(value, LaTeXToolsPluginMeta): raise InvalidPluginException(value) self._registry[key] = value @@ -344,7 +344,36 @@ def __str__(self): return str(self._registry) -_classname_to_internal_name = internal._classname_to_internal_name +def _classname_to_internal_name(s): + ''' + Converts a Python class name in to an internal name + + The intention here is to mirror how ST treats *Command objects, i.e., by + converting them from CamelCase to under_scored. Similarly, we will chop + "Plugin" off the end of the plugin, though it isn't necessary for the class + to be treated as a plugin. + + E.g., + SomeClass will become some_class + ReferencesPlugin will become references + BibLaTeXPlugin will become biblatex + ''' + if not s: + return s + + def _repl(match): + match = match.group(0) + return match[0] + match[1:].lower() + + s = re.sub(r'(?:Bib)?(?:La)?TeX', _repl, s) + + # pilfered from https://code.activestate.com/recipes/66009/ + s = re.sub(r'(?<=[a-z])[A-Z]|(?", s).lower() + + if s.endswith('_plugin'): + s = s[:-7] + + return s def _get_plugin_paths(): @@ -398,82 +427,17 @@ def _resolve_plugin_path(path): traceback.print_exc() -@contextmanager -def _latextools_module_hack(): - """ - Context manager to ensure sys.modules has certain white-listed modules, - most especially latextools_plugins. This exposes some of the modules in - LaTeXTools to plugins. It is intended primarily to expose library-esque - functionality, such as the tex_directives module, but can be configured by - the user as-needed. - """ - # add any white-listed plugins to sys.modules under their own name - plugins_whitelist = get_setting("plugins_whitelist", ["external", "latextools_utils"]) - - # always include latextools_pluing - plugins_whitelist.append("latextools_plugin") - overwritten_modules = {} - - whitelist = [(name, None) for name in plugins_whitelist] - whitelist.extend(internal._WHITELIST_ADDED) - - # put the directory containing this file on the sys.path - mydir = os.path.dirname(__file__) - - # handles ST2s relative directory - if mydir == ".": - mydir = os.path.join(sublime.packages_path(), "LaTeXTools") - - # insert the LaTeXTools directory on the path - sys.path.insert(0, mydir) - for name, module in whitelist: - if callable(module): - module = module() - - if name in sys.modules: - overwritten_modules[name] = sys.modules[name] - - # attempting to autoload module - if module is None: - # if the module has already been loaded by ST, we just use that - latextools_module_name = _get_sublime_module_name(mydir, name) - if latextools_module_name in sys.modules: - sys.modules[name] = sys.modules[latextools_module_name] - else: - try: - sys.modules[name] = _load_module(name, name, mydir) - except ImportError: - logger.error( - "An error occurred while trying to load white-listed module %s", - name, - ) - traceback.print_exc() - else: - sys.modules[name] = module - - # remove the LaTeXTools directory from the path - sys.path.pop(0) - - yield - - # restore any temporarily overwritten modules and clear our loaded modules - for module in plugins_whitelist: - if module in sys.modules and _get_sublime_module_name(mydir, module) != module: - del sys.modules[module] - if module in overwritten_modules: - sys.modules[module] = overwritten_modules[module] - - # load plugins when the Sublime API is available, just in case... def plugin_loaded(): - internal._REGISTRY = LaTeXToolsPluginRegistry() + global _REGISTRY + _REGISTRY = LaTeXToolsPluginRegistry() logger.info("Loading LaTeXTools plugins...") - for name, cls in internal._REGISTERED_CLASSES_TO_LOAD: - internal._REGISTRY[name] = cls + for name, cls in _REGISTERED_CLASSES_TO_LOAD: + _REGISTRY[name] = cls _load_plugins() - for path, glob in internal._REGISTERED_PATHS_TO_LOAD: + for path, glob in _REGISTERED_PATHS_TO_LOAD: add_plugin_path(path, glob) diff --git a/latextools/make_pdf.py b/latextools/make_pdf.py index 358f4bb83..ad6fd81e5 100644 --- a/latextools/make_pdf.py +++ b/latextools/make_pdf.py @@ -16,27 +16,26 @@ from .latextools_plugin import add_plugin_path from .latextools_plugin import get_plugin from .latextools_plugin import NoSuchPluginException -from .latextools_utils.activity_indicator import ActivityIndicator -from .latextools_utils.external_command import execute_command -from .latextools_utils.external_command import external_command -from .latextools_utils.external_command import get_texpath -from .latextools_utils.external_command import update_env -from .latextools_utils.is_tex_file import is_tex_file -from .latextools_utils.logging import logger -from .latextools_utils.output_directory import get_aux_directory -from .latextools_utils.output_directory import get_jobname -from .latextools_utils.output_directory import get_output_directory -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root -from .latextools_utils.tex_directives import parse_tex_directives -from .latextools_utils.tex_log import parse_tex_log +from .utils.activity_indicator import ActivityIndicator +from .utils.external_command import execute_command +from .utils.external_command import external_command +from .utils.external_command import get_texpath +from .utils.external_command import update_env +from .utils.is_tex_file import is_tex_file +from .utils.logging import logger +from .utils.output_directory import get_aux_directory +from .utils.output_directory import get_jobname +from .utils.output_directory import get_output_directory +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root +from .utils.tex_directives import parse_tex_directives +from .utils.tex_log import parse_tex_log __all__ = [ "LatextoolsMakePdfCommand", "LatextoolsDoOutputEditCommand", "LatextoolsDoFinishEditCommand", "LatextoolsExecEventListener", - "plugin_loaded", ] # Compile current .tex file to pdf diff --git a/latextools/migrate.py b/latextools/migrate.py index e8df7d2d0..3cdbb6da7 100644 --- a/latextools/migrate.py +++ b/latextools/migrate.py @@ -1,143 +1,143 @@ -import sublime -import sublime_plugin -import os -import codecs - -from .latextools_utils.logging import logger - -__all__ = ["LatextoolsMigrateCommand"] - -# Copy settings from default file to user directory -# Try to incorporate existing user settings - -DEFAULT_SETTINGS = "LaTeXTools.sublime-settings" -USER_SETTINGS = "LaTeXTools.sublime-settings" -OLD_SETTINGS = "LaTeXTools Preferences.sublime-settings" - -# Settings to be ported over -# "key" is the preference key -# "type" is the type, for fixups (e.g. true vs. True) -# "line" is the line in the .default-settings file (starting from 0, not 1); -# the code below looks for it, but set to -1 to flag errors, issues, etc. -# "tabs" is the number of tabs before the key -# "last" is True if it's the last line in a {...} block (so must omit comma at the end) -# WARNING: obviously, this works ONLY with a known default-settings file. -settings = [ - {"key": "cite_auto_trigger", "type": "bool", "line": -1, "tabs": 1, "last": False}, - {"key": "ref_auto_trigger", "type": "bool", "line": -1, "tabs": 1, "last": False}, - {"key": "keep_focus", "type": "bool", "line": -1, "tabs": 1, "last": False}, - {"key": "forward_sync", "type": "bool", "line": -1, "tabs": 1, "last": False}, - {"key": "python2", "type": "string", "line": -1, "tabs": 2, "last": False}, - {"key": "sublime", "type": "string", "line": -1, "tabs": 2, "last": False}, - {"key": "sync_wait", "type": "num", "line": -1, "tabs": 2, "last": True}, - {"key": "cite_panel_format", "type": "list", "line": -1, "tabs": 1, "last": False }, - {"key": "cite_autocomplete_format", "type": "string", "line": -1, "tabs": 1, "last": True} -] - -class LatextoolsMigrateCommand(sublime_plugin.ApplicationCommand): - - def run(self): - - # First of all, try to load new settings - # If they exist, either the user copied them manually, or we already did this - # Hence, quit - # NOTE: we will move this code somewhere else, but for now, it's here - - logger.info("Running settings reset") - sublime.status_message("Resetting user settings to default...") - ltt_path = os.path.join(sublime.packages_path(),"LaTeXTools") - user_path = os.path.join(sublime.packages_path(),"User") - default_file = os.path.join(ltt_path,DEFAULT_SETTINGS) - user_file = os.path.join(user_path,USER_SETTINGS) - old_file = os.path.join(user_path,OLD_SETTINGS) - - killall = False # So final message check works even if there is no existing setting file - if os.path.exists(user_file): - killall = sublime.ok_cancel_dialog(USER_SETTINGS + " already exists in the User directory!\n" - "Are you sure you want to DELETE YOUR CURRENT SETTINGS and reset them to default?", - "DELETE current settings") - if not killall: - sublime.message_dialog("OK, I will preserve your existing settings.") - return - - with codecs.open(default_file,'r','UTF-8') as def_fp: - def_lines = def_fp.readlines() - - quotes = "\"" - - # Find lines where keys are in the default file - comments = False - for i in range(len(def_lines)): - l = def_lines[i].strip() # Get rid of tabs and leading spaces - # skip comments - # This works as long as multiline comments do not start/end on a line that - # also contains code. - # It's also safest if a line with code does NOT also contain comments - beg_cmts = l[:2] - end_cmts = l[-2:] - if comments: - if beg_cmts == "*/": - comments = False - l = l[2:] # and process the line just in case - elif end_cmts == "*/": - comments = False - continue - else: # HACK: this fails if we have "...*/ ", which however is bad form - continue - if beg_cmts=="//": # single-line comments - continue - if beg_cmts=="/*": # Beginning of multiline comment. - comments = True # HACK: this fails if " /* ..." begins a multiline comment - continue - for s in settings: - # Be conservative: precise match. - m = quotes + s["key"] + quotes + ":" - if m == l[:len(m)]: - s["line"] = i - logger.info(s["key"] + " is on line " + str(i) + " (0-based)") - - # Collect needed modifications - def_modify = {} - s_old = sublime.load_settings(OLD_SETTINGS) - for s in settings: - key = s["key"] - logger.info("Trying " + key) - s_old_entry = s_old.get(key) - if s_old_entry is not None: # Checking for True misses all bool's set to False! - logger.info("Porting " + key) - l = s["tabs"]*"\t" + quotes + key + quotes + ": " - if s["type"]=="bool": - l += "true" if s_old_entry==True else "false" - elif s["type"]=="num": - l += str(s_old_entry) - elif s["type"]=="list": # HACK HACK HACK! List of strings only! - l += "[" - for el in s_old_entry: - l += quotes + el + quotes + "," - l = l[:-1] + "]" # replace last comma with bracket - else: - l += quotes + s_old_entry + quotes - if s["last"]: # Add comma, unless at the end of a {...} block - l+= "\n" - else: - l += ",\n" - logger.info(l) - def_lines[s["line"]] = l - - # Modify text saying "don't touch this!" in the default file - def_lines[0] = '// LaTeXTools Preferences\n' - def_lines[2] = '// Keep in the User directory. Personalize as needed\n' - for i in range(3, 10): - def_lines.pop(3) # Must be 3: 4 becomes 3, then 5 becomes 3... - - with codecs.open(user_file,'w','UTF-8') as user_fp: - user_fp.writelines(def_lines) - - if killall: - msg_preserved = "" - else: - msg_preserved = "Old-style, pre-2014 settings (if any) have been migrated." - sublime.status_message("Settings reset to default.") - sublime.message_dialog("LaTeXTools settings successfully reset to default. " + msg_preserved) - return - +import sublime +import sublime_plugin +import os +import codecs + +from .utils.logging import logger + +__all__ = ["LatextoolsMigrateCommand"] + +# Copy settings from default file to user directory +# Try to incorporate existing user settings + +DEFAULT_SETTINGS = "LaTeXTools.sublime-settings" +USER_SETTINGS = "LaTeXTools.sublime-settings" +OLD_SETTINGS = "LaTeXTools Preferences.sublime-settings" + +# Settings to be ported over +# "key" is the preference key +# "type" is the type, for fixups (e.g. true vs. True) +# "line" is the line in the .default-settings file (starting from 0, not 1); +# the code below looks for it, but set to -1 to flag errors, issues, etc. +# "tabs" is the number of tabs before the key +# "last" is True if it's the last line in a {...} block (so must omit comma at the end) +# WARNING: obviously, this works ONLY with a known default-settings file. +settings = [ + {"key": "cite_auto_trigger", "type": "bool", "line": -1, "tabs": 1, "last": False}, + {"key": "ref_auto_trigger", "type": "bool", "line": -1, "tabs": 1, "last": False}, + {"key": "keep_focus", "type": "bool", "line": -1, "tabs": 1, "last": False}, + {"key": "forward_sync", "type": "bool", "line": -1, "tabs": 1, "last": False}, + {"key": "python2", "type": "string", "line": -1, "tabs": 2, "last": False}, + {"key": "sublime", "type": "string", "line": -1, "tabs": 2, "last": False}, + {"key": "sync_wait", "type": "num", "line": -1, "tabs": 2, "last": True}, + {"key": "cite_panel_format", "type": "list", "line": -1, "tabs": 1, "last": False }, + {"key": "cite_autocomplete_format", "type": "string", "line": -1, "tabs": 1, "last": True} +] + +class LatextoolsMigrateCommand(sublime_plugin.ApplicationCommand): + + def run(self): + + # First of all, try to load new settings + # If they exist, either the user copied them manually, or we already did this + # Hence, quit + # NOTE: we will move this code somewhere else, but for now, it's here + + logger.info("Running settings reset") + sublime.status_message("Resetting user settings to default...") + ltt_path = os.path.join(sublime.packages_path(),"LaTeXTools") + user_path = os.path.join(sublime.packages_path(),"User") + default_file = os.path.join(ltt_path,DEFAULT_SETTINGS) + user_file = os.path.join(user_path,USER_SETTINGS) + old_file = os.path.join(user_path,OLD_SETTINGS) + + killall = False # So final message check works even if there is no existing setting file + if os.path.exists(user_file): + killall = sublime.ok_cancel_dialog(USER_SETTINGS + " already exists in the User directory!\n" + "Are you sure you want to DELETE YOUR CURRENT SETTINGS and reset them to default?", + "DELETE current settings") + if not killall: + sublime.message_dialog("OK, I will preserve your existing settings.") + return + + with codecs.open(default_file,'r','UTF-8') as def_fp: + def_lines = def_fp.readlines() + + quotes = "\"" + + # Find lines where keys are in the default file + comments = False + for i in range(len(def_lines)): + l = def_lines[i].strip() # Get rid of tabs and leading spaces + # skip comments + # This works as long as multiline comments do not start/end on a line that + # also contains code. + # It's also safest if a line with code does NOT also contain comments + beg_cmts = l[:2] + end_cmts = l[-2:] + if comments: + if beg_cmts == "*/": + comments = False + l = l[2:] # and process the line just in case + elif end_cmts == "*/": + comments = False + continue + else: # HACK: this fails if we have "...*/ ", which however is bad form + continue + if beg_cmts=="//": # single-line comments + continue + if beg_cmts=="/*": # Beginning of multiline comment. + comments = True # HACK: this fails if " /* ..." begins a multiline comment + continue + for s in settings: + # Be conservative: precise match. + m = quotes + s["key"] + quotes + ":" + if m == l[:len(m)]: + s["line"] = i + logger.info(s["key"] + " is on line " + str(i) + " (0-based)") + + # Collect needed modifications + def_modify = {} + s_old = sublime.load_settings(OLD_SETTINGS) + for s in settings: + key = s["key"] + logger.info("Trying " + key) + s_old_entry = s_old.get(key) + if s_old_entry is not None: # Checking for True misses all bool's set to False! + logger.info("Porting " + key) + l = s["tabs"]*"\t" + quotes + key + quotes + ": " + if s["type"]=="bool": + l += "true" if s_old_entry==True else "false" + elif s["type"]=="num": + l += str(s_old_entry) + elif s["type"]=="list": # HACK HACK HACK! List of strings only! + l += "[" + for el in s_old_entry: + l += quotes + el + quotes + "," + l = l[:-1] + "]" # replace last comma with bracket + else: + l += quotes + s_old_entry + quotes + if s["last"]: # Add comma, unless at the end of a {...} block + l+= "\n" + else: + l += ",\n" + logger.info(l) + def_lines[s["line"]] = l + + # Modify text saying "don't touch this!" in the default file + def_lines[0] = '// LaTeXTools Preferences\n' + def_lines[2] = '// Keep in the User directory. Personalize as needed\n' + for i in range(3, 10): + def_lines.pop(3) # Must be 3: 4 becomes 3, then 5 becomes 3... + + with codecs.open(user_file,'w','UTF-8') as user_fp: + user_fp.writelines(def_lines) + + if killall: + msg_preserved = "" + else: + msg_preserved = "Old-style, pre-2014 settings (if any) have been migrated." + sublime.status_message("Settings reset to default.") + sublime.message_dialog("LaTeXTools settings successfully reset to default. " + msg_preserved) + return + diff --git a/latextools/plugin_internal/__init__.py b/latextools/plugin_internal/__init__.py deleted file mode 100644 index 4164665bd..000000000 --- a/latextools/plugin_internal/__init__.py +++ /dev/null @@ -1,93 +0,0 @@ -""" -This is internal definitions used by the latextools_plugin module - -This separate module is required because ST's reload semantics make it -impossible to implement something like this within that module itself. -""" - -import re - -_REGISTRY = None -# list of tuples consisting of a path and a glob to load in the plugin_loaded() -# method to handle the case where `add_plugin_path` is called before this -# module has been fully loaded. -_REGISTERED_PATHS_TO_LOAD = [] - -# list of tuples consisting of names and class objects to load in the -# plugin_loaded() method to handle the case where a plugin is defined before -# the registry has been created -_REGISTERED_CLASSES_TO_LOAD = [] - -# a list of tuples consisting of a module name and a module object used in the -# _latextools_modules_hack context manager to provide an API for adding modules -_WHITELIST_ADDED = [] - - -# LaTeXToolsPlugin - base class for all plugins -class LaTeXToolsPluginMeta(type): - """ - Metaclass for plugins which will automatically register them with the - plugin registry - """ - - def __init__(cls, name, bases, attrs): - try: - super(LaTeXToolsPluginMeta, cls).__init__(name, bases, attrs) - except TypeError: - # occurs on reload - return - - if cls == LaTeXToolsPluginMeta or cls is None: - return - - try: - if not any((True for base in bases if issubclass(base, LaTeXToolsPlugin))): - return - except NameError: - return - - registered_name = _classname_to_internal_name(name) - - _REGISTERED_CLASSES_TO_LOAD.append((registered_name, cls)) - - if _REGISTRY is not None: - _REGISTRY[registered_name] = cls - - -LaTeXToolsPlugin = LaTeXToolsPluginMeta("LaTeXToolsPlugin", (object,), {}) -LaTeXToolsPlugin.__doc__ = """ -Base class for LaTeXTools plugins. Implementation details will depend on where -this plugin is supposed to be loaded. See the documentation for details. -""" - - -def _classname_to_internal_name(s): - """ - Converts a Python class name in to an internal name - - The intention here is to mirror how ST treats *Command objects, i.e., by - converting them from CamelCase to under_scored. Similarly, we will chop - "Plugin" off the end of the plugin, though it isn't necessary for the class - to be treated as a plugin. - - E.g., - SomeClass will become some_class - ReferencesPlugin will become references - BibLaTeXPlugin will become biblatex - """ - if not s: - return s - - def _repl(match): - match = match.group(0) - return match[0] + match[1:].lower() - - s = re.sub(r"(?:Bib)?(?:La)?TeX", _repl, s) - - # pilfered from https://code.activestate.com/recipes/66009/ - s = re.sub(r"(?<=[a-z])[A-Z]|(?", s).lower() - - if s.endswith("_plugin"): - s = s[:-7] - - return s diff --git a/latextools/preview/__init__.py b/latextools/preview/__init__.py new file mode 100644 index 000000000..dbfdff256 --- /dev/null +++ b/latextools/preview/__init__.py @@ -0,0 +1,2 @@ +from .preview_image import * +from .preview_math import * diff --git a/latextools/preview/preview_image.py b/latextools/preview/preview_image.py index 56ec49bf2..0a9efc46b 100644 --- a/latextools/preview/preview_image.py +++ b/latextools/preview/preview_image.py @@ -10,10 +10,10 @@ from ..jumpto_tex_file import find_image from ..jumpto_tex_file import open_image -from ..latextools_utils import cache -from ..latextools_utils.logging import logger -from ..latextools_utils.settings import get_setting -from ..latextools_utils.tex_directives import get_tex_root +from ..utils import cache +from ..utils.logging import logger +from ..utils.settings import get_setting +from ..utils.tex_directives import get_tex_root from .preview_utils import SettingsListener as PreviewSettingsListener from .preview_utils import convert_installed from .preview_utils import ghostscript_installed @@ -22,7 +22,7 @@ from . import preview_threading as pv_threading # export the listeners -exports = ["PreviewImageHoverListener", "PreviewImagePhantomListener"] +__all__ = ["PreviewImageHoverListener", "PreviewImagePhantomListener"] # the path to the temp files (set on loading) temp_path = None @@ -65,6 +65,7 @@ def plugin_unloaded(): v.erase_phantoms(_name) v.settings().clear_on_change(_name) + _lt_settings = sublime.load_settings("LaTeXTools.sublime-settings") _lt_settings.clear_on_change(_name) _lt_settings.clear_on_change("lt_preview_image_main") diff --git a/latextools/preview/preview_math.py b/latextools/preview/preview_math.py index 61e2a8e06..7a90af02f 100644 --- a/latextools/preview/preview_math.py +++ b/latextools/preview/preview_math.py @@ -12,12 +12,12 @@ import sublime import sublime_plugin -from ..latextools_utils import cache -from ..latextools_utils.external_command import execute_command -from ..latextools_utils.logging import logger -from ..latextools_utils.settings import get_setting -from ..latextools_utils.tex_log import parse_tex_log -from ..latextools_utils.utils import cpu_count +from ..utils import cache +from ..utils.external_command import execute_command +from ..utils.logging import logger +from ..utils.settings import get_setting +from ..utils.tex_log import parse_tex_log +from ..utils.utils import cpu_count from .preview_utils import SettingsListener as PreviewSettingsListener from .preview_utils import ghostscript_installed from .preview_utils import get_ghostscript_version @@ -25,7 +25,7 @@ from . import preview_threading as pv_threading # export the listener -exports = ["MathPreviewPhantomListener"] +__all__ = ["MathPreviewPhantomListener"] # increase this number if you change the convert command to mark the # generated images as expired @@ -122,6 +122,7 @@ def plugin_unloaded(): v.erase_phantoms(_name) v.settings().clear_on_change(_name) + _lt_settings = sublime.load_settings("LaTeXTools.sublime-settings") _lt_settings.clear_on_change(_name) _lt_settings.clear_on_change("lt_preview_math_main") diff --git a/latextools/preview/preview_threading.py b/latextools/preview/preview_threading.py index ff2954e30..0c93be754 100644 --- a/latextools/preview/preview_threading.py +++ b/latextools/preview/preview_threading.py @@ -1,8 +1,7 @@ import threading import traceback - -from ..latextools_utils.logging import logger +from ..utils.logging import logger from .preview_utils import try_delete_temp_files _max_threads = 2 diff --git a/latextools/preview/preview_utils.py b/latextools/preview/preview_utils.py index 2ba18056c..3dc67754b 100644 --- a/latextools/preview/preview_utils.py +++ b/latextools/preview/preview_utils.py @@ -8,6 +8,17 @@ from shutil import which +from ..utils import cache +from ..utils.distro_utils import using_miktex +from ..utils.external_command import __sentinel__ +from ..utils.external_command import check_output +from ..utils.external_command import execute_command +from ..utils.external_command import get_texpath +from ..utils.logging import logger +from ..utils.settings import get_setting + +_lt_settings = {} + if sublime.platform() == "windows": import winreg import ctypes @@ -20,18 +31,6 @@ def get_system_root(): return buffer.value -from ..latextools_utils import cache -from ..latextools_utils.distro_utils import using_miktex -from ..latextools_utils.external_command import __sentinel__ -from ..latextools_utils.external_command import check_output -from ..latextools_utils.external_command import execute_command -from ..latextools_utils.external_command import get_texpath -from ..latextools_utils.logging import logger -from ..latextools_utils.settings import get_setting - -_lt_settings = {} - - def _get_convert_command(): if hasattr(_get_convert_command, "result"): return _get_convert_command.result diff --git a/latextools/reveal_folders.py b/latextools/reveal_folders.py index 76ee43859..761786916 100644 --- a/latextools/reveal_folders.py +++ b/latextools/reveal_folders.py @@ -3,11 +3,11 @@ import sublime import sublime_plugin -from .latextools_utils.output_directory import get_aux_directory -from .latextools_utils.output_directory import get_output_directory -from .latextools_utils.logging import logger -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root +from .utils.logging import logger +from .utils.output_directory import get_aux_directory +from .utils.output_directory import get_output_directory +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root __all__ = [ "LatextoolsRevealAuxDirectoryCommand", diff --git a/latextools/search_commands.py b/latextools/search_commands.py index 276ae6c1e..9d5ffb671 100644 --- a/latextools/search_commands.py +++ b/latextools/search_commands.py @@ -1,10 +1,10 @@ import sublime_plugin from .deprecated_command import deprecate -from .latextools_utils import analysis -from .latextools_utils import ana_utils -from .latextools_utils import quickpanel -from .latextools_utils.tex_directives import get_tex_root +from .utils import analysis +from .utils import ana_utils +from .utils import quickpanel +from .utils.tex_directives import get_tex_root __all__ = ["LatextoolsSearchCommandCommand", "LatextoolsSearchCommandInputCommand"] diff --git a/latextools/smart_paste.py b/latextools/smart_paste.py index a574c8070..820b54911 100644 --- a/latextools/smart_paste.py +++ b/latextools/smart_paste.py @@ -9,9 +9,9 @@ from Default.open_context_url import rex as url_regex -from .latextools_utils import analysis -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root +from .utils import analysis +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root __all__ = ["LatextoolsDownloadInsertImageHelperCommand", "LatextoolsSmartPasteCommand"] diff --git a/latextools/system_check.py b/latextools/system_check.py index 016fd945a..1ff270a00 100644 --- a/latextools/system_check.py +++ b/latextools/system_check.py @@ -19,24 +19,24 @@ from .latextools_plugin import add_plugin_path from .latextools_plugin import get_plugin from .latextools_plugin import NoSuchPluginException -from .latextools_utils.activity_indicator import ActivityIndicator -from .latextools_utils.distro_utils import using_miktex -from .latextools_utils.external_command import check_output -from .latextools_utils.logging import logger -from .latextools_utils.output_directory import get_aux_directory -from .latextools_utils.output_directory import get_jobname -from .latextools_utils.output_directory import get_output_directory -from .latextools_utils.settings import get_setting -from .latextools_utils.sublime_utils import get_sublime_exe -from .latextools_utils.tex_directives import get_tex_root -from .latextools_utils.tex_directives import parse_tex_directives - -from .st_preview.preview_utils import convert_installed -from .st_preview.preview_utils import ghostscript_installed -from .st_preview.preview_utils import __get_gs_command as get_gs_command +from .utils.activity_indicator import ActivityIndicator +from .utils.distro_utils import using_miktex +from .utils.external_command import check_output +from .utils.logging import logger +from .utils.output_directory import get_aux_directory +from .utils.output_directory import get_jobname +from .utils.output_directory import get_output_directory +from .utils.settings import get_setting +from .utils.sublime_utils import get_sublime_exe +from .utils.tex_directives import get_tex_root +from .utils.tex_directives import parse_tex_directives + +from .preview.preview_utils import convert_installed +from .preview.preview_utils import ghostscript_installed +from .preview.preview_utils import __get_gs_command as get_gs_command if sublime.platform() == "windows": - from .st_preview.preview_utils import get_system_root + from .preview.preview_utils import get_system_root __all__ = ["LatextoolsSystemCheckCommand", "LatextoolsInsertTextCommand"] diff --git a/latextools/temp_file_cleanup.py b/latextools/temp_file_cleanup.py index 4f8383ff8..658bd7e90 100644 --- a/latextools/temp_file_cleanup.py +++ b/latextools/temp_file_cleanup.py @@ -4,7 +4,7 @@ import shutil import tempfile -from .latextools_utils.logging import logger +from .utils.logging import logger # unfortunately, there is no reliable way to do clean-up on exit in ST # see https://github.com/SublimeTextIssues/Core/issues/10 diff --git a/latextools/tex_count.py b/latextools/tex_count.py index 766a99bc0..44db428ce 100644 --- a/latextools/tex_count.py +++ b/latextools/tex_count.py @@ -4,10 +4,10 @@ import sublime_plugin from .deprecated_command import deprecate -from .latextools_utils.external_command import CalledProcessError -from .latextools_utils.external_command import check_output -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root +from .utils.external_command import CalledProcessError +from .utils.external_command import check_output +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root __all__ = ["LatextoolsTexcountCommand"] diff --git a/latextools/tex_syntax_listener.py b/latextools/tex_syntax_listener.py index 1b3a965d4..9f45b913f 100644 --- a/latextools/tex_syntax_listener.py +++ b/latextools/tex_syntax_listener.py @@ -1,7 +1,7 @@ import sublime_plugin -from .latextools_utils.settings import get_setting -from .latextools_utils.is_tex_file import is_tex_file +from .utils.settings import get_setting +from .utils.is_tex_file import is_tex_file __all__ = ["TeXSyntaxListener"] diff --git a/latextools/toc_quickpanel.py b/latextools/toc_quickpanel.py index 62d91a028..937d96b9d 100644 --- a/latextools/toc_quickpanel.py +++ b/latextools/toc_quickpanel.py @@ -1,10 +1,10 @@ import sublime_plugin from .deprecated_command import deprecate -from .latextools_utils import analysis -from .latextools_utils import quickpanel -from .latextools_utils.settings import get_setting -from .latextools_utils.tex_directives import get_tex_root +from .utils import analysis +from .utils import quickpanel +from .utils.settings import get_setting +from .utils.tex_directives import get_tex_root __all__ = ["LatextoolsTocQuickpanelCommand", "LatextoolsTocQuickpanelContext"] diff --git a/latextools/toggle_settings.py b/latextools/toggle_settings.py index e45ef675e..6ea0a554a 100644 --- a/latextools/toggle_settings.py +++ b/latextools/toggle_settings.py @@ -1,8 +1,8 @@ import sublime import sublime_plugin -from .latextools_utils.logging import logger -from .latextools_utils.settings import get_setting +from .utils.logging import logger +from .utils.settings import get_setting __all__ = ["LatextoolsToggleKeysCommand"] diff --git a/latextools/utils/analysis.py b/latextools/utils/analysis.py index 535cf400e..e5cabbb3b 100644 --- a/latextools/utils/analysis.py +++ b/latextools/utils/analysis.py @@ -7,13 +7,13 @@ import sublime +from ..libs.frozendict import frozendict + from . import utils -from ..external.frozendict import frozendict from .cache import LocalCache from .logging import logger from .tex_directives import get_tex_root - # attributes of an entry (for documentation) """ Attributes of an entry: diff --git a/latextools/utils/bibcache.py b/latextools/utils/bibcache.py index 982739a5f..dec69c355 100644 --- a/latextools/utils/bibcache.py +++ b/latextools/utils/bibcache.py @@ -7,7 +7,7 @@ from .logging import logger from .settings import get_setting -from ..external.frozendict import frozendict +from ..libs.frozendict import frozendict _VERSION = 2 diff --git a/latextools/utils/cache.py b/latextools/utils/cache.py index 8d8e7494f..3bbca54e8 100644 --- a/latextools/utils/cache.py +++ b/latextools/utils/cache.py @@ -11,12 +11,11 @@ import sublime -from ..external.frozendict import frozendict +from ..libs.frozendict import frozendict from .logging import logger from .settings import get_setting from .utils import ThreadPool - # the folder, if the local cache is not hidden, i.e. folder in the same # folder as the tex root # folder to store all hidden local caches in the cache path diff --git a/latextools/utils/distro_utils.py b/latextools/utils/distro_utils.py index 331400b61..69dfa9cb1 100644 --- a/latextools/utils/distro_utils.py +++ b/latextools/utils/distro_utils.py @@ -2,7 +2,6 @@ from .settings import get_setting - def using_miktex(): platform_settings = get_setting(sublime.platform(), {}) distro = platform_settings.get("distro", "") diff --git a/latextools/utils/external_command.py b/latextools/utils/external_command.py index d3c4a955a..fffe29dfc 100644 --- a/latextools/utils/external_command.py +++ b/latextools/utils/external_command.py @@ -55,7 +55,6 @@ from .logging import logger from .settings import get_setting - def expand_vars(texpath): return os.path.expandvars(texpath) diff --git a/latextools/utils/input_quickpanel.py b/latextools/utils/input_quickpanel.py index fe127ec4b..fedd44ad1 100644 --- a/latextools/utils/input_quickpanel.py +++ b/latextools/utils/input_quickpanel.py @@ -26,7 +26,7 @@ import sublime import sublime_plugin -exports = ["InputQuickpanelListener", "LatextoolsConfirmQuickpanelCommand"] +__all__ = ["InputQuickpanelListener", "LatextoolsConfirmQuickpanelCommand"] _DO_NOTHING = 0 _SEARCH_QUICKPANEL = 1 diff --git a/latextools/utils/internal_types.py b/latextools/utils/internal_types.py index c41628d70..451746911 100644 --- a/latextools/utils/internal_types.py +++ b/latextools/utils/internal_types.py @@ -1,4 +1,4 @@ -from LaTeXTools.latextools_plugin import LaTeXToolsPlugin +from ..latextools_plugin import LaTeXToolsPlugin class FillAllHelper(LaTeXToolsPlugin): diff --git a/latextools/utils/logging.py b/latextools/utils/logging.py index 6205fc348..6c6482223 100644 --- a/latextools/utils/logging.py +++ b/latextools/utils/logging.py @@ -27,10 +27,10 @@ def _on_settings_changed(): logger.setLevel(new_log_level) -def init(): +def init_logger(): _settings().add_on_change(__name__, _on_settings_changed) _on_settings_changed() # trigger on inital settings load, too -def shutdown(): +def shutdown_logger(): _settings().clear_on_change(__name__) diff --git a/latextools/utils/output_directory.py b/latextools/utils/output_directory.py index c280eff2d..8b4dd251d 100644 --- a/latextools/utils/output_directory.py +++ b/latextools/utils/output_directory.py @@ -12,14 +12,6 @@ from .tex_directives import parse_tex_directives -__all__ = [ - "get_aux_directory", - "get_output_directory", - "get_jobname", - "UnsavedFileException", -] - - # raised whenever the root cannot be determined, which indicates an unsaved # file class UnsavedFileException(Exception): diff --git a/latextools/utils/settings.py b/latextools/utils/settings.py index 08313a5ff..3a9d96d9e 100644 --- a/latextools/utils/settings.py +++ b/latextools/utils/settings.py @@ -1,9 +1,6 @@ import sublime -__all__ = ["get_setting"] - - def get_setting(setting, default=None, view=None): advanced_settings = sublime.load_settings("LaTeXTools (Advanced).sublime-settings") global_settings = sublime.load_settings("LaTeXTools.sublime-settings") diff --git a/latextools/utils/tex_directives.py b/latextools/utils/tex_directives.py index 8fedba44a..3a177606f 100644 --- a/latextools/utils/tex_directives.py +++ b/latextools/utils/tex_directives.py @@ -10,7 +10,7 @@ from .sublime_utils import get_project_file_name -TEX_DIRECTIVE = re.compile(r"%+\s*!(?:T|t)(?:E|e)(?:X|x)\s+([\w-]+)\s*=\s*" + r"(.*?)\s*$") +TEX_DIRECTIVE = re.compile(r"%+\s*![Tt][Ee][Xx]\s+([\w-]+)\s*=\s*(.*?)\s*$") # this is obviously imperfect, but is intended as a heuristic. we # can tolerate false negatives, but not false positives that match, e.g., diff --git a/latextools/utils/tex_log.py b/latextools/utils/tex_log.py index 709e843fc..098484ce5 100644 --- a/latextools/utils/tex_log.py +++ b/latextools/utils/tex_log.py @@ -3,7 +3,6 @@ import sys import os.path - print_debug = False interactive = False extra_file_ext = [] diff --git a/plugin.py b/plugin.py new file mode 100644 index 000000000..367dfc908 --- /dev/null +++ b/plugin.py @@ -0,0 +1,174 @@ +import sublime + +if int(sublime.version()) < 3143: + print(__package__ + " requires ST 3143+") +else: + import sys + + # clear modules cache if package is reloaded (after update?) + prefix = __package__ + "." # don't clear the base package + for module_name in [ + module_name + for module_name in sys.modules + if module_name.startswith(prefix) and module_name != __name__ + ]: + del sys.modules[module_name] + + from .latextools.utils.logging import logger, init_logger, shutdown_logger + + from .latextools.auto_label import ( + LatextoolsAutoInsertLabelCommand, + LatextoolsAutoInserLabelListener, + ) + from .latextools.biblatex_crossref_completions import ( + BiblatexCrossrefCompletions + ) + from .latextools.biblatex_field_name_completions import ( + FieldNameCompletions + ) + from .latextools.biblatex_name_completions import ( + BiblatexNameCompletions + ) + from .latextools.biblatex_snippet_completions import ( + SnippetCompletions + ) + from .latextools.biblatex_syntax_listener import ( + BibLaTeXSyntaxListener + ) + from .latextools.change_environment import ( + LatextoolsChangeEnvironmentCommand, + LatextoolsToggleEnvironmentStarCommand, + ) + from .latextools.context_provider import ( + LatextoolsContextListener + ) + from .latextools.delete_temp_files import ( + LatextoolsClearCacheCommand, + LatextoolsClearLocalCacheCommand, + LatextoolsClearBibliographyCacheCommand, + LatextoolsDeleteTempFilesCommand, + ) + from .latextools.deprecated_command import ( + LatextoolsFindDeprecatedCommandsCommand + ) + from .latextools.detect_spellcheck import ( + LatextoolsAutoDetectSpellcheckListener, + LatextoolsDetectSpellcheckCommand + ) + from .latextools.jumpto_anywhere import ( + LatextoolsJumptoAnywhereCommand, + LatextoolsJumptoAnywhereByMouseCommand + ) + from .latextools.jumpto_pdf import ( + LatextoolsJumptoPdfCommand, + LatextoolsViewPdfCommand, + ) + from .latextools.jumpto_tex_file import ( + LatextoolsJumptoFileCommand + ) + from .latextools.latex_command import ( + LatextoolsLatexCmdCommand + ) + from .latextools.latex_cwl_completions import ( + LatexCwlCompletion + ) + from .latextools.latex_directive_completions import ( + LatexDirectiveCompletion + ) + from .latextools.latex_doc_viewer import ( + LatextoolsPkgDocCommand, + LatextoolsViewDocCommand + ) + from .latextools.latex_env import ( + LatextoolsLatexEnvCommand + ) + from .latextools.latex_env_closer import ( + LatextoolsLatexEnvCloserCommand + ) + from .latextools.latex_fill_all import ( + LatexFillAllEventListener, + LatextoolsFillAllCommand, + LatexToolsFillAllCompleteBracket, + LatexToolsReplaceWord + ) + from .latextools.latex_installed_packages import ( + LatextoolsGenPkgCacheCommand + ) + from .latextools.latextools_cache_listener import ( + LatextoolsCacheUpdateListener, + LatextoolsAnalysisUpdateCommand, + LatextoolsBibcacheUpdateCommand, + ) + from .latextools.make_pdf import ( + LatextoolsMakePdfCommand, + LatextoolsDoOutputEditCommand, + LatextoolsDoFinishEditCommand, + LatextoolsExecEventListener, + ) + from .latextools.migrate import ( + LatextoolsMigrateCommand + ) + from .latextools.preview.preview_image import ( + PreviewImageHoverListener, + PreviewImagePhantomListener + ) + from .latextools.preview.preview_math import ( + MathPreviewPhantomListener + ) + from .latextools.reveal_folders import ( + LatextoolsRevealAuxDirectoryCommand, + LatextoolsRevealOutputDirectoryCommand, + LatextoolsRevealTexRootDirectoryCommand + ) + from .latextools.search_commands import ( + LatextoolsSearchCommandCommand, + LatextoolsSearchCommandInputCommand + ) + from .latextools.smart_paste import ( + LatextoolsDownloadInsertImageHelperCommand, + LatextoolsSmartPasteCommand + ) + from .latextools.system_check import ( + LatextoolsSystemCheckCommand, + LatextoolsInsertTextCommand + ) + from .latextools.tex_count import ( + LatextoolsTexcountCommand + ) + from .latextools.tex_syntax_listener import ( + TeXSyntaxListener + ) + from .latextools.toc_quickpanel import ( + LatextoolsTocQuickpanelCommand, + LatextoolsTocQuickpanelContext + ) + from .latextools.toggle_settings import ( + LatextoolsToggleKeysCommand + ) + from .latextools.utils.input_quickpanel import ( + InputQuickpanelListener, + LatextoolsConfirmQuickpanelCommand + ) + + + def _filter_func(name): + return name.startswith(prefix) and name not in (__name__, "latextools") + + + def plugin_loaded(): + init_logger() + for name in sorted(filter(_filter_func, sys.modules)): + module = sys.modules[name] + if hasattr(module, "plugin_loaded"): + logger.debug("calling %s.plugin_loaded()", name) + module.plugin_loaded() + + + def plugin_unloaded(): + for name in sorted(filter(_filter_func, sys.modules)): + module = sys.modules[name] + if hasattr(module, "plugin_unloaded"): + logger.debug("calling %s.plugin_unloaded()", name) + module.plugin_unloaded() + + shutdown_logger() diff --git a/plugins/bibliography/new_bibliography.py b/plugins/bibliography/new_bibliography.py index d0facd0a3..53a75ccd6 100644 --- a/plugins/bibliography/new_bibliography.py +++ b/plugins/bibliography/new_bibliography.py @@ -3,14 +3,16 @@ import sublime import traceback -from external import latex_chars -from external.bibtex import Parser -from external.bibtex.names import Name -from external.bibtex.tex import tokenize_list - -from latextools_plugin import LaTeXToolsPlugin -from latextools_utils import bibcache -from latextools_utils.logging import logger +from LaTeXTools.latextools.latextools_plugin import LaTeXToolsPlugin + +from LaTeXTools.latextools.libs.bibtex import Parser +from LaTeXTools.latextools.libs.bibtex.names import Name +from LaTeXTools.latextools.libs.bibtex.tex import tokenize_list + +from LaTeXTools.latextools.libs import latex_chars + +from LaTeXTools.latextools.utils import bibcache +from LaTeXTools.latextools.utils.logging import logger # LaTeX -> Unicode decoder latex_chars.register() diff --git a/plugins/bibliography/traditional_bibliography.py b/plugins/bibliography/traditional_bibliography.py index 78ee20bf5..d9ff14ae6 100644 --- a/plugins/bibliography/traditional_bibliography.py +++ b/plugins/bibliography/traditional_bibliography.py @@ -3,11 +3,11 @@ import sublime import traceback -from external import latex_chars +from LaTeXTools.latextools.latextools_plugin import LaTeXToolsPlugin -from latextools_plugin import LaTeXToolsPlugin -from latextools_utils import bibcache -from latextools_utils.logging import logger +from LaTeXTools.latextools.libs import latex_chars +from LaTeXTools.latextools.utils import bibcache +from LaTeXTools.latextools.utils.logging import logger kp = re.compile(r"@[^\{]+\{\s*(.+)\s*,") # new and improved regex diff --git a/plugins/builder/basic_builder.py b/plugins/builder/basic_builder.py index ac63dd90f..82c759643 100644 --- a/plugins/builder/basic_builder.py +++ b/plugins/builder/basic_builder.py @@ -4,9 +4,9 @@ import subprocess import sys -from latextools_utils.external_command import external_command -from latextools_utils.external_command import get_texpath -from latextools_utils.logging import logger +from LaTeXTools.latextools.utils.external_command import external_command +from LaTeXTools.latextools.utils.external_command import get_texpath +from LaTeXTools.latextools.utils.logging import logger from pdf_builder import PdfBuilder diff --git a/plugins/builder/pdf_builder.py b/plugins/builder/pdf_builder.py index 3d1fcaebd..65224d0ef 100644 --- a/plugins/builder/pdf_builder.py +++ b/plugins/builder/pdf_builder.py @@ -2,9 +2,8 @@ import sublime import sys -from latextools_plugin import add_whitelist_module -from latextools_plugin import LaTeXToolsPlugin -from latextools_utils.logging import logger +from LaTeXTools.latextools.latextools_plugin import LaTeXToolsPlugin +from LaTeXTools.latextools.utils.logging import logger class PdfBuilder(LaTeXToolsPlugin): @@ -18,8 +17,8 @@ class PdfBuilder(LaTeXToolsPlugin): tex_root: the full path to the tex root file output: object in main thread responsible for writing to the output panel - builder_settings : a dictionary containing the "builder_settings" from LaTeXTools.sublime-settings - platform_settings : a dictionary containing the "platform_settings" from LaTeXTools.sublime-settings + builder_settings : a dictionary containing the "builder_settings" from LaTeXTools.latextools.sublime-settings + platform_settings : a dictionary containing the "platform_settings" from LaTeXTools.latextools.sublime-settings E.g.: self.path = prefs["path"] @@ -94,7 +93,3 @@ def commands(self): # pass the tex root again. Need to think about this def cleantemps(self): return NotImplementedError() - - -# ensure pdfBuilder is available to any custom builders -add_whitelist_module("pdf_builder", sys.modules[PdfBuilder.__module__]) diff --git a/plugins/builder/script_builder.py b/plugins/builder/script_builder.py index 9fd20be39..d46457f62 100644 --- a/plugins/builder/script_builder.py +++ b/plugins/builder/script_builder.py @@ -6,9 +6,9 @@ from shlex import quote from string import Template -from latextools_utils.external_command import external_command -from latextools_utils.external_command import get_texpath -from latextools_utils.external_command import update_env +from LaTeXTools.latextools.utils.external_command import external_command +from LaTeXTools.latextools.utils.external_command import get_texpath +from LaTeXTools.latextools.utils.external_command import update_env from pdf_builder import PdfBuilder diff --git a/plugins/viewer/base_viewer.py b/plugins/viewer/base_viewer.py index 71e3e674f..e898bbf7a 100644 --- a/plugins/viewer/base_viewer.py +++ b/plugins/viewer/base_viewer.py @@ -1,8 +1,7 @@ import sys -from latextools_plugin import add_whitelist_module -from latextools_plugin import LaTeXToolsPlugin -from latextools_utils import sublime_utils as st_utils +from LaTeXTools.latextools.latextools_plugin import LaTeXToolsPlugin +from LaTeXTools.latextools.utils import sublime_utils as st_utils # most methods take a kwargs variable, which currently only consists of the # `keep_focus` setting @@ -54,6 +53,3 @@ def supports_platform(self, platform): def focus_st(self): st_utils.focus_st() - - -add_whitelist_module("base_viewer", sys.modules[BaseViewer.__module__]) diff --git a/plugins/viewer/command_viewer.py b/plugins/viewer/command_viewer.py index 924ff9e61..023e0a73c 100644 --- a/plugins/viewer/command_viewer.py +++ b/plugins/viewer/command_viewer.py @@ -4,9 +4,9 @@ import sublime import string -from latextools_utils.external_command import external_command -from latextools_utils.settings import get_setting -from latextools_utils.sublime_utils import get_sublime_exe +from LaTeXTools.latextools.utils.external_command import external_command +from LaTeXTools.latextools.utils.settings import get_setting +from LaTeXTools.latextools.utils.sublime_utils import get_sublime_exe from base_viewer import BaseViewer diff --git a/plugins/viewer/evince_viewer.py b/plugins/viewer/evince_viewer.py index cbe46c295..09d6c2df3 100644 --- a/plugins/viewer/evince_viewer.py +++ b/plugins/viewer/evince_viewer.py @@ -2,11 +2,11 @@ import sublime import time -from latextools_utils.external_command import check_call -from latextools_utils.external_command import check_output -from latextools_utils.external_command import external_command -from latextools_utils.settings import get_setting -from latextools_utils.sublime_utils import get_sublime_exe +from LaTeXTools.latextools.utils.external_command import check_call +from LaTeXTools.latextools.utils.external_command import check_output +from LaTeXTools.latextools.utils.external_command import external_command +from LaTeXTools.latextools.utils.settings import get_setting +from LaTeXTools.latextools.utils.sublime_utils import get_sublime_exe from base_viewer import BaseViewer diff --git a/plugins/viewer/okular_viewer.py b/plugins/viewer/okular_viewer.py index d56af313c..56e0ce2e9 100644 --- a/plugins/viewer/okular_viewer.py +++ b/plugins/viewer/okular_viewer.py @@ -1,8 +1,8 @@ import time -from latextools_utils.external_command import check_output -from latextools_utils.external_command import external_command -from latextools_utils.settings import get_setting +from LaTeXTools.latextools.utils.external_command import check_output +from LaTeXTools.latextools.utils.external_command import external_command +from LaTeXTools.latextools.utils.settings import get_setting from base_viewer import BaseViewer diff --git a/plugins/viewer/preview_viewer.py b/plugins/viewer/preview_viewer.py index 34167389a..08926d837 100644 --- a/plugins/viewer/preview_viewer.py +++ b/plugins/viewer/preview_viewer.py @@ -1,4 +1,4 @@ -from latextools_utils.external_command import external_command +from LaTeXTools.latextools.utils.external_command import external_command from base_viewer import BaseViewer diff --git a/plugins/viewer/skim_viewer.py b/plugins/viewer/skim_viewer.py index db7bd88a7..e4c0e744e 100644 --- a/plugins/viewer/skim_viewer.py +++ b/plugins/viewer/skim_viewer.py @@ -1,7 +1,7 @@ import os -from latextools_utils.external_command import check_output -from latextools_utils.external_command import external_command +from LaTeXTools.latextools.utils.external_command import check_output +from LaTeXTools.latextools.utils.external_command import external_command from base_viewer import BaseViewer diff --git a/plugins/viewer/sumatra_viewer.py b/plugins/viewer/sumatra_viewer.py index 2def89fd8..690dfcf65 100644 --- a/plugins/viewer/sumatra_viewer.py +++ b/plugins/viewer/sumatra_viewer.py @@ -9,9 +9,9 @@ # not on Windows pass -from latextools_utils.external_command import external_command -from latextools_utils.logging import logger -from latextools_utils.settings import get_setting +from LaTeXTools.latextools.utils.external_command import external_command +from LaTeXTools.latextools.utils.logging import logger +from LaTeXTools.latextools.utils.settings import get_setting from base_viewer import BaseViewer diff --git a/plugins/viewer/zathura_viewer.py b/plugins/viewer/zathura_viewer.py index 9591fcab5..8b8209fbe 100644 --- a/plugins/viewer/zathura_viewer.py +++ b/plugins/viewer/zathura_viewer.py @@ -1,9 +1,9 @@ from shutil import which -from latextools_utils.external_command import check_output -from latextools_utils.external_command import external_command -from latextools_utils.settings import get_setting -from latextools_utils.sublime_utils import get_sublime_exe +from LaTeXTools.latextools.utils.external_command import check_output +from LaTeXTools.latextools.utils.external_command import external_command +from LaTeXTools.latextools.utils.settings import get_setting +from LaTeXTools.latextools.utils.sublime_utils import get_sublime_exe from base_viewer import BaseViewer diff --git a/tests/test_context.py b/tests/test_context.py index 184cc916a..251c83cce 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -2,7 +2,7 @@ import sublime -from LaTeXTools.context_provider import LatextoolsContextListener +from LaTeXTools.latextools.context_provider import LatextoolsContextListener ST_VER = int(sublime.version()) diff --git a/tests/test_selectors.py b/tests/test_selectors.py index f72b027cd..c3410c03e 100644 --- a/tests/test_selectors.py +++ b/tests/test_selectors.py @@ -1,6 +1,6 @@ from unittest import TestCase -from LaTeXTools.latextools_utils.selectors import ( +from LaTeXTools.latextools.utils.selectors import ( AstNode as Node, AstLeaf as Leaf, build_ast )