Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch stash to run with Pythonista 3.4 beta #463

Merged
merged 14 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/check-code-and-run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Check code and run tests

on:
push:
branches:
Expand All @@ -25,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["2.7", "3.6"] # TODO: Add for Pythonista v3.4 -- , "3.10"]
python-version: ["2.7", "3.6"] # TODO: Add for Pythonista v3.4 -- , "3.10"
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
6 changes: 5 additions & 1 deletion bin/wget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

import sys
import argparse
import ssl

from six.moves.urllib.request import urlopen

import certifi

try:
import console
except ImportError:
Expand Down Expand Up @@ -51,7 +54,8 @@ def main(args):
try:

print('Opening: %s\n' % url)
u = urlopen(url)
context = ssl.create_default_context(cafile=certifi.where())
u = urlopen(url, context=context)

meta = u.info()
try:
Expand Down
45 changes: 29 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,35 @@

# =================== SETUP ===================

from distutils.core import setup
from setuptools import find_packages
from setuptools import setup,find_packages


TEST_REQUIREMENTS = [
"pyparsing==2.0.1",
"pytest>=3.6.0",
"flake8>=3.5.0",
"pycrypto==2.6",
"requests==2.9.1",
]
if sys.version_info.major==2:
INSTALL_REQUIREMENTS = [
"rsa==4.5",
"six", # required by StaSh
"pyperclip", # required by libdist for copy/paste on PC
"requests==2.9.1",
"pycrypto==2.6",
"pyte==0.8.1",
]
TEST_REQUIREMENTS = [
"pyparsing==2.0.2",
"pytest==4.6.11",
"flake8>=3.7.9",
]
else:
INSTALL_REQUIREMENTS=[
"six", # required by StaSh
"pyperclip", # required by libdist for copy/paste on PC
"requests",
"pycrypto",
"pyte",
],
TEST_REQUIREMENTS = [
"pyparsing",
"pytest",
"flake8>=3.7.9",
]


PARENT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -125,12 +143,7 @@ def get_stash_version(corepath):
},
scripts=[os.path.join(STASH_DIR, "launch_stash.py")],
zip_safe=False,
install_requires=[
"six", # required by StaSh
"pyperclip", # required by libdist for copy/paste on PC
"requests",
"pyte",
],
install_requires=INSTALL_REQUIREMENTS,
extras_require={
"testing": TEST_REQUIREMENTS,
},
Expand Down
10 changes: 9 additions & 1 deletion system/shcommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
if IN_PYTHONISTA:
import plistlib

_properties = plistlib.readPlist(os.path.join(os.path.dirname(sys.executable), 'Info.plist'))
info_plist_path = os.path.join(os.path.dirname(sys.executable), 'Info.plist')
if hasattr(plistlib, 'readPlist'):
_properties = plistlib.readPlist(info_plist_path)
elif hasattr(plistlib, 'load'):
with open(info_plist_path, 'rb') as info_plist:
_properties = plistlib.load(info_plist)
else:
raise Exception('`plistlib` does not support reading a plist file.')

PYTHONISTA_VERSION = _properties['CFBundleShortVersionString']
PYTHONISTA_VERSION_LONG = _properties['CFBundleVersion']

Expand Down
11 changes: 7 additions & 4 deletions system/shui/pythonista_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,14 @@ def _vk_tapped(self, sender):
# noinspection PyAttributeOutsideInit,PyUnusedLocal,PyPep8Naming
class ShTerminal(ShBaseTerminal):
"""
This is a wrapper class of the actual TextView that subclass the SUITextView.
This is a wrapper class of the actual TextView that subclass the SUITextView/SUITextView_PY3.
The wrapper is used to encapsulate the objc calls so that it behaves more like
a regular ui.TextView.
"""

def __init__(self, stash, parent, superview, width, height):

# Create the actual TextView by subclass SUITextView
# Create the actual TextView by subclass SUITextView/SUITextView_PY3
UIKeyCommand = ObjCClass('UIKeyCommand')

def kcDispatcher_(_self, _cmd, _sender):
Expand Down Expand Up @@ -490,7 +490,10 @@ def keyCommands(_self, _cmd):
('UIKeyInputRightArrow', 0): parent.arrowRightAction,
}

_ShTerminal = create_objc_class('_ShTerminal', ObjCClass('SUITextView'), [keyCommands, kcDispatcher_])
try:
_ShTerminal = create_objc_class('_ShTerminal', ObjCClass('SUITextView'), [keyCommands, kcDispatcher_])
except ValueError:
_ShTerminal = create_objc_class('_ShTerminal', ObjCClass('SUITextView_PY3'), [keyCommands, kcDispatcher_])

self.is_editing = False

Expand Down Expand Up @@ -883,7 +886,7 @@ def _build_attributed_string(self, chars):

def render(self, no_wait=False):
"""
Render the screen buffer to the UITextView. Normally the rendering process
Render the screen buffer to the SUITextView/SUITextView_PY3. Normally the rendering process
is delayed to throttle the total attempts of rendering.
:param bool no_wait: Immediately render the screen without delay.
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/pip/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_install_pypi_nobinary(self):
@pytest.mark.xfail(sys.version_info < (3, 0), reason="rsa v4.7.1 binary is not available on Py2")
def test_install_pypi_onlybinary(self):
"""test 'pip install --only-binary :all: <pypi_package>'."""
output = self.run_command("pip --verbose install --only-binary :all: rsa", exitcode=0)
output = self.run_command("pip --verbose install --only-binary :all: rsa==4.5", exitcode=0)
self.assertIn("Downloading package", output)
self.assert_did_run_setup(output, allow_source=False)
self.assertIn("Package installed: rsa", output)
Expand All @@ -156,7 +156,7 @@ def test_install_command(self):
self.run_command("pyrsa-keygen --help", exitcode=127)

# 2. install
output = self.run_command("pip --verbose install rsa", exitcode=0)
output = self.run_command("pip --verbose install rsa==4.5", exitcode=0)
self.assertIn("Downloading package", output)
self.assert_did_run_setup(output)
self.assertIn("Package installed: rsa", output)
Expand Down