Skip to content

Commit 2549d26

Browse files
authored
Merge pull request #463 from mkb79/patch-Pythonista3.4
Patch stash to run with Pythonista 3.4 beta
2 parents 1606d11 + 9c5fac1 commit 2549d26

6 files changed

Lines changed: 53 additions & 26 deletions

File tree

.github/workflows/check-code-and-run-tests.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: Check code and run tests
2-
32
on:
43
push:
54
branches:
@@ -25,7 +24,7 @@ jobs:
2524
strategy:
2625
fail-fast: false
2726
matrix:
28-
python-version: ["2.7", "3.6"] # TODO: Add for Pythonista v3.4 -- , "3.10"]
27+
python-version: ["2.7", "3.6", "3.10"]
2928
steps:
3029
- name: Checkout
3130
uses: actions/checkout@v3

bin/wget.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
import sys
77
import argparse
8+
import ssl
89

910
from six.moves.urllib.request import urlopen
1011

12+
import certifi
13+
1114
try:
1215
import console
1316
except ImportError:
@@ -51,7 +54,8 @@ def main(args):
5154
try:
5255

5356
print('Opening: %s\n' % url)
54-
u = urlopen(url)
57+
context = ssl.create_default_context(cafile=certifi.where())
58+
u = urlopen(url, context=context)
5559

5660
meta = u.info()
5761
try:

setup.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,35 @@
4040

4141
# =================== SETUP ===================
4242

43-
from distutils.core import setup
44-
from setuptools import find_packages
43+
from setuptools import setup,find_packages
4544

46-
47-
TEST_REQUIREMENTS = [
48-
"pyparsing==2.0.1",
49-
"pytest>=3.6.0",
50-
"flake8>=3.5.0",
51-
"pycrypto==2.6",
52-
"requests==2.9.1",
53-
]
45+
if sys.version_info.major==2:
46+
INSTALL_REQUIREMENTS = [
47+
"rsa==4.5",
48+
"six", # required by StaSh
49+
"pyperclip", # required by libdist for copy/paste on PC
50+
"requests==2.9.1",
51+
"pycrypto==2.6",
52+
"pyte==0.8.1",
53+
]
54+
TEST_REQUIREMENTS = [
55+
"pyparsing==2.0.2",
56+
"pytest==4.6.11",
57+
"flake8>=3.7.9",
58+
]
59+
else:
60+
INSTALL_REQUIREMENTS=[
61+
"six", # required by StaSh
62+
"pyperclip", # required by libdist for copy/paste on PC
63+
"requests",
64+
"pycrypto",
65+
"pyte",
66+
],
67+
TEST_REQUIREMENTS = [
68+
"pyparsing",
69+
"pytest",
70+
"flake8>=3.7.9",
71+
]
5472

5573

5674
PARENT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -125,12 +143,7 @@ def get_stash_version(corepath):
125143
},
126144
scripts=[os.path.join(STASH_DIR, "launch_stash.py")],
127145
zip_safe=False,
128-
install_requires=[
129-
"six", # required by StaSh
130-
"pyperclip", # required by libdist for copy/paste on PC
131-
"requests",
132-
"pyte",
133-
],
146+
install_requires=INSTALL_REQUIREMENTS,
134147
extras_require={
135148
"testing": TEST_REQUIREMENTS,
136149
},

system/shcommon.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@
1717
if IN_PYTHONISTA:
1818
import plistlib
1919

20-
_properties = plistlib.readPlist(os.path.join(os.path.dirname(sys.executable), 'Info.plist'))
20+
info_plist_path = os.path.join(os.path.dirname(sys.executable), 'Info.plist')
21+
if hasattr(plistlib, 'readPlist'):
22+
_properties = plistlib.readPlist(info_plist_path)
23+
elif hasattr(plistlib, 'load'):
24+
with open(info_plist_path, 'rb') as info_plist:
25+
_properties = plistlib.load(info_plist)
26+
else:
27+
raise Exception('`plistlib` does not support reading a plist file.')
28+
2129
PYTHONISTA_VERSION = _properties['CFBundleShortVersionString']
2230
PYTHONISTA_VERSION_LONG = _properties['CFBundleVersion']
2331

system/shui/pythonista_ui.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,14 @@ def _vk_tapped(self, sender):
385385
# noinspection PyAttributeOutsideInit,PyUnusedLocal,PyPep8Naming
386386
class ShTerminal(ShBaseTerminal):
387387
"""
388-
This is a wrapper class of the actual TextView that subclass the SUITextView.
388+
This is a wrapper class of the actual TextView that subclass the SUITextView/SUITextView_PY3.
389389
The wrapper is used to encapsulate the objc calls so that it behaves more like
390390
a regular ui.TextView.
391391
"""
392392

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

395-
# Create the actual TextView by subclass SUITextView
395+
# Create the actual TextView by subclass SUITextView/SUITextView_PY3
396396
UIKeyCommand = ObjCClass('UIKeyCommand')
397397

398398
def kcDispatcher_(_self, _cmd, _sender):
@@ -490,7 +490,10 @@ def keyCommands(_self, _cmd):
490490
('UIKeyInputRightArrow', 0): parent.arrowRightAction,
491491
}
492492

493-
_ShTerminal = create_objc_class('_ShTerminal', ObjCClass('SUITextView'), [keyCommands, kcDispatcher_])
493+
try:
494+
_ShTerminal = create_objc_class('_ShTerminal', ObjCClass('SUITextView'), [keyCommands, kcDispatcher_])
495+
except ValueError:
496+
_ShTerminal = create_objc_class('_ShTerminal', ObjCClass('SUITextView_PY3'), [keyCommands, kcDispatcher_])
494497

495498
self.is_editing = False
496499

@@ -883,7 +886,7 @@ def _build_attributed_string(self, chars):
883886

884887
def render(self, no_wait=False):
885888
"""
886-
Render the screen buffer to the UITextView. Normally the rendering process
889+
Render the screen buffer to the SUITextView/SUITextView_PY3. Normally the rendering process
887890
is delayed to throttle the total attempts of rendering.
888891
:param bool no_wait: Immediately render the screen without delay.
889892
"""

tests/pip/test_pip.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def test_install_pypi_nobinary(self):
138138
@pytest.mark.xfail(sys.version_info < (3, 0), reason="rsa v4.7.1 binary is not available on Py2")
139139
def test_install_pypi_onlybinary(self):
140140
"""test 'pip install --only-binary :all: <pypi_package>'."""
141-
output = self.run_command("pip --verbose install --only-binary :all: rsa", exitcode=0)
141+
output = self.run_command("pip --verbose install --only-binary :all: rsa==4.5", exitcode=0)
142142
self.assertIn("Downloading package", output)
143143
self.assert_did_run_setup(output, allow_source=False)
144144
self.assertIn("Package installed: rsa", output)
@@ -156,7 +156,7 @@ def test_install_command(self):
156156
self.run_command("pyrsa-keygen --help", exitcode=127)
157157

158158
# 2. install
159-
output = self.run_command("pip --verbose install rsa", exitcode=0)
159+
output = self.run_command("pip --verbose install rsa==4.5", exitcode=0)
160160
self.assertIn("Downloading package", output)
161161
self.assert_did_run_setup(output)
162162
self.assertIn("Package installed: rsa", output)

0 commit comments

Comments
 (0)