1
0

f18: pythonista3 現状 + stash 起動エラー暫定回避

Last updated at Posted at 2024-08-23

.

[ 01. pythonista3 の現状について ]

2023/05 に pythonista3 v3.4 がリリースされて以降、
現在、暗雲が立ち込めている感じです

この pythonista3 v3.4 は、
python 3.10 のサポートがされているのですが、
バグが多く、フォーラムでは、
報告や改善要望などがあがっておりました

わたくしもいくつか報告をさせていただいていたのですが、
2024/06 にフォーラムにアクセスしたところ、
アクセス不可の状態になっております

Pythonista Forum
https://forum.omz-software.com/

心配するユーザーの方々も動向を見守ってます

Is Pythonista (Python for iOS/iPadOS) no longer with active development and support?
https://www.reddit.com/r/Python/comments/1ca9x6h/is_pythonista_python_for_iosipados_no_longer_with/?rdt=41501

issue ページは存在し、

omz/Pythonista-Issues
https://github.com/omz/Pythonista-Issues/

アプリの配信もまだ止まってはいないのですが、
今後の継続を祈るばかりです

という状況ではありますが、stash ネタに入ります


[ 02. キッチン ]

・iphone 6s plus / ios 15.8

・pythonista3 v3.4 (python 3.10.4)

・stash v0.7.5


[ 03. stash 起動エラー暫定回避 ]

先日、旧デバイスに 新規に pythonista3 および、
stash (get_stash.py) をセットアップ後、
stash (launch_stash.py) 実行で起動エラーとなりました

ネット上にも類似エラー事例が載っておりました

2023-05-04
pythonsita3.4でStashが起動できなくなった人へ
https://yoichi-41.hatenablog.com/entry/20230504Pythonista34

-> 実行エラーが表示され、plistlib に問題があり、
 /stash/lib/ のライブラリを修正するケース

ただ、今回の環境で起きた現象としては、
stash (launch_stash.py) 実行で
pythonista3 のアプリ自体が強制終了となりました
(環境依存かもしれません)

launch_stash.py のデバッグが必要かなと思ったのですが、
以下の方法で暫定回避をおこないました

2023-05-08
Pythonista crash during start launch_stash.py #496
https://github.com/ywangd/stash/issues/496

簡単にお伝えしますと、
launch_stash.py の一部書き換えだけで OK です

(01) import ui の追加

(02) _stash.launch(ns.command) をコメントし、

@ui.in_background
def launch(*args):
_stash.launch(*args)
launch(ns.command)

に置き換え

launch_stash_2.py

# coding: utf-8
"""
Launch StaSh in a more flexible and reliable way.
"""
import sys
import argparse
import ui

module_names = (
    'stash',
    'system.shcommon',
    'system.shstreams',
    'system.shscreens',
    'system.shui',
    'system.shui.base',
    'system.shio',
    'system.shiowrapper',
    'system.shparsers',
    'system.shruntime',
    'system.shthreads',
    'system.shuseractionproxy',
    'system.shhistory',
)

# Attempt to reload modules when startup, does not seem to work
if 'stash.stash' in sys.modules:
    for name in module_names:
        sys.modules.pop('stash.' + name)
from stash import stash

ap = argparse.ArgumentParser()
ap.add_argument('--no-cfgfile', action='store_true', help='do not load external config files')
ap.add_argument('--no-rcfile', action='store_true', help='do not load external resource file')
ap.add_argument('--no-historyfile', action='store_true', help='do not load history file from last session')
ap.add_argument(
    '--log-level',
    choices=['DEBUG',
             'INFO',
             'WARN',
             'ERROR',
             'CRITICAL'],
    default='INFO',
    help='the logging level'
)
ap.add_argument('--log-file', help='the file to send logging messages')
ap.add_argument('--debug-switch', default='', help='a comma separate list to turn on debug switch for components')
ap.add_argument('-c', '--command', default=None, dest='command', help='command to run')
ap.add_argument('args',  # the editor shortcuts may pass additional arguments
                nargs='*',
                help='additional arguments (ignored)')
ns = ap.parse_args()

log_setting = {
    'level': ns.log_level,
    'file': ns.log_file,
}

if ns.debug_switch == '':
    debug = (
        # stash._DEBUG_STREAM,
        # stash._DEBUG_RENDERER,
        # stash._DEBUG_MAIN_SCREEN,
        # stash._DEBUG_MINI_BUFFER,
        # stash._DEBUG_IO,
        # stash._DEBUG_UI,
        # stash._DEBUG_TERMINAL,
        # stash._DEBUG_TV_DELEGATE,
        # stash._DEBUG_RUNTIME,
        # stash._DEBUG_PARSER,
        # stash._DEBUG_EXPANDER,
        # stash._DEBUG_COMPLETER,
    )
elif ns.debug_switch == "all":
    debug = []
    for key in dir(stash):
        if key.startswith("_DEBUG_"):
            value = getattr(stash, key, None)
            if value is not None:
                debug.append(value)
else:
    debug = []
    for ds in ns.debug_switch.split(','):
        ds = getattr(stash, '_DEBUG_{}'.format(ds.upper()), None)
        if ds is not None:
            debug.append(ds)

if ns.command:
    # tell StaSh not to run any command if command is passed
    # (we will call the command manually later)
    ctp = False
else:
    # tell StaSh to run the default command (totd.py)
    ctp = None

_stash = stash.StaSh(
    debug=debug,
    log_setting=log_setting,
    no_cfgfile=ns.no_cfgfile,
    no_rcfile=ns.no_rcfile,
    no_historyfile=ns.no_historyfile,
    command=ctp,
)

# _stash.launch(ns.command)
@ui.in_background
def launch(*args):
    _stash.launch(*args)
launch(ns.command)

if ns.command is not None:
    # TODO: _stash.launch() may block, which prevents this from being executed
    _stash(ns.command, add_to_history=False, persistent_level=0)

これで pythonista3 のアプリ自体が強制終了とならずに、
stash のコンソールが起動された状態になりました

この方法は pip コマンドを使えるようにするための
ひとまずの暫定回避方法になります

ただ、今回のエラー以前に、
pythonista3 上で stash を使用すると、
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Warning: you are running StaSh in python3.
Some commands may not work
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
との記載があるように、
pip も オプションが利用できなかったり、
対応ライブラリが少ないなど、完全な pip 互換として
利用できるわけではありませんのでご注意ください

試しておりませんが、こういうものもあるそうです

Pythonista3でstashのpipじゃない本物のpipを使いたい人向け
https://github.com/CrossDarkrix/Pythonista3_pip_Configration_Tool

ちなみに、stash 実行時、pip 実行時など、
以下の結果コードが赤字で
ちょこちょこ出力される場合がありますが、
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
stash: ^C
KeyboardInterrupt: Exit: (終了コード)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
pip コマンド実行には影響がないため、
暫定回避という意味では無視しても大丈夫です


[ 04. デザート ]

pythonista は pip (stash) の一部制限はあるものの、
iOS の python 統合環境としては秀逸で、
open in から Run Pythonista Script として
お手軽にアクセスできたりと、iOS との親和性が高いのですが、
今後は、pyto IDE など、代替え環境も
模索していく必要があるかもしれませんね


.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0