Show More
@@ -78,7 +78,6 from IPython.kernel.zmq.session import Session | |||||
78 | from IPython.nbformat.sign import NotebookNotary |
|
78 | from IPython.nbformat.sign import NotebookNotary | |
79 | from IPython.utils.importstring import import_item |
|
79 | from IPython.utils.importstring import import_item | |
80 | from IPython.utils import submodule |
|
80 | from IPython.utils import submodule | |
81 | from IPython.utils.process import check_pid |
|
|||
82 | from IPython.utils.traitlets import ( |
|
81 | from IPython.utils.traitlets import ( | |
83 | Dict, Unicode, Integer, List, Bool, Bytes, Instance, |
|
82 | Dict, Unicode, Integer, List, Bool, Bytes, Instance, | |
84 | TraitError, Type, |
|
83 | TraitError, Type, | |
@@ -88,7 +87,7 from IPython.utils.path import filefind, get_ipython_dir | |||||
88 | from IPython.utils.sysinfo import get_sys_info |
|
87 | from IPython.utils.sysinfo import get_sys_info | |
89 |
|
88 | |||
90 | from .nbextensions import SYSTEM_NBEXTENSIONS_DIRS |
|
89 | from .nbextensions import SYSTEM_NBEXTENSIONS_DIRS | |
91 | from .utils import url_path_join |
|
90 | from .utils import url_path_join, check_pid | |
92 |
|
91 | |||
93 | #----------------------------------------------------------------------------- |
|
92 | #----------------------------------------------------------------------------- | |
94 | # Module globals |
|
93 | # Module globals |
@@ -5,8 +5,10 | |||||
5 |
|
5 | |||
6 | from __future__ import print_function |
|
6 | from __future__ import print_function | |
7 |
|
7 | |||
|
8 | import errno | |||
8 | import os |
|
9 | import os | |
9 | import stat |
|
10 | import stat | |
|
11 | import sys | |||
10 |
|
12 | |||
11 | try: |
|
13 | try: | |
12 | from urllib.parse import quote, unquote |
|
14 | from urllib.parse import quote, unquote | |
@@ -139,3 +141,30 def to_api_path(os_path, root=''): | |||||
139 | path = '/'.join(parts) |
|
141 | path = '/'.join(parts) | |
140 | return path |
|
142 | return path | |
141 |
|
143 | |||
|
144 | ||||
|
145 | # Copy of IPython.utils.process.check_pid: | |||
|
146 | ||||
|
147 | def _check_pid_win32(pid): | |||
|
148 | import ctypes | |||
|
149 | # OpenProcess returns 0 if no such process (of ours) exists | |||
|
150 | # positive int otherwise | |||
|
151 | return bool(ctypes.windll.kernel32.OpenProcess(1,0,pid)) | |||
|
152 | ||||
|
153 | def _check_pid_posix(pid): | |||
|
154 | """Copy of IPython.utils.pro""" | |||
|
155 | try: | |||
|
156 | os.kill(pid, 0) | |||
|
157 | except OSError as err: | |||
|
158 | if err.errno == errno.ESRCH: | |||
|
159 | return False | |||
|
160 | elif err.errno == errno.EPERM: | |||
|
161 | # Don't have permission to signal the process - probably means it exists | |||
|
162 | return True | |||
|
163 | raise | |||
|
164 | else: | |||
|
165 | return True | |||
|
166 | ||||
|
167 | if sys.platform == 'win32': | |||
|
168 | check_pid = _check_pid_win32 | |||
|
169 | else: | |||
|
170 | check_pid = _check_pid_posix |
@@ -1,16 +1,4 | |||||
1 | """Simple utility for building a list of local IPs using the socket module. |
|
1 | """Utilities for identifying local IP addresses.""" | |
2 | This module defines two constants: |
|
|||
3 |
|
||||
4 | LOCALHOST : The loopback interface, or the first interface that points to this |
|
|||
5 | machine. It will *almost* always be '127.0.0.1' |
|
|||
6 |
|
||||
7 | LOCAL_IPS : A list of IP addresses, loopback first, that point to this machine. |
|
|||
8 | This will include LOCALHOST, PUBLIC_IPS, and aliases for all hosts, |
|
|||
9 | such as '0.0.0.0'. |
|
|||
10 |
|
||||
11 | PUBLIC_IPS : A list of public IP addresses that point to this machine. |
|
|||
12 | Use these to tell remote clients where to find you. |
|
|||
13 | """ |
|
|||
14 |
|
2 | |||
15 | # Copyright (c) IPython Development Team. |
|
3 | # Copyright (c) IPython Development Team. | |
16 | # Distributed under the terms of the Modified BSD License. |
|
4 | # Distributed under the terms of the Modified BSD License. | |
@@ -18,9 +6,9 PUBLIC_IPS : A list of public IP addresses that point to this machine. | |||||
18 | import os |
|
6 | import os | |
19 | import re |
|
7 | import re | |
20 | import socket |
|
8 | import socket | |
|
9 | from subprocess import Popen, PIPE | |||
21 |
|
10 | |||
22 | from IPython.utils.data import uniq_stable |
|
11 | from IPython.utils.data import uniq_stable | |
23 | from IPython.utils.process import get_output_error_code |
|
|||
24 | from warnings import warn |
|
12 | from warnings import warn | |
25 |
|
13 | |||
26 |
|
14 | |||
@@ -29,6 +17,14 PUBLIC_IPS = [] | |||||
29 |
|
17 | |||
30 | LOCALHOST = '' |
|
18 | LOCALHOST = '' | |
31 |
|
19 | |||
|
20 | def _get_output(cmd): | |||
|
21 | """Get output of a command, raising IOError if it fails""" | |||
|
22 | p = Popen(cmd, stdout=PIPE, stderr=PIPE) | |||
|
23 | stdout, stderr = p.communicate() | |||
|
24 | if p.returncode: | |||
|
25 | raise IOError("Failed to run %s: %s" % (cmd, stderr.decode('utf8', 'replace'))) | |||
|
26 | return stdout.decode('utf8', 'replace') | |||
|
27 | ||||
32 | def _only_once(f): |
|
28 | def _only_once(f): | |
33 | """decorator to only run a function once""" |
|
29 | """decorator to only run a function once""" | |
34 | f.called = False |
|
30 | f.called = False | |
@@ -79,12 +75,11 def _populate_from_list(addrs): | |||||
79 | def _load_ips_ifconfig(): |
|
75 | def _load_ips_ifconfig(): | |
80 | """load ip addresses from `ifconfig` output (posix)""" |
|
76 | """load ip addresses from `ifconfig` output (posix)""" | |
81 |
|
77 | |||
82 | out, err, rc = get_output_error_code('ifconfig') |
|
78 | try: | |
83 | if rc: |
|
79 | out = _get_output('ifconfig') | |
|
80 | except (IOError, OSError): | |||
84 | # no ifconfig, it's usually in /sbin and /sbin is not on everyone's PATH |
|
81 | # no ifconfig, it's usually in /sbin and /sbin is not on everyone's PATH | |
85 |
out |
|
82 | out = _get_output('/sbin/ifconfig') | |
86 | if rc: |
|
|||
87 | raise IOError("no ifconfig: %s" % err) |
|
|||
88 |
|
83 | |||
89 | lines = out.splitlines() |
|
84 | lines = out.splitlines() | |
90 | addrs = [] |
|
85 | addrs = [] | |
@@ -100,9 +95,7 def _load_ips_ifconfig(): | |||||
100 |
|
95 | |||
101 | def _load_ips_ip(): |
|
96 | def _load_ips_ip(): | |
102 | """load ip addresses from `ip addr` output (Linux)""" |
|
97 | """load ip addresses from `ip addr` output (Linux)""" | |
103 |
out |
|
98 | out = _get_output(['ip', 'addr']) | |
104 | if rc: |
|
|||
105 | raise IOError("no ip: %s" % err) |
|
|||
106 |
|
99 | |||
107 | lines = out.splitlines() |
|
100 | lines = out.splitlines() | |
108 | addrs = [] |
|
101 | addrs = [] | |
@@ -116,9 +109,7 _ipconfig_ipv4_pat = re.compile(r'ipv4.*?(\d+\.\d+\.\d+\.\d+)$', re.IGNORECASE) | |||||
116 |
|
109 | |||
117 | def _load_ips_ipconfig(): |
|
110 | def _load_ips_ipconfig(): | |
118 | """load ip addresses from `ipconfig` output (Windows)""" |
|
111 | """load ip addresses from `ipconfig` output (Windows)""" | |
119 |
out |
|
112 | out = _get_output('ipconfig') | |
120 | if rc: |
|
|||
121 | raise IOError("no ipconfig: %s" % err) |
|
|||
122 |
|
113 | |||
123 | lines = out.splitlines() |
|
114 | lines = out.splitlines() | |
124 | addrs = [] |
|
115 | addrs = [] |
@@ -23,7 +23,6 except ImportError as e: | |||||
23 |
|
23 | |||
24 | from jupyter_nbconvert.utils.pandoc import pandoc |
|
24 | from jupyter_nbconvert.utils.pandoc import pandoc | |
25 | from jupyter_nbconvert.utils.exceptions import ConversionException |
|
25 | from jupyter_nbconvert.utils.exceptions import ConversionException | |
26 | from IPython.utils.process import get_output_error_code |
|
|||
27 | from IPython.utils.py3compat import cast_bytes |
|
26 | from IPython.utils.py3compat import cast_bytes | |
28 | from IPython.utils.version import check_version |
|
27 | from IPython.utils.version import check_version | |
29 |
|
28 | |||
@@ -130,11 +129,14 def _verify_node(cmd): | |||||
130 | cmd : string |
|
129 | cmd : string | |
131 | Node command to verify (i.e 'node').""" |
|
130 | Node command to verify (i.e 'node').""" | |
132 | try: |
|
131 | try: | |
133 |
|
|
132 | p = subprocess.Popen([cmd, '--version'], | |
|
133 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |||
|
134 | out, _ = p.communicate() | |||
|
135 | out = out.decode('utf8', 'replace') | |||
134 | except OSError: |
|
136 | except OSError: | |
135 | # Command not found |
|
137 | # Command not found | |
136 | return False |
|
138 | return False | |
137 |
if return |
|
139 | if p.returncode: | |
138 | # Command error |
|
140 | # Command error | |
139 | return False |
|
141 | return False | |
140 | return check_version(out.lstrip('v'), '0.9.12') |
|
142 | return check_version(out.lstrip('v'), '0.9.12') |
@@ -10,13 +10,14 import shlex | |||||
10 | import shutil |
|
10 | import shutil | |
11 | import sys |
|
11 | import sys | |
12 | import unittest |
|
12 | import unittest | |
|
13 | from subprocess import Popen, PIPE | |||
13 |
|
14 | |||
14 | import nose.tools as nt |
|
15 | import nose.tools as nt | |
15 |
|
16 | |||
16 | from IPython.nbformat import v4, write |
|
17 | from IPython.nbformat import v4, write | |
17 | from IPython.utils.tempdir import TemporaryWorkingDirectory |
|
18 | from IPython.utils.tempdir import TemporaryWorkingDirectory | |
18 | from IPython.utils.process import get_output_error_code |
|
19 | ||
19 | from IPython.utils.py3compat import string_types |
|
20 | from IPython.utils.py3compat import string_types, bytes_to_str | |
20 |
|
21 | |||
21 | class TestsBase(unittest.TestCase): |
|
22 | class TestsBase(unittest.TestCase): | |
22 | """Base tests class. Contains useful fuzzy comparison and nbconvert |
|
23 | """Base tests class. Contains useful fuzzy comparison and nbconvert | |
@@ -141,11 +142,13 class TestsBase(unittest.TestCase): | |||||
141 | if isinstance(parameters, string_types): |
|
142 | if isinstance(parameters, string_types): | |
142 | parameters = shlex.split(parameters) |
|
143 | parameters = shlex.split(parameters) | |
143 | cmd = [sys.executable, '-m', 'jupyter_nbconvert'] + parameters |
|
144 | cmd = [sys.executable, '-m', 'jupyter_nbconvert'] + parameters | |
144 | stdout, stderr, retcode = get_output_error_code(cmd) |
|
145 | p = Popen(cmd, stdout=PIPE, stderr=PIPE) | |
145 | if not (retcode == 0 or ignore_return_code): |
|
146 | stdout, stderr = p.communicate() | |
146 | raise OSError(stderr) |
|
147 | if not (p.returncode == 0 or ignore_return_code): | |
147 | return stdout, stderr |
|
148 | raise OSError(bytes_to_str(stderr)) | |
148 |
|
149 | return stdout.decode('utf8', 'replace'), stderr.decode('utf8', 'replace') | ||
|
150 | ||||
|
151 | ||||
149 | def assert_big_text_equal(a, b, chunk_size=80): |
|
152 | def assert_big_text_equal(a, b, chunk_size=80): | |
150 | """assert that large strings are equal |
|
153 | """assert that large strings are equal | |
151 |
|
154 |
@@ -11,7 +11,7 from io import TextIOWrapper, BytesIO | |||||
11 |
|
11 | |||
12 | from IPython.utils.py3compat import cast_bytes |
|
12 | from IPython.utils.py3compat import cast_bytes | |
13 | from IPython.utils.version import check_version |
|
13 | from IPython.utils.version import check_version | |
14 |
from IPython.utils.p |
|
14 | from IPython.utils.py3compat import which | |
15 |
|
15 | |||
16 | from .exceptions import ConversionException |
|
16 | from .exceptions import ConversionException | |
17 |
|
17 | |||
@@ -71,7 +71,7 def get_pandoc_version(): | |||||
71 | global __version |
|
71 | global __version | |
72 |
|
72 | |||
73 | if __version is None: |
|
73 | if __version is None: | |
74 |
if not |
|
74 | if not which('pandoc'): | |
75 | raise PandocMissing() |
|
75 | raise PandocMissing() | |
76 |
|
76 | |||
77 | out = subprocess.check_output(['pandoc', '-v'], |
|
77 | out = subprocess.check_output(['pandoc', '-v'], |
General Comments 0
You need to be logged in to leave comments.
Login now