• ywangd

    This was caused by a bug in pip when it registers installed package, which is backed by RawConfigParser. The RawConfigParser has its own string interpolation rule which relies on the percentage sign.

    The bug has now been fixed and you can get it by selfupdate -f.

    posted in Pythonista read more
  • ywangd

    It cannot be done. greenlet does not work in Pythonista.

    greenlet is a pure C extension. It does not have any Python modules to be installed. That is what caused the error. C extension installation generally requires compiling C code which is impossible in Pythonista.

    posted in Pythonista read more
  • ywangd

    I tried to download setuptools and copy its pkg_resources sub-folder into site-packages. Then import pygal just worked. Maybe we can make this a standard process to install pkg_resources the first time stash pip is called.

    By the way, these are the commands I used to install pkg_resources.

    pip download setuptools
    tar -zxvf setuptools-25.1.0.tar.gz
    cp setuptools-25.1.0/pkg_resources site-packages/
    

    If there are any import errors afterwards, try restart Pythonista.

    posted in Pythonista read more
  • ywangd

    This is the use case that StaSh was initially created for. You can invoke your script from within StaSh similar to what you would do on a PC. You can redirect the output to a file as the follows:

    your_script.py > output.txt
    

    More details here https://github.com/ywangd/stash
    If you have previous experience with Linux shell, things should be quite familiar.

    posted in Pythonista read more
  • ywangd

    OmniClass is a stub class defined in StaSh pip. So maybe somehow it was getting in the way. Try restart Pythonista, i.e. swipe up to remove from task list.

    posted in Pythonista read more
  • ywangd

    Thanks a lot @dgelessus ! One cannot ask for a better answer!

    posted in Pythonista read more
  • ywangd

    @omz @dgelessus
    The following simple code using pythonapi works well in Python 2 but errors out in Python 3.

    import ctypes
    
    p3 = ctypes.pythonapi
    state = p3.PyGILState_Ensure()
    p3.PyRun_SimpleString('print(42)')
    p3.PyGILState_Release(state)
    

    The error is name 'p' is not defined which is very weird as it suggests that the API does not even parse the given string correctly. It somehow tries to get a variable named p which is in fact the first character of print.

    posted in Pythonista read more
  • ywangd

    Thanks @dgelessus
    The use of PyDLL worked for some initial tests!

    posted in Pythonista read more
  • ywangd

    @omz
    ctypes.pythonapi always points to the C API of Python 3 regardless of the default interpreter setting. Is there anyway to access the Python 2 version of pythonapi object? It would be even more fantastic if both of them can be accessed without switch interpreter setting.

    I also tried to manually load the library with

    ctypes.CDLL(os.path.join(os.path.dirname(sys.executable), 'Frameworks/PythonistaKit.framework/PythonistaKit'))
    

    Although it seems to load the Python 2 API and Py_GetVersion does show the version to be 2.7. But it is somehow not really usable. Many API calls working with the Python 3 API would not work or even simply crash the app.

    Any help is appreciated.

    posted in Pythonista read more
  • ywangd

    @korakot @plessner There was a bug in stash pip command that prevented it from parsing package names with uppercase letters. The bug is now fixed and you can get the updated version via selfupdate.

    posted in Pythonista read more
  • ywangd

    The install script works for both Python 2 and 3.

    The program itself runs in Python 2. However **you can still use Python 3 **as the default interpreter thanks to the shebang line for cross-interpreter calls.

    I did start porting the whole program to Python 3 a while back. However it is not completed due to some difficulties in porting some of the command scripts. Plus I am not not very happy of the overall porting. It was too aggressive and tried to use as much as Python 3 features as possible. I now think it is better to be more conservative. When omz adds the possibility to use both 2 and 3 in the same app. I basically discard the last porting. I'll probably try it again at some point. But for now, the program works fine in the new Pythonista.

    posted in Pythonista read more
  • ywangd

    I reported that for Pythonista 2 and it was fixed for the Pythonista 2 beta.

    But this time it is for Pythonista 3's python 2 interpreter. Sorry if this caused any confusion.

    posted in Pythonista read more
  • ywangd

    Beta 300014

    mmap module is available for Python 3 but NOT available in Python 2
    A fix will be appreciated. Thanks!

    posted in Pythonista read more
  • ywangd

    Thanks @JonB ! It was quite tricky to nail it down. I disabled the will_close call and it is now available in the dev branch. Hopefully this bug will be rectified soon. Thanks!

    posted in Pythonista read more
  • ywangd

    The monkey patch for sys.stdout is to allow running multiple commands of different output destinations without interfering each other. For an example, a HTTP server command can run at background with output redirected to a file, e.g. httpserver > logfile &. At the same time, a foreground client can talk to the server and send output to stash screen or Pythonista console. This is achieved by the custom stdout object checking the caller thread and acting accordingly.

    I admit the whole monkey patch is not ideal and hacky. So if @omz could provide an official mechanism to allow plugins for stdout etc, it would be fantastic.

    posted in Pythonista read more
  • ywangd

    @JonB said:

    I would suggest simply putting #!python2 at the start of launch_stash.py, to force stash to use the python2 interpreter. you can still keep your default interpreter as py3, but run stash using py2.

    This is probably a much better solution than porting the whole thing to py3?

    A follow-up question is : how can stash run a python script with the other Python interpreter (3.5) while stash itself is running in 2.7? Or vice versa, what if stash is running with Python 3.5 and the script has a python2 shebang?

    Currently stash just uses the exec function to run a python script which does not seem to honour the shebang. I'd guess this is possible with objc_util, but I am not sure where to start. Any tips are appreciated.

    Maybe @omz can provide a formal API to allow this kind of cross interpreter call?

    posted in Pythonista read more
  • ywangd

    @omz That did the trick! Thanks!

    posted in Pythonista read more
  • ywangd

    @Phuket2 You are right. The QuickType indeed causes chaos to the terminal. I always hide the QuickType bar. So I wasn't aware of this issue. After looking into it briefly, it does NOT seem possible to fix it. I guess you'll just have to hide it (swipe down on the bar).

    I tried to disable it programmatically but 2.0 app store version crashes on following method

    setAutocorrectionType_(1)
    

    It does work in both of the Betas. I'll have it added when a new official version is out.

    posted in Pythonista read more
  • ywangd

    Thanks @JonB for fixing this issue. I have also merged the pull request to the master branch. It can be retrieved with selfupdate -f.

    posted in Pythonista read more
  • ywangd

    @ihf
    @dgelessus is right. StaSh keeps all history in memory while running and write them to the history file when it quits.

    The history file is by default located under stash installation root, i.e. ~/Documents/site-packages/stash/.stash_history

    To delete the history, maybe you can try this:
    After you truncating the history file, try manually restart pythonista while stash is still running, i.e. double click home and swipe pythonista out of the task list. That will most likely end stash without it performing any tasks on exit.

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!