##// END OF EJS Templates
MAINT: deprecate append_to_syspath
Matthias Bussonnier -
Show More
@@ -0,0 +1,7 b''
1 from IPython.utils.syspathcontext import appended_to_syspath
2 import pytest
3
4
5 def test_append_deprecated():
6 with pytest.warns(DeprecationWarning):
7 appended_to_syspath(".")
@@ -1,62 +1,71 b''
1 1 # encoding: utf-8
2 2 """
3 3 Context managers for adding things to sys.path temporarily.
4 4
5 5 Authors:
6 6
7 7 * Brian Granger
8 8 """
9 9
10 10 #-----------------------------------------------------------------------------
11 11 # Copyright (C) 2008-2011 The IPython Development Team
12 12 #
13 13 # Distributed under the terms of the BSD License. The full license is in
14 14 # the file COPYING, distributed as part of this software.
15 15 #-----------------------------------------------------------------------------
16 16
17 17 import sys
18 import warnings
18 19
19 20
20 21 class appended_to_syspath(object):
21 """A context for appending a directory to sys.path for a second."""
22 """
23 Deprecated since IPython 8.1, no replacements.
24
25 A context for appending a directory to sys.path for a second."""
22 26
23 27 def __init__(self, dir):
28 warnings.warn(
29 "`appended_to_syspath` is deprecated since IPython 8.1, and has no replacements",
30 DeprecationWarning,
31 stacklevel=2,
32 )
24 33 self.dir = dir
25 34
26 35 def __enter__(self):
27 36 if self.dir not in sys.path:
28 37 sys.path.append(self.dir)
29 38 self.added = True
30 39 else:
31 40 self.added = False
32 41
33 42 def __exit__(self, type, value, traceback):
34 43 if self.added:
35 44 try:
36 45 sys.path.remove(self.dir)
37 46 except ValueError:
38 47 pass
39 48 # Returning False causes any exceptions to be re-raised.
40 49 return False
41 50
42 51 class prepended_to_syspath(object):
43 52 """A context for prepending a directory to sys.path for a second."""
44 53
45 54 def __init__(self, dir):
46 55 self.dir = dir
47 56
48 57 def __enter__(self):
49 58 if self.dir not in sys.path:
50 59 sys.path.insert(0,self.dir)
51 60 self.added = True
52 61 else:
53 62 self.added = False
54 63
55 64 def __exit__(self, type, value, traceback):
56 65 if self.added:
57 66 try:
58 67 sys.path.remove(self.dir)
59 68 except ValueError:
60 69 pass
61 70 # Returning False causes any exceptions to be re-raised.
62 71 return False
@@ -1,40 +1,43 b''
1 1 # encoding: utf-8
2 2 """
3 3 Utilities for version comparison
4 4
5 5 It is a bit ridiculous that we need these.
6 6 """
7 7
8 8 #-----------------------------------------------------------------------------
9 9 # Copyright (C) 2013 The IPython Development Team
10 10 #
11 11 # Distributed under the terms of the BSD License. The full license is in
12 12 # the file COPYING, distributed as part of this software.
13 13 #-----------------------------------------------------------------------------
14 14
15 15 from warnings import warn
16 16
17 warn("The `IPython.utils.version` module has been deprecated since IPython 8.0.")
17 warn(
18 "The `IPython.utils.version` module has been deprecated since IPython 8.0.",
19 DeprecationWarning,
20 )
18 21
19 22
20 23 def check_version(v, check):
21 24 """check version string v >= check
22 25
23 26 If dev/prerelease tags result in TypeError for string-number comparison,
24 27 it is assumed that the dependency is satisfied.
25 28 Users on dev branches are responsible for keeping their own packages up to date.
26 29 """
27 30 warn(
28 31 "`check_version` function is deprecated as of IPython 8.0"
29 32 "and will be removed in future versions.",
30 33 DeprecationWarning,
31 34 stacklevel=2,
32 35 )
33 36
34 37 from distutils.version import LooseVersion
35 38
36 39 try:
37 40 return LooseVersion(v) >= LooseVersion(check)
38 41 except TypeError:
39 42 return True
40 43
General Comments 0
You need to be logged in to leave comments. Login now