codis 1.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codis-1.1.1.dist-info/METADATA +194 -0
- codis-1.1.1.dist-info/RECORD +329 -0
- codis-1.1.1.dist-info/WHEEL +5 -0
- codis-1.1.1.dist-info/entry_points.txt +5 -0
- codis-1.1.1.dist-info/licenses/LICENSE +21 -0
- codis-1.1.1.dist-info/top_level.txt +2 -0
- run.py +190 -0
- src/__init__.py +1 -0
- src/__main__.py +81 -0
- src/_app_build.py +1507 -0
- src/_app_editor.py +1274 -0
- src/_app_kui.py +825 -0
- src/_app_lsp.py +625 -0
- src/_app_recovery.py +189 -0
- src/_app_settings.py +1385 -0
- src/_app_tools.py +2471 -0
- src/_app_webpreview.py +126 -0
- src/_font_safety.py +127 -0
- src/_shells.py +172 -0
- src/app.py +1488 -0
- src/chat/__init__.py +1 -0
- src/chat/adapters/__init__.py +33 -0
- src/chat/adapters/base.py +209 -0
- src/chat/adapters/discord.py +190 -0
- src/chat/adapters/http.py +78 -0
- src/chat/adapters/irc.py +360 -0
- src/chat/adapters/matrix.py +219 -0
- src/chat/adapters/mattermost.py +178 -0
- src/chat/adapters/mqtt.py +165 -0
- src/chat/adapters/slack.py +204 -0
- src/chat/adapters/telegram.py +117 -0
- src/chat/adapters/ws.py +154 -0
- src/chat/adapters/xmpp.py +337 -0
- src/chat/history.py +76 -0
- src/chat/models.py +207 -0
- src/chat/probe.py +79 -0
- src/chat/session.py +446 -0
- src/chat/util.py +125 -0
- src/collab/__init__.py +1 -0
- src/collab/net.py +411 -0
- src/collab/ot.py +311 -0
- src/collab/session.py +141 -0
- src/collab/tk_adapter.py +134 -0
- src/config.py +335 -0
- src/constants.py +2552 -0
- src/dep_catalog.py +446 -0
- src/diff/__init__.py +1 -0
- src/diff/engine.py +247 -0
- src/dpi.py +30 -0
- src/editor/__init__.py +1 -0
- src/editor/_pane_lsp.py +2937 -0
- src/editor/_pane_utils.py +171 -0
- src/editor/autocomplete.py +607 -0
- src/editor/code_folding.py +836 -0
- src/editor/color_preview.py +382 -0
- src/editor/complexity_lens.py +281 -0
- src/editor/diff_pane.py +623 -0
- src/editor/file_watcher.py +144 -0
- src/editor/focus_block.py +236 -0
- src/editor/heatmap.py +141 -0
- src/editor/inlay_hints.py +366 -0
- src/editor/inline_blame.py +429 -0
- src/editor/kdocs.py +3376 -0
- src/editor/large_file.py +488 -0
- src/editor/ligatures.py +180 -0
- src/editor/line_numbers.py +598 -0
- src/editor/minimap.py +691 -0
- src/editor/multi_cursor.py +269 -0
- src/editor/pane.py +2082 -0
- src/editor/rhythm.py +206 -0
- src/editor/save_hooks.py +43 -0
- src/editor/smart_selection.py +425 -0
- src/editor/smart_tips.py +719 -0
- src/editor/snippets.py +411 -0
- src/editor/sticky_note_gutter.py +410 -0
- src/editor/sticky_scroll.py +385 -0
- src/editor/suggest.py +464 -0
- src/editor/text_transforms.py +310 -0
- src/editor/vim_mode.py +1074 -0
- src/events/__init__.py +84 -0
- src/events/bus.py +427 -0
- src/events/correlator.py +244 -0
- src/events/kinds.py +125 -0
- src/events/pipeline.py +264 -0
- src/events/stream.py +416 -0
- src/events/window.py +204 -0
- src/extcompat/__init__.py +19 -0
- src/extcompat/code/__init__.py +13 -0
- src/extcompat/code/consent.py +162 -0
- src/extcompat/code/host.py +353 -0
- src/extcompat/code/hosts/py_host.py +763 -0
- src/extcompat/code/locate.py +105 -0
- src/extcompat/code/manager.py +325 -0
- src/extcompat/code/permissions.py +154 -0
- src/extcompat/code/sandbox.py +60 -0
- src/extcompat/colors.py +131 -0
- src/extcompat/common.py +184 -0
- src/extcompat/cson.py +269 -0
- src/extcompat/formats/__init__.py +22 -0
- src/extcompat/formats/_tm.py +189 -0
- src/extcompat/formats/_util.py +31 -0
- src/extcompat/formats/base16.py +66 -0
- src/extcompat/formats/brackets.py +172 -0
- src/extcompat/formats/eclipse.py +193 -0
- src/extcompat/formats/emacs.py +361 -0
- src/extcompat/formats/geany.py +147 -0
- src/extcompat/formats/generic.py +184 -0
- src/extcompat/formats/gtksource.py +117 -0
- src/extcompat/formats/helix.py +91 -0
- src/extcompat/formats/jetbrains.py +343 -0
- src/extcompat/formats/kate.py +130 -0
- src/extcompat/formats/micro.py +131 -0
- src/extcompat/formats/nano.py +111 -0
- src/extcompat/formats/notepadpp.py +140 -0
- src/extcompat/formats/pulsar.py +165 -0
- src/extcompat/formats/pyides.py +163 -0
- src/extcompat/formats/sublime.py +340 -0
- src/extcompat/jsonc.py +65 -0
- src/extcompat/lessish.py +128 -0
- src/extcompat/manager.py +122 -0
- src/extcompat/market/__init__.py +63 -0
- src/extcompat/market/sources.py +211 -0
- src/extcompat/model.py +88 -0
- src/extcompat/net.py +228 -0
- src/extcompat/openvsx.py +63 -0
- src/extcompat/readers.py +362 -0
- src/extcompat/registry.py +73 -0
- src/extcompat/safexml.py +63 -0
- src/extcompat/sexp.py +187 -0
- src/extcompat/sources.py +105 -0
- src/extcompat/store.py +276 -0
- src/extcompat/textmate.py +214 -0
- src/extcompat/themes.py +487 -0
- src/extcompat/yamlite.py +294 -0
- src/fileio.py +94 -0
- src/fs_ops.py +106 -0
- src/i18n.py +233 -0
- src/ia/__init__.py +1 -0
- src/ia/actions.py +295 -0
- src/ia/approval_gate.py +672 -0
- src/ia/checkpoints.py +308 -0
- src/ia/context_builder.py +921 -0
- src/ia/dialdiff.py +408 -0
- src/ia/iaspace.py +2078 -0
- src/ia/pair.py +296 -0
- src/ia/providers.py +954 -0
- src/ia/session.py +335 -0
- src/ia/toolbox.py +2524 -0
- src/launcher_actions.py +204 -0
- src/lint/__init__.py +1 -0
- src/lint/manager.py +1058 -0
- src/locales/.translate_manifest.json +64170 -0
- src/locales/de.json +4936 -0
- src/locales/en.json +4936 -0
- src/locales/es.json +4936 -0
- src/locales/fr.json +4936 -0
- src/locales/it.json +4936 -0
- src/locales/ja.json +4936 -0
- src/locales/ko.json +4936 -0
- src/locales/nl.json +4936 -0
- src/locales/pl.json +4936 -0
- src/locales/pt-BR.json +4936 -0
- src/locales/ru.json +4936 -0
- src/locales/tr.json +4936 -0
- src/locales/uk.json +4936 -0
- src/locales/zh-CN.json +4936 -0
- src/lsp/__init__.py +26 -0
- src/lsp/client.py +2300 -0
- src/lsp/dap_client.py +480 -0
- src/lsp/edits.py +84 -0
- src/lsp/framing.py +73 -0
- src/lsp/protocol.py +931 -0
- src/main.py +260 -0
- src/memtrim.py +91 -0
- src/plugins/__init__.py +1 -0
- src/plugins/api.py +1761 -0
- src/plugins/loader.py +571 -0
- src/plugins/process_runner.py +519 -0
- src/plugins/registry.py +342 -0
- src/plugins/safety.py +367 -0
- src/plugins/startup.py +195 -0
- src/plugins/store.py +1178 -0
- src/proc_registry.py +278 -0
- src/pyexec.py +394 -0
- src/recovery.py +259 -0
- src/stall_trace.py +92 -0
- src/standalone.py +1070 -0
- src/startup_profile.py +35 -0
- src/syntax/__init__.py +1 -0
- src/syntax/highlighter.py +776 -0
- src/syntax/patterns.py +584 -0
- src/system_profile.py +430 -0
- src/terminal/backends.py +658 -0
- src/terminal/internal.py +346 -0
- src/terminal/keys.py +138 -0
- src/terminal/palette.py +67 -0
- src/terminal/session.py +283 -0
- src/terminal/shells.py +79 -0
- src/terminal/view.py +489 -0
- src/terminal/vt.py +870 -0
- src/textfmt.py +22 -0
- src/theme/__init__.py +1 -0
- src/theme/base.py +1281 -0
- src/theme/colors.py +49 -0
- src/theme/manager.py +602 -0
- src/theme/utils.py +312 -0
- src/toolbox.py +329 -0
- src/trash_core.py +531 -0
- src/ui/__init__.py +1 -0
- src/ui/_perf_utils.py +285 -0
- src/ui/_persistence_utils.py +93 -0
- src/ui/accessibility.py +843 -0
- src/ui/activity_bar.py +860 -0
- src/ui/app_embed.py +434 -0
- src/ui/archive_panel.py +608 -0
- src/ui/bookmarks.py +314 -0
- src/ui/breadcrumb.py +383 -0
- src/ui/calculator_panel.py +982 -0
- src/ui/calendar_panel.py +1218 -0
- src/ui/chat_panel.py +1271 -0
- src/ui/chat_profile_dialog.py +278 -0
- src/ui/chat_render.py +128 -0
- src/ui/clock_panel.py +810 -0
- src/ui/code_outline.py +364 -0
- src/ui/code_runner.py +729 -0
- src/ui/code_stats.py +546 -0
- src/ui/collab_panel.py +1009 -0
- src/ui/color_picker.py +547 -0
- src/ui/command_palette.py +452 -0
- src/ui/cursor_manager.py +750 -0
- src/ui/custom_keywords_panel.py +413 -0
- src/ui/debug_panel.py +1037 -0
- src/ui/dependency_graph.py +692 -0
- src/ui/diff_panel.py +381 -0
- src/ui/docs_panel.py +514 -0
- src/ui/doom_embed.py +349 -0
- src/ui/dropdown.py +321 -0
- src/ui/easter_eggs.py +979 -0
- src/ui/env_manager.py +666 -0
- src/ui/extcode_bridge.py +215 -0
- src/ui/extcode_dialogs.py +412 -0
- src/ui/extcompat_dialog.py +583 -0
- src/ui/file_timeline.py +319 -0
- src/ui/file_tree.py +1208 -0
- src/ui/find_in_files.py +1355 -0
- src/ui/flowchart_panel.py +727 -0
- src/ui/formatter_panel.py +490 -0
- src/ui/git_auth.py +763 -0
- src/ui/git_clone_dialog.py +487 -0
- src/ui/git_panel.py +1483 -0
- src/ui/grab_safe.py +84 -0
- src/ui/internal_python_dialog.py +98 -0
- src/ui/k_ui/__init__.py +1305 -0
- src/ui/k_ui/_bgrenderer.py +317 -0
- src/ui/k_ui/_colors.py +213 -0
- src/ui/k_ui/_dock.py +545 -0
- src/ui/k_ui/_easter.py +290 -0
- src/ui/k_ui/_engine.py +5448 -0
- src/ui/k_ui/_perf.py +333 -0
- src/ui/k_ui/_tkutil.py +7 -0
- src/ui/k_ui/_tooltip.py +365 -0
- src/ui/k_ui/_widgets.py +1204 -0
- src/ui/k_ui/_world.py +837 -0
- src/ui/key_remapper.py +856 -0
- src/ui/launcher.py +1252 -0
- src/ui/lazy_panel.py +73 -0
- src/ui/macro_recorder.py +610 -0
- src/ui/menu_bar.py +898 -0
- src/ui/output_panel.py +321 -0
- src/ui/paint_canvas.py +1000 -0
- src/ui/paint_engine.py +535 -0
- src/ui/paint_panel.py +888 -0
- src/ui/panel_detach.py +112 -0
- src/ui/performance_panel.py +861 -0
- src/ui/pip_manager.py +1758 -0
- src/ui/plugin_panel.py +1586 -0
- src/ui/pomodoro_panel.py +447 -0
- src/ui/problems.py +566 -0
- src/ui/process_manager.py +1657 -0
- src/ui/project_templates.py +775 -0
- src/ui/recovery_dialog.py +122 -0
- src/ui/regex_playground.py +304 -0
- src/ui/remote_adapters.py +1398 -0
- src/ui/remote_browser.py +1224 -0
- src/ui/remote_profile_dialog.py +342 -0
- src/ui/render_panel.py +1293 -0
- src/ui/rest_client.py +549 -0
- src/ui/scratchpad.py +548 -0
- src/ui/search_bar.py +1274 -0
- src/ui/settings_editor.py +3349 -0
- src/ui/settings_window.py +1554 -0
- src/ui/snippets_panel.py +597 -0
- src/ui/sql_studio.py +1815 -0
- src/ui/status_bar.py +438 -0
- src/ui/tab_bar.py +654 -0
- src/ui/task_manager.py +1773 -0
- src/ui/terminal.py +525 -0
- src/ui/theme_preview_panel.py +851 -0
- src/ui/thread_safe_tk.py +152 -0
- src/ui/time_tracker.py +574 -0
- src/ui/tkbind.py +43 -0
- src/ui/todo_panel.py +358 -0
- src/ui/toolbox_panels.py +658 -0
- src/ui/trash_manager.py +657 -0
- src/ui/ui_scale.py +294 -0
- src/ui/ux_enhancements.py +41 -0
- src/ui/web_preview.py +397 -0
- src/ui/webdev.py +630 -0
- src/ui/welcome.py +567 -0
- src/ui/window_embed.py +1500 -0
- src/ui/wizard.py +1550 -0
- src/ui/workspace_switcher.py +418 -0
- src/ui/workspace_trust.py +370 -0
- src/ui/zen_audio.py +354 -0
- src/ui/zen_media.py +2271 -0
- src/ui/zen_media_client.py +303 -0
- src/ui/zen_media_host.py +329 -0
- src/ui/zen_player.py +907 -0
- src/ui/zen_player_widgets.py +700 -0
- src/updater/__init__.py +11 -0
- src/updater/assets.py +145 -0
- src/updater/backup.py +101 -0
- src/updater/channel.py +221 -0
- src/updater/dialog.py +492 -0
- src/updater/integrity.py +111 -0
- src/updater/manager.py +727 -0
- src/updater/result.py +114 -0
- src/venv_runtime.py +531 -0
- src/workspace_state.py +25 -0
src/ui/pip_manager.py
ADDED
|
@@ -0,0 +1,1758 @@
|
|
|
1
|
+
"""Codis - Gerenciador de Pacotes Pip.
|
|
2
|
+
|
|
3
|
+
Funcionalidades:
|
|
4
|
+
- Aba Instalados: cards visuais com versão, licença, links, badge de status
|
|
5
|
+
- Aba PyPI: busca com cards ricos (descrição, autor, downloads, botão instalar)
|
|
6
|
+
- Aba Ambientes: lista/cria/ativa virtual envs; o ambiente ativo passa a ser
|
|
7
|
+
o ambiente em que o próprio Codis roda (ver :mod:`src.venv_runtime`)
|
|
8
|
+
- Aba Outdated: lista pacotes com update disponĆvel, atualização em massa
|
|
9
|
+
- Log em tempo real com cores (ok/warn/err)
|
|
10
|
+
- Instalar, atualizar, desinstalar com progresso
|
|
11
|
+
- Exportar/importar requirements.txt
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import contextlib
|
|
17
|
+
import importlib
|
|
18
|
+
import json
|
|
19
|
+
import logging
|
|
20
|
+
import queue
|
|
21
|
+
import subprocess
|
|
22
|
+
import sys
|
|
23
|
+
import threading
|
|
24
|
+
import tkinter as tk
|
|
25
|
+
import urllib.error
|
|
26
|
+
import urllib.request
|
|
27
|
+
import webbrowser
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
from tkinter import filedialog, messagebox, ttk
|
|
30
|
+
from typing import Any
|
|
31
|
+
|
|
32
|
+
from src import dep_catalog as dc
|
|
33
|
+
from src import proc_registry, venv_runtime
|
|
34
|
+
from src.constants import APP_VERSION, FONT_MONO, FONT_UI
|
|
35
|
+
from src.i18n import _t
|
|
36
|
+
from src.pyexec import NoPythonError, child_env, python_cmd, python_executable
|
|
37
|
+
from src.theme.utils import make_toolbar_button
|
|
38
|
+
from src.ui._perf_utils import debounce_canvas
|
|
39
|
+
from src.ui.grab_safe import safe_grab_set
|
|
40
|
+
|
|
41
|
+
logger = logging.getLogger("Codis.PipManager")
|
|
42
|
+
|
|
43
|
+
_PYPI_URL = "https://pypi.org/pypi/{}/json"
|
|
44
|
+
_PYPI_SRCH = (
|
|
45
|
+
"https://pypi.org/search/?q={}&o=-zscore&c=Programming+Language+%3A%3A+Python"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
_pypi_cache: dict[str, dict] = {}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _safe_python(env_python: str | None = None) -> str:
|
|
52
|
+
"""Retorna um interpretador Python **real** para subprocessos.
|
|
53
|
+
|
|
54
|
+
Nunca devolve o executÔvel do próprio Codis: compilado, ``sys.executable``
|
|
55
|
+
Ć© o Codis, e ``[sys.executable, "-m", "pip"]`` abriria outro Codis em
|
|
56
|
+
cascata. Ver :mod:`src.pyexec`.
|
|
57
|
+
|
|
58
|
+
Raises:
|
|
59
|
+
NoPythonError: se não houver Python utilizÔvel (Codis compilado sem
|
|
60
|
+
Python instalado).
|
|
61
|
+
"""
|
|
62
|
+
return python_executable(env_python)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _make_popen_kwargs() -> dict:
|
|
66
|
+
"""Kwargs extras para subprocess no Windows: oculta console e stdin."""
|
|
67
|
+
kwargs: dict = {"stdin": subprocess.DEVNULL, "env": child_env()}
|
|
68
|
+
if sys.platform == "win32":
|
|
69
|
+
si = subprocess.STARTUPINFO()
|
|
70
|
+
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
|
71
|
+
si.wShowWindow = 0
|
|
72
|
+
kwargs["startupinfo"] = si
|
|
73
|
+
kwargs["creationflags"] = subprocess.CREATE_NO_WINDOW
|
|
74
|
+
return kwargs
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _pip(env_python: str | None = None) -> list[str]:
|
|
78
|
+
return python_cmd("-m", "pip", preferred=env_python)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _run_pip(
|
|
82
|
+
args: list[str], out_q: queue.Queue[str | None], env_python: str | None = None
|
|
83
|
+
) -> int:
|
|
84
|
+
try:
|
|
85
|
+
cmd = _pip(env_python) + args + ["--no-color"]
|
|
86
|
+
proc = subprocess.Popen(
|
|
87
|
+
cmd,
|
|
88
|
+
stdout=subprocess.PIPE,
|
|
89
|
+
stderr=subprocess.STDOUT,
|
|
90
|
+
text=True,
|
|
91
|
+
bufsize=1,
|
|
92
|
+
**_make_popen_kwargs(),
|
|
93
|
+
)
|
|
94
|
+
proc_registry.track(proc, "pip", "pip")
|
|
95
|
+
for line in proc.stdout or []:
|
|
96
|
+
out_q.put(line)
|
|
97
|
+
proc.wait()
|
|
98
|
+
importlib.invalidate_caches()
|
|
99
|
+
out_q.put(None)
|
|
100
|
+
return proc.returncode
|
|
101
|
+
except Exception as exc:
|
|
102
|
+
out_q.put(f"[Erro]: {exc}\n")
|
|
103
|
+
out_q.put(None)
|
|
104
|
+
return -1
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _fetch_pypi(name: str) -> dict | None:
|
|
108
|
+
if name in _pypi_cache:
|
|
109
|
+
return _pypi_cache[name]
|
|
110
|
+
try:
|
|
111
|
+
url = _PYPI_URL.format(name)
|
|
112
|
+
req = urllib.request.Request(url, headers={"User-Agent": "Codis/1.0"})
|
|
113
|
+
with urllib.request.urlopen(req, timeout=8) as r:
|
|
114
|
+
data = json.loads(r.read())
|
|
115
|
+
_pypi_cache[name] = data
|
|
116
|
+
return data
|
|
117
|
+
except Exception:
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _list_installed(env_python: str | None = None) -> list[dict]:
|
|
122
|
+
py = _safe_python(env_python)
|
|
123
|
+
try:
|
|
124
|
+
out = subprocess.check_output(
|
|
125
|
+
[py, "-m", "pip", "list", "--format=json"],
|
|
126
|
+
text=True,
|
|
127
|
+
timeout=30,
|
|
128
|
+
stderr=subprocess.DEVNULL,
|
|
129
|
+
**_make_popen_kwargs(),
|
|
130
|
+
)
|
|
131
|
+
return json.loads(out)
|
|
132
|
+
except NoPythonError:
|
|
133
|
+
raise
|
|
134
|
+
except Exception:
|
|
135
|
+
return []
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _list_outdated(env_python: str | None = None) -> list[dict]:
|
|
139
|
+
py = _safe_python(env_python)
|
|
140
|
+
try:
|
|
141
|
+
out = subprocess.check_output(
|
|
142
|
+
[py, "-m", "pip", "list", "--outdated", "--format=json"],
|
|
143
|
+
text=True,
|
|
144
|
+
timeout=60,
|
|
145
|
+
stderr=subprocess.DEVNULL,
|
|
146
|
+
**_make_popen_kwargs(),
|
|
147
|
+
)
|
|
148
|
+
return json.loads(out)
|
|
149
|
+
except NoPythonError:
|
|
150
|
+
raise
|
|
151
|
+
except Exception:
|
|
152
|
+
return []
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _show_info(name: str, env_python: str | None = None) -> str:
|
|
156
|
+
py = _safe_python(env_python)
|
|
157
|
+
try:
|
|
158
|
+
return subprocess.check_output(
|
|
159
|
+
[py, "-m", "pip", "show", name],
|
|
160
|
+
text=True,
|
|
161
|
+
timeout=10,
|
|
162
|
+
stderr=subprocess.DEVNULL,
|
|
163
|
+
**_make_popen_kwargs(),
|
|
164
|
+
)
|
|
165
|
+
except NoPythonError:
|
|
166
|
+
raise
|
|
167
|
+
except Exception:
|
|
168
|
+
return ""
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _find_venvs(base: Path | None = None) -> list[Path]:
|
|
172
|
+
"""Encontra virtual envs comuns."""
|
|
173
|
+
candidates = []
|
|
174
|
+
search_roots = [base] if base else []
|
|
175
|
+
search_roots += [Path.home(), Path.cwd()]
|
|
176
|
+
seen: set[Path] = set()
|
|
177
|
+
for root in search_roots:
|
|
178
|
+
if not root or not root.exists():
|
|
179
|
+
continue
|
|
180
|
+
for pattern in (
|
|
181
|
+
"*/.venv",
|
|
182
|
+
"*/venv",
|
|
183
|
+
"*/.env",
|
|
184
|
+
"*/env",
|
|
185
|
+
".venv",
|
|
186
|
+
"venv",
|
|
187
|
+
".env",
|
|
188
|
+
"env",
|
|
189
|
+
):
|
|
190
|
+
for p in root.glob(pattern):
|
|
191
|
+
rp = p.resolve()
|
|
192
|
+
if rp not in seen and (rp / "pyvenv.cfg").exists():
|
|
193
|
+
seen.add(rp)
|
|
194
|
+
candidates.append(rp)
|
|
195
|
+
return candidates[:30]
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _resolved(path: Path) -> Path:
|
|
199
|
+
"""``Path.resolve()`` tolerante a erros (raiz de venv: diretório real)."""
|
|
200
|
+
try:
|
|
201
|
+
return Path(path).resolve()
|
|
202
|
+
except (OSError, RuntimeError):
|
|
203
|
+
return Path(path)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _env_root_of(python: str | None) -> Path | None:
|
|
207
|
+
"""Raiz do venv de um ``python`` (``bin/python`` ou ``Scripts/python.exe``).
|
|
208
|
+
|
|
209
|
+
Não segue o link simbólico do interpretador: todo venv aponta para o mesmo
|
|
210
|
+
Python base, então comparar caminhos resolvidos faria todos parecerem ativos.
|
|
211
|
+
"""
|
|
212
|
+
if not python:
|
|
213
|
+
return None
|
|
214
|
+
return _resolved(Path(python).parent.parent)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class PipManagerPanel(tk.Frame):
|
|
218
|
+
"""Gerenciador pip redesenhado para o Codis."""
|
|
219
|
+
|
|
220
|
+
def __init__(
|
|
221
|
+
self,
|
|
222
|
+
parent: tk.Widget,
|
|
223
|
+
tmgr: Any,
|
|
224
|
+
cfg: Any,
|
|
225
|
+
on_restart: Any = None,
|
|
226
|
+
) -> None:
|
|
227
|
+
"""Inicializa o painel principal do gerenciador de pacotes pip.
|
|
228
|
+
|
|
229
|
+
Args:
|
|
230
|
+
parent: Widget pai.
|
|
231
|
+
tmgr: Gerenciador de temas.
|
|
232
|
+
cfg: Configuração do Codis.
|
|
233
|
+
on_restart: Callback que reinicia o Codis (oferecido quando o venv
|
|
234
|
+
escolhido só vale por inteiro depois de reiniciar).
|
|
235
|
+
"""
|
|
236
|
+
t = tmgr.theme
|
|
237
|
+
super().__init__(parent, bg=t.panel_bg)
|
|
238
|
+
self._tmgr = tmgr
|
|
239
|
+
self._cfg = cfg
|
|
240
|
+
self._on_restart = on_restart
|
|
241
|
+
|
|
242
|
+
self._packages: list[dict] = []
|
|
243
|
+
self._filtered: list[dict] = []
|
|
244
|
+
self._outdated: list[dict] = []
|
|
245
|
+
self._busy = False
|
|
246
|
+
self._active_env: str | None = venv_runtime.env_python()
|
|
247
|
+
self._install_var = tk.StringVar()
|
|
248
|
+
|
|
249
|
+
self._build(t)
|
|
250
|
+
self.after(200, self._refresh_installed)
|
|
251
|
+
|
|
252
|
+
def _build(self, t: Any) -> None:
|
|
253
|
+
hdr = tk.Frame(self, bg=t.activity_bg, height=52)
|
|
254
|
+
hdr.pack(fill="x")
|
|
255
|
+
hdr.pack_propagate(False)
|
|
256
|
+
|
|
257
|
+
tk.Label(
|
|
258
|
+
hdr, text="š¦", bg=t.activity_bg, fg=t.accent, font=(FONT_UI, 18)
|
|
259
|
+
).pack(side="left", padx=(12, 4), pady=8)
|
|
260
|
+
tk.Label(
|
|
261
|
+
hdr,
|
|
262
|
+
text=_t("pip.title", "Gerenciador Pip"),
|
|
263
|
+
bg=t.activity_bg,
|
|
264
|
+
fg=t.fg,
|
|
265
|
+
font=(FONT_UI, 13, "bold"),
|
|
266
|
+
).pack(side="left")
|
|
267
|
+
|
|
268
|
+
self._status_lbl = tk.Label(
|
|
269
|
+
hdr, text="", bg=t.activity_bg, fg=t.fg_muted, font=(FONT_UI, 8)
|
|
270
|
+
)
|
|
271
|
+
self._status_lbl.pack(side="right", padx=12)
|
|
272
|
+
|
|
273
|
+
inst_bar = tk.Frame(
|
|
274
|
+
self, bg=t.sidebar_bg, highlightthickness=1, highlightbackground=t.border
|
|
275
|
+
)
|
|
276
|
+
inst_bar.pack(fill="x", padx=0, pady=0)
|
|
277
|
+
|
|
278
|
+
tk.Label(
|
|
279
|
+
inst_bar,
|
|
280
|
+
text=_t("pip.install_pkg", "Instalar:"),
|
|
281
|
+
bg=t.sidebar_bg,
|
|
282
|
+
fg=t.fg_muted,
|
|
283
|
+
font=(FONT_UI, 8),
|
|
284
|
+
).pack(side="left", padx=(10, 4), pady=6)
|
|
285
|
+
inst_ent = tk.Entry(
|
|
286
|
+
inst_bar,
|
|
287
|
+
textvariable=self._install_var,
|
|
288
|
+
bg=t.editor_bg,
|
|
289
|
+
fg=t.fg,
|
|
290
|
+
insertbackground=t.cursor,
|
|
291
|
+
relief="flat",
|
|
292
|
+
bd=4,
|
|
293
|
+
font=(FONT_MONO, 9),
|
|
294
|
+
width=28,
|
|
295
|
+
)
|
|
296
|
+
inst_ent.pack(side="left", pady=6)
|
|
297
|
+
inst_ent.bind("<Return>", lambda _: self._quick_install())
|
|
298
|
+
|
|
299
|
+
inst_btn = tk.Label(
|
|
300
|
+
inst_bar,
|
|
301
|
+
text=_t("pip.install_btn", "ā Instalar"),
|
|
302
|
+
bg=t.accent,
|
|
303
|
+
fg="#FFF",
|
|
304
|
+
font=(FONT_UI, 8, "bold"),
|
|
305
|
+
padx=10,
|
|
306
|
+
pady=4,
|
|
307
|
+
cursor="hand2",
|
|
308
|
+
)
|
|
309
|
+
inst_btn.pack(side="left", padx=(4, 0), pady=6)
|
|
310
|
+
inst_btn.bind("<Button-1>", lambda _: self._quick_install())
|
|
311
|
+
|
|
312
|
+
env_lbl = tk.Label(
|
|
313
|
+
inst_bar,
|
|
314
|
+
text=_t("pip.env_label", "Env:"),
|
|
315
|
+
bg=t.sidebar_bg,
|
|
316
|
+
fg=t.fg_muted,
|
|
317
|
+
font=(FONT_UI, 8),
|
|
318
|
+
)
|
|
319
|
+
env_lbl.pack(side="right", padx=(0, 4), pady=6)
|
|
320
|
+
self._env_var = tk.StringVar(value="system")
|
|
321
|
+
self._env_combo = ttk.Combobox(
|
|
322
|
+
inst_bar,
|
|
323
|
+
textvariable=self._env_var,
|
|
324
|
+
state="readonly",
|
|
325
|
+
width=14,
|
|
326
|
+
font=(FONT_UI, 8),
|
|
327
|
+
)
|
|
328
|
+
self._env_combo.pack(side="right", padx=(0, 8), pady=6)
|
|
329
|
+
self._env_combo.bind("<<ComboboxSelected>>", self._on_env_changed)
|
|
330
|
+
self._refresh_env_list()
|
|
331
|
+
|
|
332
|
+
tk.Frame(self, bg=t.border, height=1).pack(fill="x")
|
|
333
|
+
|
|
334
|
+
nb = ttk.Notebook(self)
|
|
335
|
+
self._nb = nb
|
|
336
|
+
self._build_env_banner(t)
|
|
337
|
+
nb.pack(fill="both", expand=True)
|
|
338
|
+
|
|
339
|
+
self._tab_installed = tk.Frame(nb, bg=t.panel_bg)
|
|
340
|
+
self._tab_search = tk.Frame(nb, bg=t.panel_bg)
|
|
341
|
+
self._tab_outdated = tk.Frame(nb, bg=t.panel_bg)
|
|
342
|
+
self._tab_venv = tk.Frame(nb, bg=t.panel_bg)
|
|
343
|
+
self._tab_log = tk.Frame(nb, bg=t.panel_bg)
|
|
344
|
+
self._tab_codis = tk.Frame(nb, bg=t.panel_bg)
|
|
345
|
+
|
|
346
|
+
nb.add(self._tab_installed, text=_t(
|
|
347
|
+
"pip.tab_installed", " Instalados "))
|
|
348
|
+
nb.add(self._tab_search, text=_t("pip.tab_search", " š PyPI "))
|
|
349
|
+
nb.add(self._tab_outdated, text=_t(
|
|
350
|
+
"pip.tab_outdated", " ā Outdated "))
|
|
351
|
+
nb.add(self._tab_venv, text=_t("pip.tab_venv", " š Envs "))
|
|
352
|
+
nb.add(self._tab_codis, text=" š§© Codis Deps ")
|
|
353
|
+
nb.add(self._tab_log, text=_t("pip.tab_log", " Log "))
|
|
354
|
+
|
|
355
|
+
self._build_installed_tab(t)
|
|
356
|
+
self._build_search_tab(t)
|
|
357
|
+
self._build_outdated_tab(t)
|
|
358
|
+
self._build_venv_tab(t)
|
|
359
|
+
self._build_codis_deps_tab(t)
|
|
360
|
+
self._build_log_tab(t)
|
|
361
|
+
self._update_env_banner()
|
|
362
|
+
|
|
363
|
+
def _build_installed_tab(self, t: Any) -> None:
|
|
364
|
+
p = self._tab_installed
|
|
365
|
+
|
|
366
|
+
toolbar = tk.Frame(p, bg=t.panel_bg)
|
|
367
|
+
toolbar.pack(fill="x", padx=8, pady=6)
|
|
368
|
+
|
|
369
|
+
self._inst_search_var = tk.StringVar()
|
|
370
|
+
self._inst_search_job: str | None = None
|
|
371
|
+
srch = tk.Entry(
|
|
372
|
+
toolbar,
|
|
373
|
+
textvariable=self._inst_search_var,
|
|
374
|
+
bg=t.editor_bg,
|
|
375
|
+
fg=t.fg,
|
|
376
|
+
insertbackground=t.cursor,
|
|
377
|
+
relief="flat",
|
|
378
|
+
bd=4,
|
|
379
|
+
font=(FONT_UI, 9),
|
|
380
|
+
width=20,
|
|
381
|
+
highlightthickness=1,
|
|
382
|
+
highlightbackground=t.border,
|
|
383
|
+
)
|
|
384
|
+
srch.pack(side="left")
|
|
385
|
+
srch.bind("<KeyRelease>", lambda _: self._schedule_filter_installed())
|
|
386
|
+
|
|
387
|
+
tk.Label(
|
|
388
|
+
toolbar, text="š", bg=t.panel_bg, fg=t.fg_muted, font=(FONT_UI, 9)
|
|
389
|
+
).pack(side="left", padx=(2, 8))
|
|
390
|
+
|
|
391
|
+
def _tb(lbl: str, cmd: Any) -> tk.Label:
|
|
392
|
+
return make_toolbar_button(
|
|
393
|
+
toolbar,
|
|
394
|
+
t,
|
|
395
|
+
lbl,
|
|
396
|
+
cmd,
|
|
397
|
+
side="right",
|
|
398
|
+
inner_padx=7,
|
|
399
|
+
inner_pady=3,
|
|
400
|
+
font_size=7,
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
_tb(_t("pip.export", "š¤ Exportar req"), self._export_requirements)
|
|
404
|
+
_tb(_t("pip.import", "š„ Importar req"), self._import_requirements)
|
|
405
|
+
_tb(_t("pip.refresh", "ā» Atualizar"), self._refresh_installed)
|
|
406
|
+
|
|
407
|
+
self._inst_stat = tk.Label(
|
|
408
|
+
p, text="", bg=t.panel_bg, fg=t.fg_muted, font=(FONT_UI, 7), anchor="w"
|
|
409
|
+
)
|
|
410
|
+
self._inst_stat.pack(fill="x", padx=10, pady=(0, 2))
|
|
411
|
+
|
|
412
|
+
cols = ("name", "version", "summary")
|
|
413
|
+
self._inst_tree = ttk.Treeview(
|
|
414
|
+
p, columns=cols, show="headings", selectmode="browse"
|
|
415
|
+
)
|
|
416
|
+
self._inst_tree.heading("name", text=_t("pip.col_name", "Pacote"))
|
|
417
|
+
self._inst_tree.heading(
|
|
418
|
+
"version", text=_t("pip.col_version", "Versão"))
|
|
419
|
+
self._inst_tree.heading("summary", text=_t(
|
|
420
|
+
"pip.col_summary", "Descrição"))
|
|
421
|
+
self._inst_tree.column("name", width=160, minwidth=100)
|
|
422
|
+
self._inst_tree.column("version", width=80, minwidth=60)
|
|
423
|
+
self._inst_tree.column("summary", width=340, minwidth=100)
|
|
424
|
+
self._inst_tree.tag_configure("even", background=t.editor_bg)
|
|
425
|
+
self._inst_tree.tag_configure("odd", background=t.panel_bg)
|
|
426
|
+
self._inst_tree.tag_configure("outdated", foreground="#f9e2af")
|
|
427
|
+
|
|
428
|
+
vsb = ttk.Scrollbar(p, orient="vertical",
|
|
429
|
+
command=self._inst_tree.yview)
|
|
430
|
+
hsb = ttk.Scrollbar(p, orient="horizontal",
|
|
431
|
+
command=self._inst_tree.xview)
|
|
432
|
+
self._inst_tree.configure(
|
|
433
|
+
yscrollcommand=vsb.set, xscrollcommand=hsb.set)
|
|
434
|
+
vsb.pack(side="right", fill="y")
|
|
435
|
+
self._inst_tree.pack(fill="both", expand=True, padx=(8, 0))
|
|
436
|
+
hsb.pack(fill="x", padx=8)
|
|
437
|
+
|
|
438
|
+
action_row = tk.Frame(p, bg=t.panel_bg)
|
|
439
|
+
action_row.pack(fill="x", padx=8, pady=(4, 6))
|
|
440
|
+
|
|
441
|
+
def _ab(
|
|
442
|
+
lbl: str, cmd: Any, bg: str | None = None, fg: str | None = None
|
|
443
|
+
) -> tk.Label:
|
|
444
|
+
abg = bg or t.sidebar_bg
|
|
445
|
+
afg = fg or t.fg
|
|
446
|
+
b = tk.Label(
|
|
447
|
+
action_row,
|
|
448
|
+
text=lbl,
|
|
449
|
+
bg=abg,
|
|
450
|
+
fg=afg,
|
|
451
|
+
font=(FONT_UI, 8, "bold"),
|
|
452
|
+
padx=10,
|
|
453
|
+
pady=5,
|
|
454
|
+
cursor="hand2",
|
|
455
|
+
)
|
|
456
|
+
b.pack(side="left", padx=2)
|
|
457
|
+
b.bind("<Button-1>", lambda _: cmd())
|
|
458
|
+
b.bind("<Enter>", lambda _: b.config(bg=t.btn_hover))
|
|
459
|
+
b.bind("<Leave>", lambda _: b.config(bg=abg))
|
|
460
|
+
return b
|
|
461
|
+
|
|
462
|
+
_ab(_t("pip.upgrade", "⬠Atualizar"), self._upgrade_selected)
|
|
463
|
+
_ab(_t("pip.show_info", "ā¹ Info"), self._show_package_info)
|
|
464
|
+
_ab(_t("pip.open_pypi", "š PyPI"), self._open_pypi_page)
|
|
465
|
+
_ab(
|
|
466
|
+
_t("pip.uninstall", "š Remover"),
|
|
467
|
+
self._uninstall_selected,
|
|
468
|
+
bg="#c0392b",
|
|
469
|
+
fg="#FFF",
|
|
470
|
+
)
|
|
471
|
+
|
|
472
|
+
self._inst_tree.bind("<Double-1>", lambda _: self._show_package_info())
|
|
473
|
+
|
|
474
|
+
def _build_search_tab(self, t: Any) -> None:
|
|
475
|
+
p = self._tab_search
|
|
476
|
+
|
|
477
|
+
progress_bar = tk.Frame(p, bg=t.panel_bg)
|
|
478
|
+
progress_bar.pack(fill="x", padx=8, pady=8)
|
|
479
|
+
|
|
480
|
+
self._pypi_var = tk.StringVar()
|
|
481
|
+
srch_ent = tk.Entry(
|
|
482
|
+
progress_bar,
|
|
483
|
+
textvariable=self._pypi_var,
|
|
484
|
+
bg=t.editor_bg,
|
|
485
|
+
fg=t.fg,
|
|
486
|
+
insertbackground=t.cursor,
|
|
487
|
+
relief="flat",
|
|
488
|
+
bd=4,
|
|
489
|
+
font=(FONT_UI, 10),
|
|
490
|
+
width=28,
|
|
491
|
+
)
|
|
492
|
+
srch_ent.pack(side="left")
|
|
493
|
+
srch_ent.bind("<Return>", lambda _: self._search_pypi())
|
|
494
|
+
srch_ent.focus_set()
|
|
495
|
+
|
|
496
|
+
srch_btn = tk.Label(
|
|
497
|
+
progress_bar,
|
|
498
|
+
text=_t("pip.search_btn", "š Buscar"),
|
|
499
|
+
bg=t.accent,
|
|
500
|
+
fg="#FFF",
|
|
501
|
+
font=(FONT_UI, 9, "bold"),
|
|
502
|
+
padx=12,
|
|
503
|
+
pady=5,
|
|
504
|
+
cursor="hand2",
|
|
505
|
+
)
|
|
506
|
+
srch_btn.pack(side="left", padx=6)
|
|
507
|
+
srch_btn.bind("<Button-1>", lambda _: self._search_pypi())
|
|
508
|
+
|
|
509
|
+
self._pypi_status = tk.Label(
|
|
510
|
+
progress_bar, text="", bg=t.panel_bg, fg=t.fg_muted, font=(FONT_UI, 8)
|
|
511
|
+
)
|
|
512
|
+
self._pypi_status.pack(side="left", padx=8)
|
|
513
|
+
|
|
514
|
+
wrap = tk.Frame(p, bg=t.panel_bg)
|
|
515
|
+
wrap.pack(fill="both", expand=True, padx=8)
|
|
516
|
+
|
|
517
|
+
self._pypi_canvas = tk.Canvas(
|
|
518
|
+
wrap, bg=t.panel_bg, highlightthickness=0)
|
|
519
|
+
vsb = ttk.Scrollbar(wrap, orient="vertical",
|
|
520
|
+
command=self._pypi_canvas.yview)
|
|
521
|
+
self._pypi_canvas.configure(yscrollcommand=vsb.set)
|
|
522
|
+
vsb.pack(side="right", fill="y")
|
|
523
|
+
self._pypi_canvas.pack(fill="both", expand=True)
|
|
524
|
+
|
|
525
|
+
self._pypi_inner = tk.Frame(self._pypi_canvas, bg=t.panel_bg)
|
|
526
|
+
self._pypi_win = self._pypi_canvas.create_window(
|
|
527
|
+
(0, 0), window=self._pypi_inner, anchor="nw"
|
|
528
|
+
)
|
|
529
|
+
|
|
530
|
+
debounce_canvas(
|
|
531
|
+
self._pypi_canvas, self._pypi_win, ms=40, extra_widget=self._pypi_inner
|
|
532
|
+
)
|
|
533
|
+
|
|
534
|
+
self._pypi_hint = tk.Label(
|
|
535
|
+
self._pypi_inner,
|
|
536
|
+
text=_t(
|
|
537
|
+
"pip.search_hint", "š Digite o nome de um pacote para buscar no PyPI"
|
|
538
|
+
),
|
|
539
|
+
bg=t.panel_bg,
|
|
540
|
+
fg=t.fg_muted,
|
|
541
|
+
font=(FONT_UI, 10),
|
|
542
|
+
)
|
|
543
|
+
self._pypi_hint.pack(pady=40)
|
|
544
|
+
|
|
545
|
+
def _build_outdated_tab(self, t: Any) -> None:
|
|
546
|
+
p = self._tab_outdated
|
|
547
|
+
|
|
548
|
+
progress_bar = tk.Frame(p, bg=t.panel_bg)
|
|
549
|
+
progress_bar.pack(fill="x", padx=8, pady=6)
|
|
550
|
+
|
|
551
|
+
tk.Label(
|
|
552
|
+
progress_bar,
|
|
553
|
+
text=_t("pip.outdated_hint", "Pacotes com atualização disponĆvel:"),
|
|
554
|
+
bg=t.panel_bg,
|
|
555
|
+
fg=t.fg_muted,
|
|
556
|
+
font=(FONT_UI, 8),
|
|
557
|
+
).pack(side="left")
|
|
558
|
+
|
|
559
|
+
def _tb(lbl: str, cmd: Any, accent: bool = False) -> tk.Label:
|
|
560
|
+
return make_toolbar_button(
|
|
561
|
+
progress_bar, t, lbl, cmd, accent=accent, side="right", outer_pady=0
|
|
562
|
+
)
|
|
563
|
+
|
|
564
|
+
_tb(_t("pip.update_all", "ā¬ā¬ Atualizar todos"),
|
|
565
|
+
self._upgrade_all, accent=True)
|
|
566
|
+
_tb(_t("pip.check_outdated", "ā» Verificar"), self._check_outdated)
|
|
567
|
+
|
|
568
|
+
cols = ("name", "current", "latest", "type")
|
|
569
|
+
self._out_tree = ttk.Treeview(
|
|
570
|
+
p, columns=cols, show="headings", selectmode="browse"
|
|
571
|
+
)
|
|
572
|
+
self._out_tree.heading("name", text=_t("pip.col_name", "Pacote"))
|
|
573
|
+
self._out_tree.heading("current", text=_t("pip.col_current", "Atual"))
|
|
574
|
+
self._out_tree.heading("latest", text=_t(
|
|
575
|
+
"pip.col_latest", "DisponĆvel"))
|
|
576
|
+
self._out_tree.heading("type", text=_t("pip.col_type", "Tipo"))
|
|
577
|
+
self._out_tree.column("name", width=200)
|
|
578
|
+
self._out_tree.column("current", width=100)
|
|
579
|
+
self._out_tree.column("latest", width=100)
|
|
580
|
+
self._out_tree.column("type", width=80)
|
|
581
|
+
self._out_tree.tag_configure("pkg", foreground="#f9e2af")
|
|
582
|
+
|
|
583
|
+
vsb = ttk.Scrollbar(p, orient="vertical", command=self._out_tree.yview)
|
|
584
|
+
vsb.pack(side="right", fill="y")
|
|
585
|
+
self._out_tree.pack(fill="both", expand=True, padx=(8, 0))
|
|
586
|
+
|
|
587
|
+
act = tk.Frame(p, bg=t.panel_bg)
|
|
588
|
+
act.pack(fill="x", padx=8, pady=4)
|
|
589
|
+
upd_sel = tk.Label(
|
|
590
|
+
act,
|
|
591
|
+
text=_t("pip.upgrade", "⬠Atualizar selecionado"),
|
|
592
|
+
bg=t.sidebar_bg,
|
|
593
|
+
fg=t.fg,
|
|
594
|
+
font=(FONT_UI, 8),
|
|
595
|
+
padx=8,
|
|
596
|
+
pady=4,
|
|
597
|
+
cursor="hand2",
|
|
598
|
+
)
|
|
599
|
+
upd_sel.pack(side="left", padx=2)
|
|
600
|
+
upd_sel.bind("<Button-1>", lambda _: self._upgrade_outdated_selected())
|
|
601
|
+
|
|
602
|
+
def _build_venv_tab(self, t: Any) -> None:
|
|
603
|
+
p = self._tab_venv
|
|
604
|
+
|
|
605
|
+
hdr = tk.Frame(p, bg=t.panel_bg)
|
|
606
|
+
hdr.pack(fill="x", padx=8, pady=6)
|
|
607
|
+
tk.Label(
|
|
608
|
+
hdr,
|
|
609
|
+
text=_t("pip.venv_title", "Ambientes Virtuais"),
|
|
610
|
+
bg=t.panel_bg,
|
|
611
|
+
fg=t.fg,
|
|
612
|
+
font=(FONT_UI, 10, "bold"),
|
|
613
|
+
).pack(side="left")
|
|
614
|
+
|
|
615
|
+
def _tb(lbl: str, cmd: Any, accent: bool = False) -> tk.Label:
|
|
616
|
+
return make_toolbar_button(
|
|
617
|
+
hdr, t, lbl, cmd, accent=accent, side="right", outer_pady=0
|
|
618
|
+
)
|
|
619
|
+
|
|
620
|
+
_tb(_t("pip.venv_new", "ļ¼ Criar venv"), self._create_venv, accent=True)
|
|
621
|
+
_tb(_t("pip.venv_browse", "š Procurar"), self._browse_venv)
|
|
622
|
+
_tb(_t("pip.venv_scan", "ā» Escanear"), self._scan_venvs)
|
|
623
|
+
|
|
624
|
+
self._env_status_lbl = tk.Label(
|
|
625
|
+
p,
|
|
626
|
+
text="",
|
|
627
|
+
bg=t.panel_bg,
|
|
628
|
+
fg=t.fg_muted,
|
|
629
|
+
font=(FONT_MONO, 8),
|
|
630
|
+
anchor="w",
|
|
631
|
+
justify="left",
|
|
632
|
+
)
|
|
633
|
+
self._env_status_lbl.pack(fill="x", padx=10, pady=(0, 4))
|
|
634
|
+
|
|
635
|
+
wrap = tk.Frame(p, bg=t.panel_bg)
|
|
636
|
+
wrap.pack(fill="both", expand=True, padx=8)
|
|
637
|
+
|
|
638
|
+
venv_canvas = tk.Canvas(wrap, bg=t.panel_bg, highlightthickness=0)
|
|
639
|
+
vsb = ttk.Scrollbar(wrap, orient="vertical", command=venv_canvas.yview)
|
|
640
|
+
venv_canvas.configure(yscrollcommand=vsb.set)
|
|
641
|
+
vsb.pack(side="right", fill="y")
|
|
642
|
+
venv_canvas.pack(fill="both", expand=True)
|
|
643
|
+
|
|
644
|
+
self._venv_inner = tk.Frame(venv_canvas, bg=t.panel_bg)
|
|
645
|
+
venv_win = venv_canvas.create_window(
|
|
646
|
+
(0, 0), window=self._venv_inner, anchor="nw"
|
|
647
|
+
)
|
|
648
|
+
|
|
649
|
+
debounce_canvas(venv_canvas, venv_win, ms=40,
|
|
650
|
+
extra_widget=self._venv_inner)
|
|
651
|
+
|
|
652
|
+
self._venvs: list[Path] = []
|
|
653
|
+
self.after(300, self._scan_venvs)
|
|
654
|
+
|
|
655
|
+
# Aba "Codis Deps": o que o Codis, o build e o desenvolvimento pedem
|
|
656
|
+
|
|
657
|
+
def _dep_python(self) -> str | None:
|
|
658
|
+
"""Interpretador onde o pip instala; ``None`` para olhar o próprio processo."""
|
|
659
|
+
if self._active_env:
|
|
660
|
+
return self._active_env
|
|
661
|
+
if getattr(sys, "frozen", False):
|
|
662
|
+
try:
|
|
663
|
+
return python_executable(None)
|
|
664
|
+
except NoPythonError:
|
|
665
|
+
return None
|
|
666
|
+
return None
|
|
667
|
+
|
|
668
|
+
def _build_codis_deps_tab(self, t: Any) -> None:
|
|
669
|
+
"""Constrói a aba de dependências do Codis (opcionais, de build e de desenvolvimento)."""
|
|
670
|
+
p = self._tab_codis
|
|
671
|
+
self._dep_t = t
|
|
672
|
+
self._dep_statuses: list[dc.DepStatus] = []
|
|
673
|
+
self._dep_generation = 0
|
|
674
|
+
|
|
675
|
+
hdr = tk.Frame(p, bg=t.panel_bg)
|
|
676
|
+
hdr.pack(fill="x", padx=12, pady=(10, 4))
|
|
677
|
+
tk.Label(
|
|
678
|
+
hdr, text="DependĆŖncias do Codis", bg=t.panel_bg, fg=t.fg,
|
|
679
|
+
font=(FONT_UI, 11, "bold"), anchor="w",
|
|
680
|
+
).pack(side="left")
|
|
681
|
+
|
|
682
|
+
def _button(parent: tk.Misc, text: str, command: Any, accent: bool = False) -> tk.Button:
|
|
683
|
+
return tk.Button(
|
|
684
|
+
parent, text=text, command=command, relief="flat", cursor="hand2", padx=10,
|
|
685
|
+
bg=getattr(t, "accent", t.sel_bg) if accent else t.sidebar_bg,
|
|
686
|
+
fg=getattr(t, "sel_fg", "#fff") if accent else t.fg, font=(FONT_UI, 9),
|
|
687
|
+
)
|
|
688
|
+
|
|
689
|
+
right = tk.Frame(hdr, bg=t.panel_bg)
|
|
690
|
+
right.pack(side="right")
|
|
691
|
+
_button(right, "Copiar diagnóstico", self._copy_dep_report).pack(side="left", padx=(0, 6))
|
|
692
|
+
_button(right, "Verificar de novo", self._refresh_codis_deps).pack(side="left")
|
|
693
|
+
|
|
694
|
+
sets = tk.Frame(p, bg=t.panel_bg)
|
|
695
|
+
sets.pack(fill="x", padx=12, pady=(2, 4))
|
|
696
|
+
tk.Label(
|
|
697
|
+
sets, text="Instalar conjunto:", bg=t.panel_bg, fg=t.fg_muted, font=(FONT_UI, 8)
|
|
698
|
+
).pack(side="left", padx=(0, 6))
|
|
699
|
+
_button(sets, "Recursos comuns", self._install_common_missing, accent=True).pack(side="left", padx=(0, 4))
|
|
700
|
+
for key, (title, _pkgs) in dc.PROFILES.items():
|
|
701
|
+
_button(sets, title, lambda k=key: self._install_profile(k)).pack(side="left", padx=(0, 4))
|
|
702
|
+
|
|
703
|
+
self._dep_summary = tk.Label(
|
|
704
|
+
p, text="Verificando...", bg=t.panel_bg, fg=t.fg_muted, font=(FONT_UI, 8),
|
|
705
|
+
anchor="w", justify="left",
|
|
706
|
+
)
|
|
707
|
+
self._dep_summary.pack(fill="x", padx=12, pady=(4, 2))
|
|
708
|
+
tk.Frame(p, bg=t.border, height=1).pack(fill="x", padx=12, pady=(2, 4))
|
|
709
|
+
|
|
710
|
+
outer = tk.Frame(p, bg=t.panel_bg)
|
|
711
|
+
outer.pack(fill="both", expand=True)
|
|
712
|
+
canvas = tk.Canvas(outer, bg=t.panel_bg, highlightthickness=0)
|
|
713
|
+
vsb = ttk.Scrollbar(outer, orient="vertical", command=canvas.yview)
|
|
714
|
+
canvas.config(yscrollcommand=vsb.set)
|
|
715
|
+
vsb.pack(side="right", fill="y")
|
|
716
|
+
canvas.pack(side="left", fill="both", expand=True)
|
|
717
|
+
inner = tk.Frame(canvas, bg=t.panel_bg)
|
|
718
|
+
canvas_win = canvas.create_window((0, 0), window=inner, anchor="nw")
|
|
719
|
+
debounce_canvas(canvas, canvas_win, ms=40, extra_widget=inner)
|
|
720
|
+
canvas.bind("<MouseWheel>", lambda e: canvas.yview_scroll(-1 * (e.delta // 120), "units"))
|
|
721
|
+
canvas.bind("<Button-4>", lambda _: canvas.yview_scroll(-3, "units"))
|
|
722
|
+
canvas.bind("<Button-5>", lambda _: canvas.yview_scroll(3, "units"))
|
|
723
|
+
self._dep_inner = inner
|
|
724
|
+
self._dep_canvas = canvas
|
|
725
|
+
|
|
726
|
+
self.after(150, self._refresh_codis_deps)
|
|
727
|
+
|
|
728
|
+
def _refresh_codis_deps(self, *_: Any) -> None:
|
|
729
|
+
"""Verifica as dependĆŖncias em segundo plano e redesenha a lista quando terminar."""
|
|
730
|
+
self._dep_generation += 1
|
|
731
|
+
generation = self._dep_generation
|
|
732
|
+
self._dep_summary.config(text="Verificando...")
|
|
733
|
+
results: queue.Queue[list[dc.DepStatus]] = queue.Queue()
|
|
734
|
+
python = self._dep_python()
|
|
735
|
+
|
|
736
|
+
def _work() -> None:
|
|
737
|
+
try:
|
|
738
|
+
results.put(dc.check_all(python=python))
|
|
739
|
+
except Exception:
|
|
740
|
+
results.put([]) # a lista aparece mesmo que o registro do erro demore
|
|
741
|
+
logger.exception("Falha ao verificar as dependĆŖncias")
|
|
742
|
+
|
|
743
|
+
def _poll() -> None:
|
|
744
|
+
if generation != self._dep_generation or not self.winfo_exists():
|
|
745
|
+
return
|
|
746
|
+
try:
|
|
747
|
+
statuses = results.get_nowait()
|
|
748
|
+
except queue.Empty:
|
|
749
|
+
self.after(80, _poll)
|
|
750
|
+
return
|
|
751
|
+
self._dep_statuses = statuses
|
|
752
|
+
self._render_codis_deps()
|
|
753
|
+
|
|
754
|
+
threading.Thread(target=_work, daemon=True, name="codis-dep-check").start()
|
|
755
|
+
self.after(80, _poll)
|
|
756
|
+
|
|
757
|
+
def _render_codis_deps(self) -> None:
|
|
758
|
+
t = self._dep_t
|
|
759
|
+
inner = self._dep_inner
|
|
760
|
+
for w in inner.winfo_children():
|
|
761
|
+
w.destroy()
|
|
762
|
+
|
|
763
|
+
ready, total = dc.summary(self._dep_statuses)
|
|
764
|
+
python = self._dep_python() or sys.executable
|
|
765
|
+
self._dep_summary.config(text=f"{ready} de {total} prontas | Ambiente: {python}")
|
|
766
|
+
ok_fg = getattr(t, "diff_add_fg", "#4caf50")
|
|
767
|
+
warn_fg = getattr(t, "warn_fg", "#f9e2af")
|
|
768
|
+
labels = {
|
|
769
|
+
dc.OK: ("Instalado", ok_fg),
|
|
770
|
+
dc.OUTDATED: ("Desatualizado", warn_fg),
|
|
771
|
+
dc.MISSING: ("Ausente", warn_fg),
|
|
772
|
+
dc.NO_LIB: ("Falta a biblioteca do sistema", warn_fg),
|
|
773
|
+
dc.BLOCKED: ("Falta a biblioteca do sistema", warn_fg),
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
for title, items in dc.by_group(self._dep_statuses):
|
|
777
|
+
tk.Label(
|
|
778
|
+
inner, text=f" {title}", bg=t.panel_bg, fg=t.fg_muted,
|
|
779
|
+
font=(FONT_UI, 8, "bold"), anchor="w",
|
|
780
|
+
).pack(fill="x", padx=8, pady=(8, 2))
|
|
781
|
+
tk.Frame(inner, bg=t.border, height=1).pack(fill="x", padx=8, pady=(0, 4))
|
|
782
|
+
for status in items:
|
|
783
|
+
self._build_dep_card(inner, t, status, labels)
|
|
784
|
+
|
|
785
|
+
self._dep_canvas.update_idletasks()
|
|
786
|
+
bounds = self._dep_canvas.bbox("all")
|
|
787
|
+
if bounds:
|
|
788
|
+
self._dep_canvas.config(scrollregion=bounds)
|
|
789
|
+
|
|
790
|
+
def _build_dep_card(self, parent: tk.Misc, t: Any, status: dc.DepStatus, labels: dict) -> None:
|
|
791
|
+
dep = status.dep
|
|
792
|
+
text, color = labels[status.state]
|
|
793
|
+
card = tk.Frame(parent, bg=t.panel_bg, highlightthickness=1, highlightbackground=t.border)
|
|
794
|
+
card.pack(fill="x", padx=8, pady=3)
|
|
795
|
+
top = tk.Frame(card, bg=t.panel_bg)
|
|
796
|
+
top.pack(fill="x", padx=10, pady=(6, 2))
|
|
797
|
+
tk.Label(top, text=dep.pkg, bg=t.panel_bg, fg=t.fg, font=(FONT_UI, 9, "bold")).pack(side="left")
|
|
798
|
+
shown = f"{status.version} (mĆnimo {dep.min})" if status.version else f"mĆnimo {dep.min}"
|
|
799
|
+
tk.Label(top, text=shown, bg=t.panel_bg, fg=t.fg_muted, font=(FONT_UI, 8)).pack(side="left", padx=(8, 0))
|
|
800
|
+
tk.Label(top, text=text, bg=t.panel_bg, fg=color, font=(FONT_UI, 8)).pack(side="right", padx=(8, 0))
|
|
801
|
+
if dc.needs_install(status):
|
|
802
|
+
verb = "Atualizar" if status.state == dc.OUTDATED else "Instalar"
|
|
803
|
+
tk.Button(
|
|
804
|
+
top, text=verb, relief="flat", cursor="hand2", padx=8, font=(FONT_UI, 8),
|
|
805
|
+
bg=getattr(t, "accent", t.sel_bg), fg=getattr(t, "sel_fg", "#fff"),
|
|
806
|
+
command=lambda spec=dep.spec: self._install_packages([spec]),
|
|
807
|
+
).pack(side="right", padx=4)
|
|
808
|
+
tk.Label(
|
|
809
|
+
card, text=dep.desc, bg=t.panel_bg, fg=t.fg_muted, font=(FONT_UI, 8),
|
|
810
|
+
anchor="w", justify="left", wraplength=540,
|
|
811
|
+
).pack(fill="x", padx=10, pady=(0, 4 if dep.lib else 6))
|
|
812
|
+
if dep.lib and status.state in (dc.NO_LIB, dc.BLOCKED):
|
|
813
|
+
tk.Label(
|
|
814
|
+
card, text=f"{dep.lib.label} não encontrada. {dc.lib_help(dep)}", bg=t.panel_bg, fg=color,
|
|
815
|
+
font=(FONT_UI, 8), anchor="w", justify="left", wraplength=540,
|
|
816
|
+
).pack(fill="x", padx=10, pady=(0, 6))
|
|
817
|
+
|
|
818
|
+
def _confirm_install(self, title: str, specs: list[str]) -> None:
|
|
819
|
+
if not specs:
|
|
820
|
+
self._log(f"{title}: nada a instalar, tudo jĆ” estĆ” em dia.\n")
|
|
821
|
+
self._set_status("")
|
|
822
|
+
return
|
|
823
|
+
listing = "\n".join(f" {spec}" for spec in specs)
|
|
824
|
+
if messagebox.askyesno(title, f"Instalar no ambiente selecionado?\n\n{listing}", parent=self):
|
|
825
|
+
self._install_packages(specs)
|
|
826
|
+
|
|
827
|
+
def _install_common_missing(self) -> None:
|
|
828
|
+
"""Instala os recursos comuns que faltam; mĆdia (mpv/VLC), build e testes ficam de fora."""
|
|
829
|
+
self._confirm_install("Recursos comuns", dc.batch_specs(self._dep_statuses))
|
|
830
|
+
|
|
831
|
+
def _install_profile(self, key: str) -> None:
|
|
832
|
+
title = dc.PROFILES[key][0]
|
|
833
|
+
self._confirm_install(title, dc.profile_specs(key, self._dep_statuses))
|
|
834
|
+
|
|
835
|
+
def _copy_dep_report(self) -> None:
|
|
836
|
+
report = dc.build_report(self._dep_statuses, APP_VERSION)
|
|
837
|
+
self.clipboard_clear()
|
|
838
|
+
self.clipboard_append(report)
|
|
839
|
+
self._set_status("Diagnóstico copiado para a Ôrea de transferência.")
|
|
840
|
+
|
|
841
|
+
def _install_packages(self, pkgs: list[str]) -> None:
|
|
842
|
+
"""Instala uma lista de pacotes e exibe o log em tempo real."""
|
|
843
|
+
if self._busy:
|
|
844
|
+
return
|
|
845
|
+
self._busy = True
|
|
846
|
+
q: queue.Queue[str | None] = queue.Queue()
|
|
847
|
+
args = ["install", "--disable-pip-version-check", "--progress-bar", "off", *pkgs]
|
|
848
|
+
|
|
849
|
+
self._log(f"Instalando: {', '.join(pkgs)}\n")
|
|
850
|
+
self._set_status(f"Instalando {len(pkgs)} pacote(s)...")
|
|
851
|
+
|
|
852
|
+
def _work() -> None:
|
|
853
|
+
_run_pip(args, q, self._active_env)
|
|
854
|
+
|
|
855
|
+
threading.Thread(target=_work, daemon=True).start()
|
|
856
|
+
self._drain_queue(q, on_done=self._refresh_codis_deps)
|
|
857
|
+
|
|
858
|
+
def _build_log_tab(self, t: Any) -> None:
|
|
859
|
+
p = self._tab_log
|
|
860
|
+
|
|
861
|
+
btn_row = tk.Frame(p, bg=t.panel_bg)
|
|
862
|
+
btn_row.pack(fill="x", padx=8, pady=4)
|
|
863
|
+
clear_b = tk.Label(
|
|
864
|
+
btn_row,
|
|
865
|
+
text=_t("pip.clear_log", "š Limpar log"),
|
|
866
|
+
bg=t.sidebar_bg,
|
|
867
|
+
fg=t.fg,
|
|
868
|
+
font=(FONT_UI, 8),
|
|
869
|
+
padx=8,
|
|
870
|
+
pady=4,
|
|
871
|
+
cursor="hand2",
|
|
872
|
+
)
|
|
873
|
+
clear_b.pack(side="right")
|
|
874
|
+
clear_b.bind("<Button-1>", lambda _: self._clear_log())
|
|
875
|
+
|
|
876
|
+
self._log_text = tk.Text(
|
|
877
|
+
p,
|
|
878
|
+
bg=t.editor_bg,
|
|
879
|
+
fg=t.fg,
|
|
880
|
+
font=(FONT_MONO, 9),
|
|
881
|
+
wrap="word",
|
|
882
|
+
insertbackground=t.cursor,
|
|
883
|
+
relief="flat",
|
|
884
|
+
state="disabled",
|
|
885
|
+
selectbackground=t.sel_bg,
|
|
886
|
+
)
|
|
887
|
+
vsb = ttk.Scrollbar(p, orient="vertical", command=self._log_text.yview)
|
|
888
|
+
vsb.pack(side="right", fill="y")
|
|
889
|
+
self._log_text.config(yscrollcommand=vsb.set)
|
|
890
|
+
self._log_text.pack(fill="both", expand=True, padx=8)
|
|
891
|
+
|
|
892
|
+
self._log_text.tag_configure("ok", foreground="#a6e3a1")
|
|
893
|
+
self._log_text.tag_configure("warn", foreground="#f9e2af")
|
|
894
|
+
self._log_text.tag_configure("err", foreground="#f38ba8")
|
|
895
|
+
self._log_text.tag_configure("info", foreground="#89b4fa")
|
|
896
|
+
self._log_text.tag_configure("dim", foreground="#6c7086")
|
|
897
|
+
|
|
898
|
+
def _set_status(self, msg: str) -> None:
|
|
899
|
+
self._status_lbl.config(text=msg)
|
|
900
|
+
|
|
901
|
+
def _log(self, line: str) -> None:
|
|
902
|
+
self._log_text.config(state="normal")
|
|
903
|
+
line_stripped = line.rstrip()
|
|
904
|
+
if not line_stripped:
|
|
905
|
+
self._log_text.config(state="disabled")
|
|
906
|
+
return
|
|
907
|
+
tag = "info"
|
|
908
|
+
ll = line_stripped.lower()
|
|
909
|
+
if "error" in ll or "failed" in ll or "exception" in ll:
|
|
910
|
+
tag = "err"
|
|
911
|
+
elif "warning" in ll or "warn" in ll:
|
|
912
|
+
tag = "warn"
|
|
913
|
+
elif "successfully" in ll or "installed" in ll or "upgraded" in ll:
|
|
914
|
+
tag = "ok"
|
|
915
|
+
elif line_stripped.startswith(" ") or line_stripped.startswith("-"):
|
|
916
|
+
tag = "dim"
|
|
917
|
+
self._log_text.insert("end", line_stripped + "\n", tag)
|
|
918
|
+
self._log_text.see("end")
|
|
919
|
+
self._log_text.config(state="disabled")
|
|
920
|
+
|
|
921
|
+
def _clear_log(self) -> None:
|
|
922
|
+
self._log_text.config(state="normal")
|
|
923
|
+
self._log_text.delete("1.0", "end")
|
|
924
|
+
self._log_text.config(state="disabled")
|
|
925
|
+
|
|
926
|
+
def _drain_queue(self, q: queue.Queue[str | None], on_done: Any = None) -> None:
|
|
927
|
+
with contextlib.suppress(queue.Empty):
|
|
928
|
+
while True:
|
|
929
|
+
item = q.get_nowait()
|
|
930
|
+
if item is None:
|
|
931
|
+
self._busy = False
|
|
932
|
+
self._set_status("")
|
|
933
|
+
if on_done:
|
|
934
|
+
on_done()
|
|
935
|
+
return
|
|
936
|
+
self._log(item)
|
|
937
|
+
self.after(80, lambda: self._drain_queue(q, on_done))
|
|
938
|
+
|
|
939
|
+
def _refresh_installed(self) -> None:
|
|
940
|
+
if self._busy:
|
|
941
|
+
return
|
|
942
|
+
self._busy = True
|
|
943
|
+
self._set_status(_t("pip.loading", "Carregando..."))
|
|
944
|
+
outdated_names = {p["name"].lower() for p in self._outdated}
|
|
945
|
+
|
|
946
|
+
def _work() -> None:
|
|
947
|
+
try:
|
|
948
|
+
pkgs = _list_installed(self._active_env)
|
|
949
|
+
except NoPythonError as exc:
|
|
950
|
+
msg = str(exc)
|
|
951
|
+
self.after(0, lambda m=msg: self._python_missing(m))
|
|
952
|
+
return
|
|
953
|
+
self.after(0, lambda: self._populate_installed(
|
|
954
|
+
pkgs, outdated_names))
|
|
955
|
+
|
|
956
|
+
threading.Thread(target=_work, daemon=True).start()
|
|
957
|
+
|
|
958
|
+
def _python_missing(self, message: str) -> None:
|
|
959
|
+
"""Exibe, uma vez, que não hÔ Python para o pip (Codis compilado)."""
|
|
960
|
+
self._busy = False
|
|
961
|
+
self._set_status(message)
|
|
962
|
+
self._log(f"ā {message}\n")
|
|
963
|
+
if not getattr(self, "_python_missing_shown", False):
|
|
964
|
+
self._python_missing_shown = True
|
|
965
|
+
messagebox.showwarning(
|
|
966
|
+
_t("pip.no_python_title", "Python não encontrado"), message, parent=self
|
|
967
|
+
)
|
|
968
|
+
|
|
969
|
+
def _populate_installed(self, pkgs: list[dict], outdated_names: set[str]) -> None:
|
|
970
|
+
self._packages = pkgs
|
|
971
|
+
self._filter_installed(outdated_names)
|
|
972
|
+
self._busy = False
|
|
973
|
+
self._set_status("")
|
|
974
|
+
n = len(pkgs)
|
|
975
|
+
self._inst_stat.config(
|
|
976
|
+
text=_t("pip.pkg_count", f"{n} pacotes instalados"))
|
|
977
|
+
|
|
978
|
+
def _schedule_filter_installed(self) -> None:
|
|
979
|
+
"""Debounce de 80ms na busca de pacotes instalados."""
|
|
980
|
+
if self._inst_search_job:
|
|
981
|
+
with contextlib.suppress(Exception):
|
|
982
|
+
self.after_cancel(self._inst_search_job)
|
|
983
|
+
self._inst_search_job = self.after(80, self._filter_installed)
|
|
984
|
+
|
|
985
|
+
def _filter_installed(self, outdated_names: set[str] | None = None) -> None:
|
|
986
|
+
q = self._inst_search_var.get().lower()
|
|
987
|
+
if outdated_names is None:
|
|
988
|
+
outdated_names = {p["name"].lower() for p in self._outdated}
|
|
989
|
+
self._filtered = [p for p in self._packages if q in p["name"].lower()]
|
|
990
|
+
self._inst_tree.delete(*self._inst_tree.get_children())
|
|
991
|
+
for i, p in enumerate(self._filtered):
|
|
992
|
+
tag = (
|
|
993
|
+
"outdated"
|
|
994
|
+
if p["name"].lower() in outdated_names
|
|
995
|
+
else ("even" if i % 2 == 0 else "odd")
|
|
996
|
+
)
|
|
997
|
+
self._inst_tree.insert(
|
|
998
|
+
"", "end", values=(p["name"], p["version"], ""), tags=(tag,)
|
|
999
|
+
)
|
|
1000
|
+
|
|
1001
|
+
def _selected_package(self) -> str | None:
|
|
1002
|
+
sel = self._inst_tree.selection()
|
|
1003
|
+
if not sel:
|
|
1004
|
+
return None
|
|
1005
|
+
return self._inst_tree.item(sel[0])["values"][0]
|
|
1006
|
+
|
|
1007
|
+
def _quick_install(self) -> None:
|
|
1008
|
+
pkg = self._install_var.get().strip()
|
|
1009
|
+
if not pkg or self._busy:
|
|
1010
|
+
return
|
|
1011
|
+
self._install_var.set("")
|
|
1012
|
+
self._pip_op(["install", pkg], on_done=self._refresh_installed)
|
|
1013
|
+
|
|
1014
|
+
def _upgrade_selected(self) -> None:
|
|
1015
|
+
pkg = self._selected_package()
|
|
1016
|
+
if not pkg:
|
|
1017
|
+
return
|
|
1018
|
+
self._pip_op(["install", "--upgrade", pkg],
|
|
1019
|
+
on_done=self._refresh_installed)
|
|
1020
|
+
|
|
1021
|
+
def _uninstall_selected(self) -> None:
|
|
1022
|
+
pkg = self._selected_package()
|
|
1023
|
+
if not pkg:
|
|
1024
|
+
return
|
|
1025
|
+
if not messagebox.askyesno(
|
|
1026
|
+
_t("pip.uninstall_title", "Desinstalar"),
|
|
1027
|
+
_t("pip.uninstall_confirm", f"Desinstalar '{pkg}'?"),
|
|
1028
|
+
):
|
|
1029
|
+
return
|
|
1030
|
+
self._pip_op(["uninstall", "-y", pkg], on_done=self._refresh_installed)
|
|
1031
|
+
|
|
1032
|
+
def _show_package_info(self) -> None:
|
|
1033
|
+
pkg = self._selected_package()
|
|
1034
|
+
if not pkg:
|
|
1035
|
+
return
|
|
1036
|
+
try:
|
|
1037
|
+
info = _show_info(pkg, self._active_env)
|
|
1038
|
+
except NoPythonError as exc:
|
|
1039
|
+
self._python_missing(str(exc))
|
|
1040
|
+
return
|
|
1041
|
+
if not info:
|
|
1042
|
+
return
|
|
1043
|
+
_InfoWindow(self, self._tmgr, pkg, info)
|
|
1044
|
+
|
|
1045
|
+
def _open_pypi_page(self) -> None:
|
|
1046
|
+
pkg = self._selected_package()
|
|
1047
|
+
if not pkg:
|
|
1048
|
+
return
|
|
1049
|
+
webbrowser.open(f"https://pypi.org/project/{pkg}/")
|
|
1050
|
+
|
|
1051
|
+
def _export_requirements(self) -> None:
|
|
1052
|
+
path = filedialog.asksaveasfilename(
|
|
1053
|
+
defaultextension=".txt",
|
|
1054
|
+
filetypes=[("Text", "*.txt"), ("All", "*.*")],
|
|
1055
|
+
initialfile="requirements.txt",
|
|
1056
|
+
)
|
|
1057
|
+
if not path:
|
|
1058
|
+
return
|
|
1059
|
+
lines = [f"{p['name']}=={p['version']}" for p in self._packages]
|
|
1060
|
+
Path(path).write_text("\n".join(lines) + "\n", encoding="utf-8")
|
|
1061
|
+
self._log(f"Exportado: {path}\n")
|
|
1062
|
+
|
|
1063
|
+
def _import_requirements(self) -> None:
|
|
1064
|
+
path = filedialog.askopenfilename(
|
|
1065
|
+
filetypes=[("Text", "*.txt"), ("All", "*.*")])
|
|
1066
|
+
if not path:
|
|
1067
|
+
return
|
|
1068
|
+
self._pip_op(["install", "-r", path], on_done=self._refresh_installed)
|
|
1069
|
+
|
|
1070
|
+
def _check_outdated(self) -> None:
|
|
1071
|
+
if self._busy:
|
|
1072
|
+
return
|
|
1073
|
+
self._busy = True
|
|
1074
|
+
self._set_status(
|
|
1075
|
+
_t("pip.checking_updates", "Verificando atualizaƧƵes..."))
|
|
1076
|
+
|
|
1077
|
+
def _work() -> None:
|
|
1078
|
+
try:
|
|
1079
|
+
data = _list_outdated(self._active_env)
|
|
1080
|
+
except NoPythonError as exc:
|
|
1081
|
+
msg = str(exc)
|
|
1082
|
+
self.after(0, lambda m=msg: self._python_missing(m))
|
|
1083
|
+
return
|
|
1084
|
+
self.after(0, lambda: self._populate_outdated(data))
|
|
1085
|
+
|
|
1086
|
+
threading.Thread(target=_work, daemon=True).start()
|
|
1087
|
+
|
|
1088
|
+
def _populate_outdated(self, data: list[dict]) -> None:
|
|
1089
|
+
self._outdated = data
|
|
1090
|
+
self._busy = False
|
|
1091
|
+
self._set_status(
|
|
1092
|
+
_t("pip.outdated_found", f"{len(data)} pacote(s) desatualizado(s)")
|
|
1093
|
+
)
|
|
1094
|
+
self._out_tree.delete(*self._out_tree.get_children())
|
|
1095
|
+
for p in data:
|
|
1096
|
+
self._out_tree.insert(
|
|
1097
|
+
"",
|
|
1098
|
+
"end",
|
|
1099
|
+
values=(
|
|
1100
|
+
p["name"],
|
|
1101
|
+
p["version"],
|
|
1102
|
+
p["latest_version"],
|
|
1103
|
+
p.get("latest_filetype", ""),
|
|
1104
|
+
),
|
|
1105
|
+
tags=("pkg",),
|
|
1106
|
+
)
|
|
1107
|
+
self._filter_installed()
|
|
1108
|
+
|
|
1109
|
+
def _upgrade_outdated_selected(self) -> None:
|
|
1110
|
+
sel = self._out_tree.selection()
|
|
1111
|
+
if not sel:
|
|
1112
|
+
return
|
|
1113
|
+
pkg = self._out_tree.item(sel[0])["values"][0]
|
|
1114
|
+
self._pip_op(["install", "--upgrade", pkg],
|
|
1115
|
+
on_done=self._check_outdated)
|
|
1116
|
+
|
|
1117
|
+
def _upgrade_all(self) -> None:
|
|
1118
|
+
if not self._outdated:
|
|
1119
|
+
return
|
|
1120
|
+
names = [p["name"] for p in self._outdated]
|
|
1121
|
+
if not messagebox.askyesno(
|
|
1122
|
+
_t("pip.update_all_title", "Atualizar todos"),
|
|
1123
|
+
_t("pip.update_all_confirm", f"Atualizar {len(names)} pacotes?"),
|
|
1124
|
+
):
|
|
1125
|
+
return
|
|
1126
|
+
self._pip_op(
|
|
1127
|
+
["install", "--upgrade"] + names,
|
|
1128
|
+
on_done=lambda: (self._check_outdated(),
|
|
1129
|
+
self._refresh_installed()),
|
|
1130
|
+
)
|
|
1131
|
+
|
|
1132
|
+
def _pip_op(self, args: list[str], on_done: Any = None) -> None:
|
|
1133
|
+
if self._busy:
|
|
1134
|
+
return
|
|
1135
|
+
self._busy = True
|
|
1136
|
+
q: queue.Queue[str | None] = queue.Queue()
|
|
1137
|
+
op_name = " ".join(args[:2])
|
|
1138
|
+
self._set_status(f"{op_name}...")
|
|
1139
|
+
self._log(f"\nā¶ pip {' '.join(args)}\n")
|
|
1140
|
+
threading.Thread(
|
|
1141
|
+
target=_run_pip, args=(args, q, self._active_env), daemon=True
|
|
1142
|
+
).start()
|
|
1143
|
+
self._drain_queue(q, on_done=on_done)
|
|
1144
|
+
|
|
1145
|
+
def _search_pypi(self) -> None:
|
|
1146
|
+
query = self._pypi_var.get().strip()
|
|
1147
|
+
if not query:
|
|
1148
|
+
return
|
|
1149
|
+
self._pypi_status.config(text=_t("pip.searching", "Buscando..."))
|
|
1150
|
+
for w in self._pypi_inner.winfo_children():
|
|
1151
|
+
w.destroy()
|
|
1152
|
+
|
|
1153
|
+
threading.Thread(
|
|
1154
|
+
target=self._do_pypi_search, args=(query,), daemon=True
|
|
1155
|
+
).start()
|
|
1156
|
+
|
|
1157
|
+
def _do_pypi_search(self, query: str) -> None:
|
|
1158
|
+
exact = _fetch_pypi(query)
|
|
1159
|
+
results = [self._pypi_to_card(exact)] if exact else []
|
|
1160
|
+
self.after(0, lambda: self._render_pypi_cards(results))
|
|
1161
|
+
|
|
1162
|
+
def _pypi_to_card(self, data: dict) -> dict:
|
|
1163
|
+
info = data.get("info", {})
|
|
1164
|
+
return {
|
|
1165
|
+
"name": info.get("name", ""),
|
|
1166
|
+
"version": info.get("version", ""),
|
|
1167
|
+
"summary": info.get("summary", ""),
|
|
1168
|
+
"author": info.get("author", ""),
|
|
1169
|
+
"license": info.get("license", ""),
|
|
1170
|
+
"home": info.get("home_page", "") or info.get("project_url", ""),
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
def _render_pypi_cards(self, results: list[dict]) -> None:
|
|
1174
|
+
t = self._tmgr.theme
|
|
1175
|
+
for w in self._pypi_inner.winfo_children():
|
|
1176
|
+
w.destroy()
|
|
1177
|
+
|
|
1178
|
+
if not results:
|
|
1179
|
+
tk.Label(
|
|
1180
|
+
self._pypi_inner,
|
|
1181
|
+
text=_t("pip.no_results", "Nenhum resultado encontrado."),
|
|
1182
|
+
bg=t.panel_bg,
|
|
1183
|
+
fg=t.fg_muted,
|
|
1184
|
+
font=(FONT_UI, 10),
|
|
1185
|
+
).pack(pady=20)
|
|
1186
|
+
self._pypi_status.config(text="")
|
|
1187
|
+
return
|
|
1188
|
+
|
|
1189
|
+
self._pypi_status.config(
|
|
1190
|
+
text=_t("pip.search_results", f"{len(results)} resultado(s)")
|
|
1191
|
+
)
|
|
1192
|
+
installed_names = {p["name"].lower() for p in self._packages}
|
|
1193
|
+
|
|
1194
|
+
for r in results:
|
|
1195
|
+
self._build_pypi_card(t, r, installed_names)
|
|
1196
|
+
|
|
1197
|
+
def _build_pypi_card(self, t: Any, r: dict, installed: set[str]) -> None:
|
|
1198
|
+
name = r.get("name", "")
|
|
1199
|
+
version = r.get("version", "")
|
|
1200
|
+
summary = r.get("summary", "") or ""
|
|
1201
|
+
author = r.get("author", "") or ""
|
|
1202
|
+
license_ = r.get("license", "") or ""
|
|
1203
|
+
is_inst = name.lower() in installed
|
|
1204
|
+
|
|
1205
|
+
card = tk.Frame(
|
|
1206
|
+
self._pypi_inner,
|
|
1207
|
+
bg=t.sidebar_bg,
|
|
1208
|
+
highlightthickness=1,
|
|
1209
|
+
highlightbackground=t.border,
|
|
1210
|
+
)
|
|
1211
|
+
card.pack(fill="x", pady=3, padx=2)
|
|
1212
|
+
|
|
1213
|
+
top = tk.Frame(card, bg=t.sidebar_bg)
|
|
1214
|
+
top.pack(fill="x", padx=10, pady=(8, 2))
|
|
1215
|
+
|
|
1216
|
+
tk.Label(
|
|
1217
|
+
top, text=name, bg=t.sidebar_bg, fg=t.accent, font=(
|
|
1218
|
+
FONT_UI, 10, "bold")
|
|
1219
|
+
).pack(side="left")
|
|
1220
|
+
if version:
|
|
1221
|
+
tk.Label(
|
|
1222
|
+
top,
|
|
1223
|
+
text=f" v{version}",
|
|
1224
|
+
bg=t.sidebar_bg,
|
|
1225
|
+
fg=t.fg_muted,
|
|
1226
|
+
font=(FONT_MONO, 8),
|
|
1227
|
+
).pack(side="left")
|
|
1228
|
+
|
|
1229
|
+
if is_inst:
|
|
1230
|
+
tk.Label(
|
|
1231
|
+
top,
|
|
1232
|
+
text=_t("pip.installed_badge", "instalado"),
|
|
1233
|
+
bg="#1e6b2e",
|
|
1234
|
+
fg="#a6e3a1",
|
|
1235
|
+
font=(FONT_UI, 7),
|
|
1236
|
+
padx=5,
|
|
1237
|
+
pady=1,
|
|
1238
|
+
).pack(side="left", padx=6)
|
|
1239
|
+
|
|
1240
|
+
btn_text = (
|
|
1241
|
+
_t("pip.upgrade", "⬠Atualizar")
|
|
1242
|
+
if is_inst
|
|
1243
|
+
else _t("pip.install_btn", "ā Instalar")
|
|
1244
|
+
)
|
|
1245
|
+
inst_b = tk.Label(
|
|
1246
|
+
top,
|
|
1247
|
+
text=btn_text,
|
|
1248
|
+
bg=t.accent,
|
|
1249
|
+
fg="#FFF",
|
|
1250
|
+
font=(FONT_UI, 7, "bold"),
|
|
1251
|
+
padx=6,
|
|
1252
|
+
pady=2,
|
|
1253
|
+
cursor="hand2",
|
|
1254
|
+
)
|
|
1255
|
+
inst_b.pack(side="right")
|
|
1256
|
+
inst_b.bind(
|
|
1257
|
+
"<Button-1>",
|
|
1258
|
+
lambda _, n=name: self._pip_op(
|
|
1259
|
+
["install", n], on_done=self._refresh_installed
|
|
1260
|
+
),
|
|
1261
|
+
)
|
|
1262
|
+
|
|
1263
|
+
if summary:
|
|
1264
|
+
tk.Label(
|
|
1265
|
+
card,
|
|
1266
|
+
text=summary[:120],
|
|
1267
|
+
bg=t.sidebar_bg,
|
|
1268
|
+
fg=t.fg,
|
|
1269
|
+
font=(FONT_UI, 8),
|
|
1270
|
+
anchor="w",
|
|
1271
|
+
wraplength=480,
|
|
1272
|
+
).pack(fill="x", padx=10, pady=(0, 4))
|
|
1273
|
+
|
|
1274
|
+
meta = tk.Frame(card, bg=t.sidebar_bg)
|
|
1275
|
+
meta.pack(fill="x", padx=10, pady=(0, 8))
|
|
1276
|
+
if author:
|
|
1277
|
+
tk.Label(
|
|
1278
|
+
meta,
|
|
1279
|
+
text=f"š¤ {author}",
|
|
1280
|
+
bg=t.sidebar_bg,
|
|
1281
|
+
fg=t.fg_muted,
|
|
1282
|
+
font=(FONT_UI, 7),
|
|
1283
|
+
).pack(side="left", padx=(0, 8))
|
|
1284
|
+
if license_:
|
|
1285
|
+
tk.Label(
|
|
1286
|
+
meta,
|
|
1287
|
+
text=f"ā {license_[:30]}",
|
|
1288
|
+
bg=t.sidebar_bg,
|
|
1289
|
+
fg=t.fg_muted,
|
|
1290
|
+
font=(FONT_UI, 7),
|
|
1291
|
+
).pack(side="left")
|
|
1292
|
+
pypi_lnk = tk.Label(
|
|
1293
|
+
meta,
|
|
1294
|
+
text=_t("pip.pypi_link", "š PyPI"),
|
|
1295
|
+
bg=t.sidebar_bg,
|
|
1296
|
+
fg=t.t_link,
|
|
1297
|
+
font=(FONT_UI, 7),
|
|
1298
|
+
cursor="hand2",
|
|
1299
|
+
)
|
|
1300
|
+
pypi_lnk.pack(side="right")
|
|
1301
|
+
pypi_lnk.bind(
|
|
1302
|
+
"<Button-1>",
|
|
1303
|
+
lambda _, n=name: webbrowser.open(
|
|
1304
|
+
f"https://pypi.org/project/{n}/"
|
|
1305
|
+
),
|
|
1306
|
+
)
|
|
1307
|
+
|
|
1308
|
+
def _scan_venvs(self) -> None:
|
|
1309
|
+
def _work() -> None:
|
|
1310
|
+
found = _find_venvs()
|
|
1311
|
+
self.after(0, lambda: self._render_venvs(found))
|
|
1312
|
+
|
|
1313
|
+
threading.Thread(target=_work, daemon=True).start()
|
|
1314
|
+
|
|
1315
|
+
def _render_venvs(self, venvs: list[Path]) -> None:
|
|
1316
|
+
t = self._tmgr.theme
|
|
1317
|
+
self._venvs = venvs
|
|
1318
|
+
for w in self._venv_inner.winfo_children():
|
|
1319
|
+
w.destroy()
|
|
1320
|
+
|
|
1321
|
+
if not venvs:
|
|
1322
|
+
tk.Label(
|
|
1323
|
+
self._venv_inner,
|
|
1324
|
+
text=_t(
|
|
1325
|
+
"pip.no_venvs",
|
|
1326
|
+
"Nenhum ambiente virtual encontrado.\nCrie um com ļ¼ Criar venv.",
|
|
1327
|
+
),
|
|
1328
|
+
bg=t.panel_bg,
|
|
1329
|
+
fg=t.fg_muted,
|
|
1330
|
+
font=(FONT_UI, 9),
|
|
1331
|
+
justify="center",
|
|
1332
|
+
).pack(pady=24)
|
|
1333
|
+
return
|
|
1334
|
+
|
|
1335
|
+
for venv_path in venvs:
|
|
1336
|
+
self._build_venv_card(t, venv_path)
|
|
1337
|
+
|
|
1338
|
+
def _build_venv_card(self, t: Any, venv_path: Path) -> None:
|
|
1339
|
+
py_bin = venv_path / "bin" / "python"
|
|
1340
|
+
if not py_bin.exists():
|
|
1341
|
+
py_bin = venv_path / "Scripts" / "python.exe"
|
|
1342
|
+
|
|
1343
|
+
is_active = _env_root_of(self._active_env) == _resolved(venv_path)
|
|
1344
|
+
|
|
1345
|
+
card_bg = t.editor_bg if is_active else t.sidebar_bg
|
|
1346
|
+
border = t.accent if is_active else t.border
|
|
1347
|
+
card = tk.Frame(
|
|
1348
|
+
self._venv_inner,
|
|
1349
|
+
bg=card_bg,
|
|
1350
|
+
highlightthickness=1,
|
|
1351
|
+
highlightbackground=border,
|
|
1352
|
+
)
|
|
1353
|
+
card.pack(fill="x", pady=3, padx=2)
|
|
1354
|
+
|
|
1355
|
+
top = tk.Frame(card, bg=card_bg)
|
|
1356
|
+
top.pack(fill="x", padx=10, pady=(8, 2))
|
|
1357
|
+
|
|
1358
|
+
icon = "š¢" if is_active else "š"
|
|
1359
|
+
tk.Label(top, text=icon, bg=card_bg, font=(
|
|
1360
|
+
FONT_UI, 12)).pack(side="left")
|
|
1361
|
+
tk.Label(
|
|
1362
|
+
top,
|
|
1363
|
+
text=f" {venv_path.name}",
|
|
1364
|
+
bg=card_bg,
|
|
1365
|
+
fg=t.fg,
|
|
1366
|
+
font=(FONT_UI, 9, "bold"),
|
|
1367
|
+
).pack(side="left")
|
|
1368
|
+
|
|
1369
|
+
if is_active:
|
|
1370
|
+
tk.Label(
|
|
1371
|
+
top,
|
|
1372
|
+
text=_t("pip.active_env", "ativo"),
|
|
1373
|
+
bg=t.accent,
|
|
1374
|
+
fg="#FFF",
|
|
1375
|
+
font=(FONT_UI, 7),
|
|
1376
|
+
padx=5,
|
|
1377
|
+
pady=1,
|
|
1378
|
+
).pack(side="left", padx=6)
|
|
1379
|
+
|
|
1380
|
+
act_btn = tk.Label(
|
|
1381
|
+
top,
|
|
1382
|
+
text=(
|
|
1383
|
+
_t("pip.env_deactivate", "ā» Desativar")
|
|
1384
|
+
if is_active
|
|
1385
|
+
else _t("pip.env_activate", "ā¶ Usar")
|
|
1386
|
+
),
|
|
1387
|
+
bg=t.accent if not is_active else t.sidebar_bg,
|
|
1388
|
+
fg="#FFF" if not is_active else t.fg,
|
|
1389
|
+
font=(FONT_UI, 7),
|
|
1390
|
+
padx=6,
|
|
1391
|
+
pady=2,
|
|
1392
|
+
cursor="hand2",
|
|
1393
|
+
)
|
|
1394
|
+
act_btn.pack(side="right")
|
|
1395
|
+
act_btn.bind(
|
|
1396
|
+
"<Button-1>", lambda _, p=py_bin, a=is_active: self._toggle_venv(
|
|
1397
|
+
p, a)
|
|
1398
|
+
)
|
|
1399
|
+
|
|
1400
|
+
tk.Label(
|
|
1401
|
+
card,
|
|
1402
|
+
text=str(venv_path),
|
|
1403
|
+
bg=card_bg,
|
|
1404
|
+
fg=t.fg_muted,
|
|
1405
|
+
font=(FONT_MONO, 7),
|
|
1406
|
+
anchor="w",
|
|
1407
|
+
).pack(fill="x", padx=10, pady=(0, 8))
|
|
1408
|
+
|
|
1409
|
+
def _toggle_venv(self, py_bin: Path, currently_active: bool) -> None:
|
|
1410
|
+
self._adopt(None if currently_active else py_bin.parent.parent)
|
|
1411
|
+
|
|
1412
|
+
def _env_choices(self) -> list[tuple[str, Path]]:
|
|
1413
|
+
"""Ambientes selecionÔveis como ``(rótulo, raiz)``, sem repetições.
|
|
1414
|
+
|
|
1415
|
+
Inclui o venv adotado mesmo quando ele estĆ” fora das pastas varridas. O
|
|
1416
|
+
rótulo é o nome da pasta, ou ``projeto/nome`` quando hÔ nomes iguais.
|
|
1417
|
+
"""
|
|
1418
|
+
roots: list[Path] = []
|
|
1419
|
+
current = venv_runtime.current()
|
|
1420
|
+
extra = [current.root] if current is not None else []
|
|
1421
|
+
for candidate in [*_find_venvs(), *getattr(self, "_venvs", []), *extra]:
|
|
1422
|
+
resolved = _resolved(candidate)
|
|
1423
|
+
if resolved not in roots:
|
|
1424
|
+
roots.append(resolved)
|
|
1425
|
+
names = [r.name for r in roots]
|
|
1426
|
+
return [
|
|
1427
|
+
(r.name if names.count(r.name) == 1 else f"{r.parent.name}/{r.name}", r)
|
|
1428
|
+
for r in roots
|
|
1429
|
+
]
|
|
1430
|
+
|
|
1431
|
+
def _refresh_env_list(self) -> None:
|
|
1432
|
+
choices = self._env_choices()
|
|
1433
|
+
self._env_combo["values"] = ["system"] + [label for label, _ in choices]
|
|
1434
|
+
active = _env_root_of(self._active_env)
|
|
1435
|
+
label = next((lb for lb, root in choices if root == active), None)
|
|
1436
|
+
self._env_var.set(label if self._active_env and label else "system")
|
|
1437
|
+
|
|
1438
|
+
def _on_env_changed(self, _e: Any = None) -> None:
|
|
1439
|
+
sel = self._env_var.get()
|
|
1440
|
+
if sel == "system":
|
|
1441
|
+
self._adopt(None)
|
|
1442
|
+
return
|
|
1443
|
+
for label, root in self._env_choices():
|
|
1444
|
+
if label == sel:
|
|
1445
|
+
self._adopt(root)
|
|
1446
|
+
return
|
|
1447
|
+
|
|
1448
|
+
def _adopt(self, root: Path | None) -> None:
|
|
1449
|
+
"""Faz de ``root`` o ambiente do Codis (``None`` volta ao Python do sistema).
|
|
1450
|
+
|
|
1451
|
+
O pip, o LSP, o executor de código e o terminal passam a usar o Python
|
|
1452
|
+
do venv na hora; os módulos do próprio Codis só trocam ao reiniciar.
|
|
1453
|
+
"""
|
|
1454
|
+
try:
|
|
1455
|
+
if root is None:
|
|
1456
|
+
venv_runtime.clear_choice()
|
|
1457
|
+
self._active_env = None
|
|
1458
|
+
else:
|
|
1459
|
+
info = venv_runtime.set_choice(root)
|
|
1460
|
+
self._active_env = str(info.python)
|
|
1461
|
+
except ValueError:
|
|
1462
|
+
messagebox.showerror(
|
|
1463
|
+
_t("pip.env_adopt_title", "Usar como ambiente do Codis"),
|
|
1464
|
+
_t("pip.env_invalid", "Ambiente virtual invƔlido: {path}", path=root),
|
|
1465
|
+
parent=self,
|
|
1466
|
+
)
|
|
1467
|
+
self._refresh_env_list()
|
|
1468
|
+
return
|
|
1469
|
+
self._refresh_env_list()
|
|
1470
|
+
self._update_env_banner()
|
|
1471
|
+
self._scan_venvs()
|
|
1472
|
+
self._refresh_installed()
|
|
1473
|
+
self._refresh_codis_deps()
|
|
1474
|
+
|
|
1475
|
+
def _offer_adopt(self, dest: Path) -> None:
|
|
1476
|
+
"""Depois de criar um venv, oferece tornĆ”-lo o ambiente do Codis."""
|
|
1477
|
+
if venv_runtime.inspect_venv(dest) is None:
|
|
1478
|
+
return
|
|
1479
|
+
if messagebox.askyesno(
|
|
1480
|
+
_t("pip.env_adopt_title", "Usar como ambiente do Codis"),
|
|
1481
|
+
_t(
|
|
1482
|
+
"pip.env_adopt_ask",
|
|
1483
|
+
'Usar "{name}" como ambiente do Codis?\n\nO pip, o LSP, o executor de '
|
|
1484
|
+
"código e o terminal passam a usar o Python dele, e o Codis carrega os "
|
|
1485
|
+
"módulos instalados nele no lugar dos embutidos no executÔvel (após "
|
|
1486
|
+
"reiniciar).",
|
|
1487
|
+
name=dest.name,
|
|
1488
|
+
),
|
|
1489
|
+
parent=self,
|
|
1490
|
+
):
|
|
1491
|
+
self._adopt(dest)
|
|
1492
|
+
|
|
1493
|
+
def _build_env_banner(self, t: Any) -> None:
|
|
1494
|
+
"""Faixa (oculta por padrĆ£o) avisando que o ambiente pede reinĆcio ou Ć© incompatĆvel."""
|
|
1495
|
+
self._banner = tk.Frame(
|
|
1496
|
+
self, bg=t.sidebar_bg, highlightthickness=1, highlightbackground=t.accent
|
|
1497
|
+
)
|
|
1498
|
+
self._banner_lbl = tk.Label(
|
|
1499
|
+
self._banner,
|
|
1500
|
+
text="",
|
|
1501
|
+
bg=t.sidebar_bg,
|
|
1502
|
+
fg=t.fg,
|
|
1503
|
+
font=(FONT_UI, 8),
|
|
1504
|
+
anchor="w",
|
|
1505
|
+
justify="left",
|
|
1506
|
+
wraplength=720,
|
|
1507
|
+
)
|
|
1508
|
+
self._banner_lbl.pack(side="left", fill="x", expand=True, padx=10, pady=5)
|
|
1509
|
+
self._banner_btn = tk.Label(
|
|
1510
|
+
self._banner,
|
|
1511
|
+
text=_t("pip.env_restart_btn", "ā» Reiniciar agora"),
|
|
1512
|
+
bg=t.accent,
|
|
1513
|
+
fg="#FFF",
|
|
1514
|
+
font=(FONT_UI, 8, "bold"),
|
|
1515
|
+
padx=10,
|
|
1516
|
+
pady=3,
|
|
1517
|
+
cursor="hand2",
|
|
1518
|
+
)
|
|
1519
|
+
self._banner_btn.bind("<Button-1>", lambda _: self._request_restart())
|
|
1520
|
+
|
|
1521
|
+
def _update_env_banner(self) -> None:
|
|
1522
|
+
"""Atualiza a linha de status da aba Envs e a faixa de aviso."""
|
|
1523
|
+
st = venv_runtime.status()
|
|
1524
|
+
root = st["root"]
|
|
1525
|
+
if root:
|
|
1526
|
+
text = _t("pip.env_runtime", "Ambiente do Codis: {path}", path=root)
|
|
1527
|
+
if st["imports_from_venv"]:
|
|
1528
|
+
text += " · " + _t("pip.env_imports_venv", "módulos do venv")
|
|
1529
|
+
else:
|
|
1530
|
+
text = _t("pip.env_runtime_system", "Ambiente do Codis: Python do sistema")
|
|
1531
|
+
self._env_status_lbl.config(text=text)
|
|
1532
|
+
|
|
1533
|
+
message = ""
|
|
1534
|
+
info = venv_runtime.current()
|
|
1535
|
+
if st["needs_restart"]:
|
|
1536
|
+
message = _t(
|
|
1537
|
+
"pip.env_restart_needed",
|
|
1538
|
+
"Reinicie o Codis para carregar os módulos do ambiente escolhido.",
|
|
1539
|
+
)
|
|
1540
|
+
elif info is not None and not st["imports_from_venv"] and not info.abi_compatible:
|
|
1541
|
+
message = _t(
|
|
1542
|
+
"pip.env_incompatible",
|
|
1543
|
+
"O Python do venv ({venv}) difere do embutido no Codis ({bundled}): "
|
|
1544
|
+
"pip, LSP e terminal usam o venv, mas os módulos do próprio Codis "
|
|
1545
|
+
"continuam sendo os embutidos.",
|
|
1546
|
+
venv="{}.{}".format(*info.version) if info.version else "?",
|
|
1547
|
+
bundled=f"{sys.version_info[0]}.{sys.version_info[1]}",
|
|
1548
|
+
)
|
|
1549
|
+
self._banner_btn.pack_forget()
|
|
1550
|
+
if not message:
|
|
1551
|
+
self._banner.pack_forget()
|
|
1552
|
+
return
|
|
1553
|
+
self._banner_lbl.config(text=message)
|
|
1554
|
+
if st["needs_restart"]:
|
|
1555
|
+
self._banner_btn.pack(side="right", padx=8, pady=4)
|
|
1556
|
+
self._banner.pack(fill="x", before=self._nb)
|
|
1557
|
+
|
|
1558
|
+
def _request_restart(self) -> None:
|
|
1559
|
+
"""Pede o reinĆcio do Codis (pelo app) ou orienta a reabrir manualmente."""
|
|
1560
|
+
if self._on_restart is not None:
|
|
1561
|
+
self._on_restart()
|
|
1562
|
+
return
|
|
1563
|
+
messagebox.showinfo(
|
|
1564
|
+
_t("pip.env_adopt_title", "Usar como ambiente do Codis"),
|
|
1565
|
+
_t(
|
|
1566
|
+
"pip.env_restart_manual",
|
|
1567
|
+
"Feche e abra o Codis novamente para aplicar o ambiente escolhido.",
|
|
1568
|
+
),
|
|
1569
|
+
parent=self,
|
|
1570
|
+
)
|
|
1571
|
+
|
|
1572
|
+
def _create_venv(self) -> None:
|
|
1573
|
+
path = filedialog.askdirectory(
|
|
1574
|
+
title=_t("pip.venv_choose_dir", "Escolha onde criar o venv")
|
|
1575
|
+
)
|
|
1576
|
+
if not path:
|
|
1577
|
+
return
|
|
1578
|
+
name = _VenvNameDialog(self, self._tmgr).result
|
|
1579
|
+
if not name:
|
|
1580
|
+
return
|
|
1581
|
+
dest = Path(path) / name
|
|
1582
|
+
try:
|
|
1583
|
+
cmd = python_cmd("-m", "venv", str(dest))
|
|
1584
|
+
except NoPythonError as exc:
|
|
1585
|
+
self._python_missing(str(exc))
|
|
1586
|
+
return
|
|
1587
|
+
self._pip_op_raw(
|
|
1588
|
+
cmd,
|
|
1589
|
+
msg=f"Criando {dest}...",
|
|
1590
|
+
on_done=lambda: (self._scan_venvs(), self._offer_adopt(dest)),
|
|
1591
|
+
)
|
|
1592
|
+
|
|
1593
|
+
def _browse_venv(self) -> None:
|
|
1594
|
+
path = filedialog.askdirectory(
|
|
1595
|
+
title=_t("pip.venv_browse_dir", "Selecione pasta do venv")
|
|
1596
|
+
)
|
|
1597
|
+
if path and (Path(path) / "pyvenv.cfg").exists():
|
|
1598
|
+
venv_path = Path(path)
|
|
1599
|
+
if venv_path not in self._venvs:
|
|
1600
|
+
self._venvs.append(venv_path)
|
|
1601
|
+
self._render_venvs(self._venvs)
|
|
1602
|
+
|
|
1603
|
+
def _pip_op_raw(self, cmd: list[str], msg: str = "", on_done: Any = None) -> None:
|
|
1604
|
+
"""Executa qualquer comando de processo (não necessariamente pip)."""
|
|
1605
|
+
if self._busy:
|
|
1606
|
+
return
|
|
1607
|
+
self._busy = True
|
|
1608
|
+
q: queue.Queue[str | None] = queue.Queue()
|
|
1609
|
+
self._set_status(msg)
|
|
1610
|
+
self._log(f"\nā¶ {' '.join(cmd)}\n")
|
|
1611
|
+
|
|
1612
|
+
def _run() -> None:
|
|
1613
|
+
try:
|
|
1614
|
+
proc = subprocess.Popen(
|
|
1615
|
+
cmd,
|
|
1616
|
+
stdout=subprocess.PIPE,
|
|
1617
|
+
stderr=subprocess.STDOUT,
|
|
1618
|
+
text=True,
|
|
1619
|
+
bufsize=1,
|
|
1620
|
+
**_make_popen_kwargs(),
|
|
1621
|
+
)
|
|
1622
|
+
proc_registry.track(proc, "pip", "pip")
|
|
1623
|
+
for line in proc.stdout or []:
|
|
1624
|
+
q.put(line)
|
|
1625
|
+
proc.wait()
|
|
1626
|
+
except Exception as exc:
|
|
1627
|
+
q.put(f"[Erro] {exc}\n")
|
|
1628
|
+
q.put(None)
|
|
1629
|
+
|
|
1630
|
+
threading.Thread(target=_run, daemon=True).start()
|
|
1631
|
+
self._drain_queue(q, on_done=on_done)
|
|
1632
|
+
|
|
1633
|
+
|
|
1634
|
+
class _InfoWindow(tk.Toplevel):
|
|
1635
|
+
def __init__(self, parent: tk.Widget, tmgr: Any, name: str, info: str) -> None:
|
|
1636
|
+
super().__init__(parent)
|
|
1637
|
+
t = tmgr.theme
|
|
1638
|
+
self.title(f"š¦ {name}")
|
|
1639
|
+
self.geometry("540x400")
|
|
1640
|
+
self.config(bg=t.panel_bg)
|
|
1641
|
+
|
|
1642
|
+
hdr = tk.Frame(self, bg=t.activity_bg)
|
|
1643
|
+
hdr.pack(fill="x")
|
|
1644
|
+
tk.Label(
|
|
1645
|
+
hdr,
|
|
1646
|
+
text=f"š¦ {name}",
|
|
1647
|
+
bg=t.activity_bg,
|
|
1648
|
+
fg=t.accent,
|
|
1649
|
+
font=(FONT_UI, 12, "bold"),
|
|
1650
|
+
).pack(side="left", padx=12, pady=8)
|
|
1651
|
+
|
|
1652
|
+
txt = tk.Text(
|
|
1653
|
+
self,
|
|
1654
|
+
bg=t.editor_bg,
|
|
1655
|
+
fg=t.fg,
|
|
1656
|
+
font=(FONT_MONO, 9),
|
|
1657
|
+
relief="flat",
|
|
1658
|
+
bd=8,
|
|
1659
|
+
wrap="word",
|
|
1660
|
+
state="normal",
|
|
1661
|
+
)
|
|
1662
|
+
vsb = ttk.Scrollbar(self, orient="vertical", command=txt.yview)
|
|
1663
|
+
vsb.pack(side="right", fill="y")
|
|
1664
|
+
txt.config(yscrollcommand=vsb.set)
|
|
1665
|
+
txt.pack(fill="both", expand=True)
|
|
1666
|
+
txt.insert("end", info)
|
|
1667
|
+
txt.config(state="disabled")
|
|
1668
|
+
|
|
1669
|
+
btn_row = tk.Frame(self, bg=t.panel_bg)
|
|
1670
|
+
btn_row.pack(fill="x", padx=8, pady=6)
|
|
1671
|
+
pypi_b = tk.Label(
|
|
1672
|
+
btn_row,
|
|
1673
|
+
text=_t("pip.view_pypi", "š Ver no PyPI"),
|
|
1674
|
+
bg=t.accent,
|
|
1675
|
+
fg="#FFF",
|
|
1676
|
+
font=(FONT_UI, 9),
|
|
1677
|
+
padx=10,
|
|
1678
|
+
pady=4,
|
|
1679
|
+
cursor="hand2",
|
|
1680
|
+
)
|
|
1681
|
+
pypi_b.pack(side="left")
|
|
1682
|
+
pypi_b.bind(
|
|
1683
|
+
"<Button-1>",
|
|
1684
|
+
lambda _: webbrowser.open(
|
|
1685
|
+
f"https://pypi.org/project/{name}/"
|
|
1686
|
+
),
|
|
1687
|
+
)
|
|
1688
|
+
|
|
1689
|
+
|
|
1690
|
+
class _VenvNameDialog(tk.Toplevel):
|
|
1691
|
+
def __init__(self, parent: tk.Widget, tmgr: Any) -> None:
|
|
1692
|
+
super().__init__(parent)
|
|
1693
|
+
t = tmgr.theme
|
|
1694
|
+
self.title("Nome do ambiente virtual")
|
|
1695
|
+
self.config(bg=t.panel_bg)
|
|
1696
|
+
self.resizable(False, False)
|
|
1697
|
+
safe_grab_set(self)
|
|
1698
|
+
self.result: str | None = None
|
|
1699
|
+
|
|
1700
|
+
tk.Label(
|
|
1701
|
+
self,
|
|
1702
|
+
text=_t("pip.field_name", "Nome do pacote:"),
|
|
1703
|
+
bg=t.panel_bg,
|
|
1704
|
+
fg=t.fg,
|
|
1705
|
+
font=(FONT_UI, 10),
|
|
1706
|
+
).pack(padx=16, pady=(12, 4))
|
|
1707
|
+
self._var = tk.StringVar(value=".venv")
|
|
1708
|
+
ent = tk.Entry(
|
|
1709
|
+
self,
|
|
1710
|
+
textvariable=self._var,
|
|
1711
|
+
bg=t.editor_bg,
|
|
1712
|
+
fg=t.fg,
|
|
1713
|
+
insertbackground=t.cursor,
|
|
1714
|
+
relief="flat",
|
|
1715
|
+
bd=4,
|
|
1716
|
+
font=(FONT_UI, 10),
|
|
1717
|
+
width=20,
|
|
1718
|
+
)
|
|
1719
|
+
ent.pack(padx=16, pady=4)
|
|
1720
|
+
ent.bind("<Return>", lambda _: self._ok())
|
|
1721
|
+
|
|
1722
|
+
btn_row = tk.Frame(self, bg=t.panel_bg)
|
|
1723
|
+
btn_row.pack(padx=16, pady=10)
|
|
1724
|
+
ok_b = tk.Label(
|
|
1725
|
+
btn_row,
|
|
1726
|
+
text=_t("pip.create_venv", "Criar"),
|
|
1727
|
+
bg=t.accent,
|
|
1728
|
+
fg="#FFF",
|
|
1729
|
+
font=(FONT_UI, 9),
|
|
1730
|
+
padx=10,
|
|
1731
|
+
pady=4,
|
|
1732
|
+
cursor="hand2",
|
|
1733
|
+
)
|
|
1734
|
+
ok_b.pack(side="left", padx=4)
|
|
1735
|
+
ok_b.bind("<Button-1>", lambda _: self._ok())
|
|
1736
|
+
cancel_b = tk.Label(
|
|
1737
|
+
btn_row,
|
|
1738
|
+
text=_t("pip.btn_cancel", "Cancelar"),
|
|
1739
|
+
bg=t.sidebar_bg,
|
|
1740
|
+
fg=t.fg,
|
|
1741
|
+
font=(FONT_UI, 9),
|
|
1742
|
+
padx=10,
|
|
1743
|
+
pady=4,
|
|
1744
|
+
cursor="hand2",
|
|
1745
|
+
)
|
|
1746
|
+
cancel_b.pack(side="left", padx=4)
|
|
1747
|
+
cancel_b.bind("<Button-1>", lambda _: self.destroy())
|
|
1748
|
+
|
|
1749
|
+
self.update_idletasks()
|
|
1750
|
+
w, h = self.winfo_reqwidth(), self.winfo_reqheight()
|
|
1751
|
+
x = (self.winfo_screenwidth() - w) // 2
|
|
1752
|
+
y = (self.winfo_screenheight() - h) // 2
|
|
1753
|
+
self.geometry(f"{w}x{h}+{x}+{y}")
|
|
1754
|
+
self.wait_window()
|
|
1755
|
+
|
|
1756
|
+
def _ok(self) -> None:
|
|
1757
|
+
self.result = self._var.get().strip() or ".venv"
|
|
1758
|
+
self.destroy()
|