Skip to content

Commit fd3b384

Browse files
author
Ong Yong Xin
authored
Merge pull request ywangd#2 from ywangd/dev
Flush commits from ywangd to fork
2 parents e83bf3f + 0ccd3b2 commit fd3b384

File tree

10 files changed

+288
-50
lines changed

10 files changed

+288
-50
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
* colored error messages
88
* history is now per command
99
* `pip` now supports extras
10+
* `pip` will now show error messages for known incompatible packages
11+
* `wget` will now show an progress bar
12+
* support for unicode symbols im prompt
13+
* various bugfixes and minor improvements
1014

1115
### Version 0.7.0 - 2018-05-04
1216
* New Features

bin/pip.py

Lines changed: 146 additions & 49 deletions
Large diffs are not rendered by default.

bin/totd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def main(args):
1515

1616
ns = ap.parse_args(args)
1717

18-
filename = os.path.join(os.environ['STASH_ROOT'], '.stash_tips')
18+
filename = os.path.join(os.environ['STASH_ROOT'], 'data', 'stash_tips.json')
1919
if not os.path.exists(filename):
2020
return 1
2121

data/pip_blacklist.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"reasons": {
3+
"C": "This package uses C-Code, which can not be compiled by StaSh.",
4+
"unknown": "Reason unknown.",
5+
"is_stash": "The name of the package conflicts with StaSh.",
6+
"is_pip": "StaSh uses a custom version of PIP. Installing the 'pip' package would likely break StaSh.",
7+
"lowlevel_os": "This package uses (relatively) low-level OS functions, which can not be used with Pythonista.",
8+
"processes": "This package requires process interaction, which is not possible on iOS",
9+
"bundled": "This package is already bundled with Pythonista",
10+
"incompatible_dependency": "This package has one or more dependencies which are incompatible with Pythonista."
11+
},
12+
"blacklist": {
13+
"stash": ["is_stash", true, null],
14+
"pip": ["is_pip", true, null],
15+
"selenium": ["processes", true, null],
16+
"matplotlib": ["bundled", false, null],
17+
"mypy": ["C", true, null],
18+
"eventlet": ["C", true, null],
19+
"scipy": ["C", true, null],
20+
"tensorflow": ["C", true, null],
21+
"pyobjc": ["C", true, null],
22+
"pyttsx3": ["incompatible_dependency", true, null]
23+
}
24+
}
File renamed without changes.

docs/pip_blacklist.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#PIP blacklist
2+
-----------------------
3+
Starting with version 0.7.5, StaSh pip includes a blacklist.
4+
5+
6+
It indicates whether a package should not be installed and what reasons
7+
should be given.
8+
9+
10+
## Motivation
11+
12+
The reason for this blacklist is the high number of issues regarding
13+
installation problems of known incompatible packages. I hope that by
14+
slowly adding packages to the blacklist we can reduce the amount of
15+
these issues.
16+
17+
18+
The blacklist was initially discussed in issue #376.
19+
20+
21+
## Details
22+
This blacklist is stored as a JSON file at `$STASH_ROOT/data/pip_blacklist.json`.
23+
It is a dict with two top-level keys:
24+
25+
26+
**`reasons`** Is a dict mapping a reasonID (str) to a message (str).
27+
It is used to reduce redundancy of error messages.
28+
29+
30+
**`blacklist`** Is a dict mapping packagename (str) to details (list).
31+
Every package mentioned in a key of the dict is considered blacklisted.
32+
33+
The first (`i=0`) element of the list is the reasonID (str). Use the `reasons` toplevel
34+
key to determine the actual reason.
35+
36+
The second (`i=1`) element of the list is a bool indicating whether this
37+
blacklisting is fatal. If true, it is considered fatal. This means that
38+
`pip` should abort the installation. Otherwise it is considered nonfatal.
39+
This means that `pip` should skip the installation, but continue the install.
40+
This is useful if the package can not be installed, but Pythonista already
41+
bundles the module.
42+
43+
The third (`i=2`) is either `null`/`None` or a string. If it is a string
44+
and the package is marked non-fatal, use this string as the packagename instead.
45+
In this case, requested extras and version specifier are discarded.

lib/libversion.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ def parse_requirement(requirement):
328328
splitted = specs_s.split(",")
329329
specs = []
330330
for vs in splitted:
331+
if vs == "":
332+
# for some weird reasons, sometimes a trailing ',' is
333+
# included in the requirement list.
334+
continue
331335
cmp_end = re.search(version_cmp, vs).end()
332336
c, v = vs[:cmp_end], vs[cmp_end:]
333337
specs.append((c, v))
File renamed without changes.

tests/misc/test_totd.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
Tests for the 'totd' command.
3+
"""
4+
from stash.tests.stashtest import StashTestCase
5+
6+
7+
class TotdTests(StashTestCase):
8+
"""
9+
Tests for the 'totd' command.
10+
"""
11+
12+
def test_help(self):
13+
"""
14+
Test 'totd --help'.
15+
"""
16+
output = self.run_command("totd --help", exitcode=0)
17+
self.assertIn("totd", output)
18+
self.assertIn("-h", output)
19+
self.assertIn("--help", output)
20+
self.assertIn("-n", output)
21+
self.assertIn("--count", output)
22+
23+
def test_count(self):
24+
"""
25+
Test 'totd --count'.
26+
"""
27+
output = self.run_command("totd --count", exitcode=0).replace("\n", "")
28+
# ensure that the string is correct
29+
self.assertTrue(output.startswith("Total available tips: "))
30+
# ensure that number of tips is not zero
31+
self.assertFalse(output.endswith(" "))
32+
33+
def test_simple(self):
34+
"""
35+
Test a simple 'totd' execution.
36+
Ensure that different totds are returned.
37+
"""
38+
known = []
39+
n_unique = 0
40+
for i in range(100):
41+
output = self.run_command("totd", exitcode=0).replace("\n", "")
42+
if output not in known:
43+
known.append(output)
44+
n_unique += 1
45+
self.assertGreater(n_unique, 3)
46+

tests/pip/test_pip.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,21 @@ def test_uninstall(self):
286286
except ImportError as e:
287287
# expected failure
288288
pass
289+
290+
def test_blacklist_fatal(self):
291+
"""test 'pip install <blacklisted-fatal-package>'."""
292+
output = self.run_command("pip --verbose install pip", exitcode=1)
293+
self.assertIn("StaSh uses a custom version of PIP", output)
294+
self.assertIn("PackageBlacklisted", output)
295+
self.assertNotIn("Package installed: pip", output)
296+
297+
def test_blacklist_nonfatal(self):
298+
"""test 'pip install <blacklisted-nonfatal-package>'."""
299+
output = self.run_command("pip --verbose install matplotlib", exitcode=0)
300+
self.assertIn("Warning: package 'matplotlib' is blacklisted, but marked as non-fatal.", output)
301+
self.assertIn("This package is already bundled with Pythonista", output)
302+
self.assertNotIn("PackageBlacklisted", output)
303+
self.assertNotIn("Package installed: matplotlib", output)
304+
305+
# TODO: add test for blacklist with alternative.
306+

0 commit comments

Comments
 (0)