Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0daec1

Browse files
authored
Merge branch 'main' into completion-matcher
2 parents 21f1467 + 84af481 commit b0daec1

36 files changed

Lines changed: 407 additions & 155 deletions

.github/workflows/docs.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v2
11-
- name: Set up Python 3.8
12-
uses: actions/setup-python@v2
10+
- uses: actions/checkout@v3
11+
- name: Set up Python
12+
uses: actions/setup-python@v4
1313
with:
14-
python-version: 3.8
14+
python-version: 3.x
1515
- name: Install Graphviz
1616
run: |
1717
sudo apt-get update

.github/workflows/downstream.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ jobs:
2121
python-version: "3.9"
2222

2323
steps:
24-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v3
2525
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v2
26+
uses: actions/setup-python@v4
2727
with:
2828
python-version: ${{ matrix.python-version }}
2929
- name: Update Python installer

.github/workflows/mypy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
python-version: [3.8]
1616

1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
1919
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v2
20+
uses: actions/setup-python@v4
2121
with:
2222
python-version: ${{ matrix.python-version }}
2323
- name: Install dependencies

.github/workflows/python-package.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@ jobs:
1414

1515
runs-on: ubuntu-latest
1616
timeout-minutes: 5
17-
strategy:
18-
matrix:
19-
python-version: [3.8]
20-
2117
steps:
22-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
2319
with:
2420
fetch-depth: 0
25-
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v2
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
2723
with:
28-
python-version: ${{ matrix.python-version }}
24+
python-version: 3.x
2925
- name: Install dependencies
3026
run: |
3127
python -m pip install --upgrade pip

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ jobs:
4949
deps: test
5050

5151
steps:
52-
- uses: actions/checkout@v2
52+
- uses: actions/checkout@v3
5353
- name: Set up Python ${{ matrix.python-version }}
54-
uses: actions/setup-python@v2
54+
uses: actions/setup-python@v4
5555
with:
5656
python-version: ${{ matrix.python-version }}
5757
cache: pip

IPython/core/completer.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -906,19 +906,23 @@ def global_matches(self, text):
906906
matches = []
907907
match_append = matches.append
908908
n = len(text)
909-
for lst in [keyword.kwlist,
910-
builtin_mod.__dict__.keys(),
911-
self.namespace.keys(),
912-
self.global_namespace.keys()]:
909+
for lst in [
910+
keyword.kwlist,
911+
builtin_mod.__dict__.keys(),
912+
list(self.namespace.keys()),
913+
list(self.global_namespace.keys()),
914+
]:
913915
for word in lst:
914916
if word[:n] == text and word != "__builtins__":
915917
match_append(word)
916918

917919
snake_case_re = re.compile(r"[^_]+(_[^_]+)+?\Z")
918-
for lst in [self.namespace.keys(),
919-
self.global_namespace.keys()]:
920-
shortened = {"_".join([sub[0] for sub in word.split('_')]) : word
921-
for word in lst if snake_case_re.match(word)}
920+
for lst in [list(self.namespace.keys()), list(self.global_namespace.keys())]:
921+
shortened = {
922+
"_".join([sub[0] for sub in word.split("_")]): word
923+
for word in lst
924+
if snake_case_re.match(word)
925+
}
922926
for word in shortened.keys():
923927
if word[:n] == text and word != "__builtins__":
924928
match_append(shortened[word])

IPython/core/history.py

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ def __init__(self, profile="default", hist_file="", **traits):
202202
config : :class:`~traitlets.config.loader.Config`
203203
Config object. hist_file can also be set through this.
204204
"""
205-
# We need a pointer back to the shell for various tasks.
206205
super(HistoryAccessor, self).__init__(**traits)
207206
# defer setting hist_file from kwarg until after init,
208207
# otherwise the default kwarg value would clobber any value
@@ -344,11 +343,6 @@ def get_last_session_id(self):
344343
def get_tail(self, n=10, raw=True, output=False, include_latest=False):
345344
"""Get the last n lines from the history database.
346345
347-
Most recent entry last.
348-
349-
Completion will be reordered so that that the last ones are when
350-
possible from current session.
351-
352346
Parameters
353347
----------
354348
n : int
@@ -367,31 +361,12 @@ def get_tail(self, n=10, raw=True, output=False, include_latest=False):
367361
self.writeout_cache()
368362
if not include_latest:
369363
n += 1
370-
# cursor/line/entry
371-
this_cur = list(
372-
self._run_sql(
373-
"WHERE session == ? ORDER BY line DESC LIMIT ? ",
374-
(self.session_number, n),
375-
raw=raw,
376-
output=output,
377-
)
378-
)
379-
other_cur = list(
380-
self._run_sql(
381-
"WHERE session != ? ORDER BY session DESC, line DESC LIMIT ?",
382-
(self.session_number, n),
383-
raw=raw,
384-
output=output,
385-
)
364+
cur = self._run_sql(
365+
"ORDER BY session DESC, line DESC LIMIT ?", (n,), raw=raw, output=output
386366
)
387-
388-
everything = this_cur + other_cur
389-
390-
everything = everything[:n]
391-
392367
if not include_latest:
393-
return list(everything)[:0:-1]
394-
return list(everything)[::-1]
368+
return reversed(list(cur)[1:])
369+
return reversed(list(cur))
395370

396371
@catch_corrupt_db
397372
def search(self, pattern="*", raw=True, search_raw=True,
@@ -560,7 +535,6 @@ def _dir_hist_default(self):
560535
def __init__(self, shell=None, config=None, **traits):
561536
"""Create a new history manager associated with a shell instance.
562537
"""
563-
# We need a pointer back to the shell for various tasks.
564538
super(HistoryManager, self).__init__(shell=shell, config=config,
565539
**traits)
566540
self.save_flag = threading.Event()
@@ -656,6 +630,59 @@ def get_session_info(self, session=0):
656630

657631
return super(HistoryManager, self).get_session_info(session=session)
658632

633+
@catch_corrupt_db
634+
def get_tail(self, n=10, raw=True, output=False, include_latest=False):
635+
"""Get the last n lines from the history database.
636+
637+
Most recent entry last.
638+
639+
Completion will be reordered so that that the last ones are when
640+
possible from current session.
641+
642+
Parameters
643+
----------
644+
n : int
645+
The number of lines to get
646+
raw, output : bool
647+
See :meth:`get_range`
648+
include_latest : bool
649+
If False (default), n+1 lines are fetched, and the latest one
650+
is discarded. This is intended to be used where the function
651+
is called by a user command, which it should not return.
652+
653+
Returns
654+
-------
655+
Tuples as :meth:`get_range`
656+
"""
657+
self.writeout_cache()
658+
if not include_latest:
659+
n += 1
660+
# cursor/line/entry
661+
this_cur = list(
662+
self._run_sql(
663+
"WHERE session == ? ORDER BY line DESC LIMIT ? ",
664+
(self.session_number, n),
665+
raw=raw,
666+
output=output,
667+
)
668+
)
669+
other_cur = list(
670+
self._run_sql(
671+
"WHERE session != ? ORDER BY session DESC, line DESC LIMIT ?",
672+
(self.session_number, n),
673+
raw=raw,
674+
output=output,
675+
)
676+
)
677+
678+
everything = this_cur + other_cur
679+
680+
everything = everything[:n]
681+
682+
if not include_latest:
683+
return list(everything)[:0:-1]
684+
return list(everything)[::-1]
685+
659686
def _get_range_session(self, start=1, stop=None, raw=True, output=False):
660687
"""Get input and output history from the current session. Called by
661688
get_range, and takes similar parameters."""

IPython/core/hooks.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,17 @@ def clipboard_get(self):
155155
""" Get text from the clipboard.
156156
"""
157157
from ..lib.clipboard import (
158-
osx_clipboard_get, tkinter_clipboard_get,
159-
win32_clipboard_get
158+
osx_clipboard_get,
159+
tkinter_clipboard_get,
160+
win32_clipboard_get,
161+
wayland_clipboard_get,
160162
)
161163
if sys.platform == 'win32':
162164
chain = [win32_clipboard_get, tkinter_clipboard_get]
163165
elif sys.platform == 'darwin':
164166
chain = [osx_clipboard_get, tkinter_clipboard_get]
165167
else:
166-
chain = [tkinter_clipboard_get]
168+
chain = [wayland_clipboard_get, tkinter_clipboard_get]
167169
dispatcher = CommandChainDispatcher()
168170
for func in chain:
169171
dispatcher.add(func)

IPython/core/magics/osm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import io
1010
import os
11+
import pathlib
1112
import re
1213
import sys
1314
from pprint import pformat
@@ -409,7 +410,7 @@ def cd(self, parameter_s=''):
409410
except OSError:
410411
print(sys.exc_info()[1])
411412
else:
412-
cwd = os.getcwd()
413+
cwd = pathlib.Path.cwd()
413414
dhist = self.shell.user_ns['_dh']
414415
if oldcwd != cwd:
415416
dhist.append(cwd)
@@ -419,7 +420,7 @@ def cd(self, parameter_s=''):
419420
os.chdir(self.shell.home_dir)
420421
if hasattr(self.shell, 'term_title') and self.shell.term_title:
421422
set_term_title(self.shell.term_title_format.format(cwd="~"))
422-
cwd = os.getcwd()
423+
cwd = pathlib.Path.cwd()
423424
dhist = self.shell.user_ns['_dh']
424425

425426
if oldcwd != cwd:

IPython/core/release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# release. 'dev' as a _version_extra string means this is a development
1717
# version
1818
_version_major = 8
19-
_version_minor = 5
19+
_version_minor = 6
2020
_version_patch = 0
2121
_version_extra = ".dev"
2222
# _version_extra = "rc1"

0 commit comments

Comments
 (0)