Skip to content

Commit

Permalink
Merge pull request #1931 from SublimeLinter/prep38
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste committed Apr 15, 2024
2 parents 93ace4d + d7522f4 commit b83d0c7
Show file tree
Hide file tree
Showing 21 changed files with 376 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Expand Up @@ -6,11 +6,11 @@
# archive files. See http://git-scm.com/docs/gitattributes for details.

/docs/ export-ignore
/scripts/ export-ignore
/tests/ export-ignore
/.codecov.yml export-ignore
/.coveragerc export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.python-version export-ignore
/.travis.yml export-ignore
/setup.cfg export-ignore
2 changes: 1 addition & 1 deletion .github/workflows/flake8.yml
Expand Up @@ -24,6 +24,6 @@ jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pip install "flake8<6.0.0"
- uses: TrueBrain/actions-flake8@v2
4 changes: 2 additions & 2 deletions .github/workflows/mypy.yml
Expand Up @@ -14,9 +14,9 @@ jobs:
platform: ['linux', 'darwin', 'win32']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install mypy
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/sphinx.yml
Expand Up @@ -14,11 +14,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: 3.7
python-version: 3.8
- name: Update pip and install sphinx
run: |
python -m pip install --upgrade pip
Expand All @@ -31,11 +31,11 @@ jobs:
check-links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: 3.7
python-version: 3.8
- name: Update pip and install sphinx
run: |
python -m pip install --upgrade pip
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Expand Up @@ -15,9 +15,9 @@ jobs:
strategy:
fail-fast: false
matrix:
st-version: [3, 4]
st-version: [4]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: SublimeText/UnitTesting/actions/setup@v1
with:
sublime-text-version: ${{ matrix.st-version }}
Expand All @@ -26,12 +26,12 @@ jobs:
run-syntax-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: SublimeText/UnitTesting/actions/setup@v1
- uses: SublimeText/UnitTesting/actions/run-syntax-tests@v1

check-upgrade-messages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: kaste/upgrade-messages-test-action@v1
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,3 +9,4 @@ _build/
.mypy_cache/
.ropeproject/
docs-out
scripts/sublime_linter.sublime-package
1 change: 1 addition & 0 deletions .python-version
@@ -0,0 +1 @@
3.8
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -11,6 +11,13 @@ No linters included: get them via [Package Control](https://packagecontrol.io/se

## Installation

Note: *** We're in a transition phase to the newer ST4 plugin host. Unless we have
more experience for the process, it _may_ be necessary to restart Sublime Text
after installing or upgrading helper packages. Just check if everything works
or if the console shows permanent errors. On my machine, no restarts were
necessary. ***


Probably don't get fancy and just install SublimeLinter via [Package Control](https://packagecontrol.io/search/SublimeLinter).
Refer https://www.sublimelinter.com/en/latest/installation.html for further information,
but, spoiler!,
Expand Down
141 changes: 141 additions & 0 deletions __allo__.py
@@ -0,0 +1,141 @@
from pathlib import Path
import zipfile

import sublime

from typing import Set


pp = Path(sublime.packages_path())
ipp = Path(sublime.installed_packages_path())


def ip__has_python_version_file(package: Path) -> bool:
with zipfile.ZipFile(package) as zfile:
try:
zfile.getinfo(".python-version")
except KeyError:
return False
else:
return True


def p__has_python_version_file(package: str) -> bool:
fpath = pp / package
return (fpath / ".python-version").exists()


def p__is_lift(package: str) -> bool:
fpath = pp / package
return (
(fpath / ".python-version").exists()
and len(list(fpath.glob("*"))) == 1
)


def create_python_version_file(package: str) -> None:
fpath = pp / package
fpath.mkdir(exist_ok=True)
(fpath / ".python-version").write_text("3.8\n")


def remove_python_version_file(package: str) -> None:
fpath = pp / package
(fpath / ".python-version").unlink(missing_ok=True)
if not list(fpath.glob("*")):
fpath.rmdir()


def check_all_plugins() -> None:
removals = [
(remove_python_version_file, path.stem)
for path in ipp.glob("SublimeLinter*")
if (
ip__has_python_version_file(path)
and p__is_lift(path.stem)
)
] + [
(remove_python_version_file, path.name)
for path in pp.glob("SublimeLinter*")
if (
p__is_lift(path.name)
and not (ipp / f"{path.name}.sublime-package").exists()
)
]
additions = sorted(
[
(create_python_version_file, path.stem)
for path in ipp.glob("SublimeLinter*")
if (
not ip__has_python_version_file(path)
and not p__has_python_version_file(path.stem)
)
] + [
(create_python_version_file, path.name)
for path in pp.glob("SublimeLinter*")
if not p__has_python_version_file(path.name)
],
key=lambda x: x[1]
)

tasks = removals + additions
for fn, package in tasks:
print(f'SublimeLinter-lift: {fn.__name__}("{package}"), ', end="")
try:
fn(package)
except Exception as e:
print(e)
else:
print("ok.")

if additions:
print("SublimeLinter-lift: If in doubt, reload. 😐")


check_all_plugins() # <== side-effect on module load! 🕺


PACKAGE_CONTROL_PREFERENCES_FILE = 'Package Control.sublime-settings'
OBSERVER_KEY = '302e8c92-64a9-4483-b7a7-3a04d2ee641d'
INSTALLED_PLUGINS = set()


def package_control_settings() -> sublime.Settings:
return sublime.load_settings(PACKAGE_CONTROL_PREFERENCES_FILE)


def plugin_loaded() -> None:
global INSTALLED_PLUGINS
package_control_settings().add_on_change(OBSERVER_KEY, on_change)
INSTALLED_PLUGINS = installed_sl_plugins()


def plugin_unloaded() -> None:
package_control_settings().clear_on_change(OBSERVER_KEY)


def on_change() -> None:
global INSTALLED_PLUGINS
previous_state, next_state = INSTALLED_PLUGINS, installed_sl_plugins()
additions = next_state - previous_state
deletions = previous_state - next_state

# We're pessimistic here and assume every plugin needs the lift
# because we want to be early and before PC has actually installed
# the package.
# We call `check_all_plugins` unconditionally which will clean up
# for us if this step was in fact unnecessary.
for package in additions:
create_python_version_file(package)

if additions or deletions:
sublime.set_timeout(check_all_plugins, 5000)

INSTALLED_PLUGINS = next_state


def installed_sl_plugins() -> Set[str]:
return set(
p for p in package_control_settings().get('installed_packages', []) # type: ignore[union-attr] # stub error
if p.startswith("SublimeLinter-")
)
4 changes: 2 additions & 2 deletions goto_commands.py
Expand Up @@ -77,7 +77,7 @@ def before_current_pos(pos):
move_to(view, point)


class _sublime_linter_move_cursor(sublime_plugin.TextCommand):
class sublime_linter_move_cursor(sublime_plugin.TextCommand):
# We ensure `on_selection_modified` handlers run by using a `TextCommand`.
# See: https://github.com/SublimeLinter/SublimeLinter/pull/867
# and https://github.com/SublimeTextIssues/Core/issues/485#issuecomment-337480388
Expand All @@ -90,7 +90,7 @@ def run(self, edit, point):
def move_to(view, point):
# type: (sublime.View, int) -> None
add_selection_to_jump_history(view)
view.run_command('_sublime_linter_move_cursor', {'point': point})
view.run_command('sublime_linter_move_cursor', {'point': point})


if int(sublime.version()) < 4000:
Expand Down
3 changes: 2 additions & 1 deletion messages.json
Expand Up @@ -4,5 +4,6 @@
"4.17.0": "messages/4.17.0.txt",
"4.19.0": "messages/4.19.0.txt",
"4.20.0": "messages/4.20.0.txt",
"4.22.0": "messages/4.22.0.txt"
"4.22.0": "messages/4.22.0.txt",
"4.24.0": "messages/4.24.0.txt"
}
23 changes: 23 additions & 0 deletions messages/4.24.0.txt
@@ -0,0 +1,23 @@
SublimeLinter 4.24.0

That's it: we say Goodbye to Sublime Text 3 and run on the Python 3.8 host.
You may want to restart.

How is this implemented? On Sublime's startup and when you install/remove
packages using Package Control we automatically lift all SL adapters/addons
to the 3.8 host. This is necessary as it is impossible to get cooperation
in a single step and limited timeline for 100+ repos. Over time these helper
packages may eventually update and Sublime Linter will remove the "lifts".

During that period it may or may not be necessary to restart Sublime Text
after upgrades of such plugins. This is currently unknown as I (and we) don't
have much experience in these processes. This is a novel approach after all.
That being said, on my machine installing and uninstalling is seamless and
just works™️.


Sincerely,
💕


Yes, I do enjoy coffee: https://paypal.me/herrkaste
6 changes: 6 additions & 0 deletions messages/install.txt
Expand Up @@ -11,6 +11,12 @@ Welcome to SublimeLinter, a linter framework for Sublime Text.
Linters are not included, they must be installed separately.
Get them from Package Control: https://packagecontrol.io/search/SublimeLinter

*** We're in a transition phase to the newer ST4 plugin host. Unless we have
more experience for the process, it _may_ be necessary to restart Sublime Text
after installing or upgrading helper packages. Just check if everything works
or if the console shows permanent errors. On my machine, no restarts were
necessary. ***


For complete documentation on how to use and configure SublimeLinter,
please see: http://www.sublimelinter.com
Expand Down
8 changes: 4 additions & 4 deletions panel_view.py
Expand Up @@ -693,10 +693,10 @@ def update_panel_selection(active_view, cursor, draw_info=None, **kwargs):
def update_panel_content(panel, text):
if not text:
text = NO_RESULTS_MESSAGE
panel.run_command('_sublime_linter_replace_panel_content', {'text': text})
panel.run_command('sublime_linter_replace_panel_content', {'text': text})


class _sublime_linter_replace_panel_content(sublime_plugin.TextCommand):
class sublime_linter_replace_panel_content(sublime_plugin.TextCommand):
def run(self, edit, text):
view = self.view
_, y = view.viewport_position()
Expand Down Expand Up @@ -777,10 +777,10 @@ def scroll_into_view(panel, wanted_lines, errors):
def scroll_to_line(view, line, animate):
"""Scroll y-axis so that `line` appears at the top of the viewport."""
x, y = view.text_to_layout(view.text_point(line, 0))
view.run_command('_sublime_linter_scroll_y', {'y': y, 'animate': animate})
view.run_command('sublime_linter_scroll_y', {'y': y, 'animate': animate})


class _sublime_linter_scroll_y(sublime_plugin.TextCommand):
class sublime_linter_scroll_y(sublime_plugin.TextCommand):
def run(self, edit, y, animate):
x, _ = self.view.viewport_position()
self.view.set_viewport_position((x, y), animate)
Expand Down

0 comments on commit b83d0c7

Please sign in to comment.