|
618 | 618 | { |
619 | 619 | "data": { |
620 | 620 | "text/plain": [ |
621 | | - "['c', 'f', 'e', 'g', 'h', 'b', 'd', 'a']" |
| 621 | + "['c', 'h', 'f', 'a', 'g', 'd', 'b', 'e']" |
622 | 622 | ] |
623 | 623 | }, |
624 | 624 | "execution_count": null, |
|
1045 | 1045 | "outputs": [], |
1046 | 1046 | "source": [ |
1047 | 1047 | "#export\n", |
1048 | | - "def run(cmd, *rest, ignore_ex=False, as_bytes=False, stderr=False):\n", |
| 1048 | + "def run(cmd, *rest, same_in_win=False, ignore_ex=False, as_bytes=False, stderr=False):\n", |
1049 | 1049 | " \"Pass `cmd` (splitting with `shlex` if string) to `subprocess.run`; return `stdout`; raise `IOError` if fails\"\n", |
1050 | | - " if rest: cmd = (cmd,)+rest\n", |
1051 | | - " elif isinstance(cmd,str): cmd = shlex.split(cmd)\n", |
| 1050 | + " # Even the command is same on Windows, we have to add `cmd /c `\"\n", |
| 1051 | + " import logging\n", |
| 1052 | + " if rest: \n", |
| 1053 | + " if sys.platform == 'win32' and same_in_win: \n", |
| 1054 | + " cmd = ('cmd', '/c', cmd, *rest)\n", |
| 1055 | + " else:\n", |
| 1056 | + " cmd = (cmd,)+rest\n", |
| 1057 | + " elif isinstance(cmd, str):\n", |
| 1058 | + " if sys.platform == 'win32' and same_in_win: cmd = 'cmd /c ' + cmd\n", |
| 1059 | + " cmd = shlex.split(cmd)\n", |
| 1060 | + " elif isinstance(cmd, list):\n", |
| 1061 | + " if sys.platform == 'win32' and same_in_win: cmd = ['cmd', '/c'] + cmd\n", |
1052 | 1062 | " res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n", |
1053 | 1063 | " stdout = res.stdout\n", |
1054 | 1064 | " if stderr and res.stderr: stdout += b' ;; ' + res.stderr\n", |
|
1069 | 1079 | "cell_type": "code", |
1070 | 1080 | "execution_count": null, |
1071 | 1081 | "metadata": {}, |
1072 | | - "outputs": [], |
| 1082 | + "outputs": [ |
| 1083 | + { |
| 1084 | + "name": "stdout", |
| 1085 | + "output_type": "stream", |
| 1086 | + "text": [ |
| 1087 | + "popenargs (['cmd', '/c', 'echo'],)\n", |
| 1088 | + "kwargs {'stdout': -1, 'stderr': -1}\n", |
| 1089 | + "popenargs (('cmd', '/c', 'pip', '--version'),)\n", |
| 1090 | + "kwargs {'stdout': -1, 'stderr': -1}\n", |
| 1091 | + "popenargs (['cmd', '/c', 'pip', '--version'],)\n", |
| 1092 | + "kwargs {'stdout': -1, 'stderr': -1}\n" |
| 1093 | + ] |
| 1094 | + }, |
| 1095 | + { |
| 1096 | + "data": { |
| 1097 | + "text/plain": [ |
| 1098 | + "'pip 21.0.1 from D:\\\\programs\\\\envs\\\\nbdev\\\\lib\\\\site-packages\\\\pip (python 3.8)'" |
| 1099 | + ] |
| 1100 | + }, |
| 1101 | + "execution_count": null, |
| 1102 | + "metadata": {}, |
| 1103 | + "output_type": "execute_result" |
| 1104 | + } |
| 1105 | + ], |
| 1106 | + "source": [ |
| 1107 | + "run('echo', same_in_win=True)\n", |
| 1108 | + "run('pip', '--version', same_in_win=True)\n", |
| 1109 | + "run(['pip', '--version'], same_in_win=True)" |
| 1110 | + ] |
| 1111 | + }, |
| 1112 | + { |
| 1113 | + "cell_type": "code", |
| 1114 | + "execution_count": null, |
| 1115 | + "metadata": {}, |
| 1116 | + "outputs": [ |
| 1117 | + { |
| 1118 | + "name": "stdout", |
| 1119 | + "output_type": "stream", |
| 1120 | + "text": [ |
| 1121 | + "popenargs (['cmd', '/c', 'dir', '/p'],)\n", |
| 1122 | + "kwargs {'stdout': -1, 'stderr': -1}\n", |
| 1123 | + "popenargs (['cmd', '/c', 'dir', '/p'],)\n", |
| 1124 | + "kwargs {'stdout': -1, 'stderr': -1}\n", |
| 1125 | + "popenargs (('cmd', '/c', 'dir', '/p'),)\n", |
| 1126 | + "kwargs {'stdout': -1, 'stderr': -1}\n" |
| 1127 | + ] |
| 1128 | + } |
| 1129 | + ], |
1073 | 1130 | "source": [ |
1074 | 1131 | "if sys.platform == 'win32':\n", |
1075 | 1132 | " assert 'ipynb' in run('cmd /c dir /p')\n", |
|
1092 | 1149 | "cell_type": "code", |
1093 | 1150 | "execution_count": null, |
1094 | 1151 | "metadata": {}, |
1095 | | - "outputs": [], |
| 1152 | + "outputs": [ |
| 1153 | + { |
| 1154 | + "name": "stdout", |
| 1155 | + "output_type": "stream", |
| 1156 | + "text": [ |
| 1157 | + "popenargs (['cmd', '/c', 'findstr', 'asdfds', '00_test.ipynb'],)\n", |
| 1158 | + "kwargs {'stdout': -1, 'stderr': -1}\n" |
| 1159 | + ] |
| 1160 | + } |
| 1161 | + ], |
1096 | 1162 | "source": [ |
1097 | 1163 | "if sys.platform == 'win32':\n", |
1098 | 1164 | " test_eq(run('cmd /c findstr asdfds 00_test.ipynb', ignore_ex=True)[0], 1)\n", |
|
1111 | 1177 | "cell_type": "code", |
1112 | 1178 | "execution_count": null, |
1113 | 1179 | "metadata": {}, |
1114 | | - "outputs": [], |
| 1180 | + "outputs": [ |
| 1181 | + { |
| 1182 | + "name": "stdout", |
| 1183 | + "output_type": "stream", |
| 1184 | + "text": [ |
| 1185 | + "popenargs (['cmd', '/c', 'echo', 'hi'],)\n", |
| 1186 | + "kwargs {'stdout': -1, 'stderr': -1}\n" |
| 1187 | + ] |
| 1188 | + } |
| 1189 | + ], |
1115 | 1190 | "source": [ |
1116 | 1191 | "if sys.platform == 'win32':\n", |
1117 | | - " # why I ignore as_types, because every time nbdev_clean_nbs will update \\n to \\nn\n", |
| 1192 | + " # why I ignore as_types, because every time nbdev_clean_nbs will update \\n to \\r\\n\n", |
1118 | 1193 | " test_eq(run('cmd /c echo hi'), 'hi')\n", |
1119 | 1194 | "else:\n", |
1120 | 1195 | " test_eq(run('echo hi', as_bytes=True), b'hi\\n')" |
|
1298 | 1373 | { |
1299 | 1374 | "data": { |
1300 | 1375 | "text/plain": [ |
1301 | | - "(Path('../fastcore/__init__.py'), Path('01_basics.ipynb'))" |
| 1376 | + "(Path('../fastcore/all.py'), Path('00_test.ipynb'))" |
1302 | 1377 | ] |
1303 | 1378 | }, |
1304 | 1379 | "execution_count": null, |
|
1575 | 1650 | "name": "stdout", |
1576 | 1651 | "output_type": "stream", |
1577 | 1652 | "text": [ |
1578 | | - "Num Events: 8, Freq/sec: 423.0\n", |
1579 | | - "Most recent: ▂▂▁▁▇ 318.5 319.0 266.9 275.6 427.7\n" |
| 1653 | + "Num Events: 1, Freq/sec: 62.9\n", |
| 1654 | + "Most recent: ▃▇▃▁▃ 31.3 31.9 31.4 30.8 31.3\n" |
1580 | 1655 | ] |
1581 | 1656 | } |
1582 | 1657 | ], |
|
1725 | 1800 | "name": "stdout", |
1726 | 1801 | "output_type": "stream", |
1727 | 1802 | "text": [ |
1728 | | - "2000-01-01 12:00:00 UTC is 2000-01-01 12:00:00+00:00 local time\n" |
| 1803 | + "2000-01-01 12:00:00 UTC is 2000-01-01 04:00:00-08:00 local time\n" |
1729 | 1804 | ] |
1730 | 1805 | } |
1731 | 1806 | ], |
|
1755 | 1830 | "name": "stdout", |
1756 | 1831 | "output_type": "stream", |
1757 | 1832 | "text": [ |
1758 | | - "2000-01-01 12:00:00 local is 2000-01-01 12:00:00+00:00 UTC time\n" |
| 1833 | + "2000-01-01 12:00:00 local is 2000-01-01 20:00:00+00:00 UTC time\n" |
1759 | 1834 | ] |
1760 | 1835 | } |
1761 | 1836 | ], |
|
0 commit comments