From e41930dcf069674a747482b4c85f7b11e616a7a8 2022-08-29 20:23:05 From: Pieter Eendebak Date: 2022-08-29 20:23:05 Subject: [PATCH] Merge branch 'main' into latex_rendering_tempdir --- diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 03b58c6..8b1a4c3 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -2,9 +2,9 @@ name: Run MyPy on: push: - branches: [ master, 7.x] + branches: [ main, 7.x] pull_request: - branches: [ master, 7.x] + branches: [ main, 7.x] jobs: build: diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 663607f..37d0218 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -5,9 +5,9 @@ name: Python package on: push: - branches: [ master, 7.x ] + branches: [ main, 7.x ] pull_request: - branches: [ master, 7.x ] + branches: [ main, 7.x ] jobs: formatting: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1bbddbf..f57425a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - master - '*.x' pull_request: # Run weekly on Monday at 1:23 UTC diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 11321a4..5826baf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,7 +33,7 @@ When opening a new Issue, please take the following steps: 1. Search GitHub and/or Google for your issue to avoid duplicate reports. Keyword searches for your error messages are most helpful. -2. If possible, try updating to master and reproducing your issue, +2. If possible, try updating to main and reproducing your issue, because we may have already fixed it. 3. Try to include a minimal reproducible test case. 4. Include relevant system information. Start with the output of: @@ -53,7 +53,7 @@ Some guidelines on contributing to IPython: Review and discussion can begin well before the work is complete, and the more discussion the better. The worst case is that the PR is closed. -* Pull Requests should generally be made against master +* Pull Requests should generally be made against main * Pull Requests should be tested, if feasible: - bugfixes should include regression tests. - new behavior should at least get minimal exercise. diff --git a/IPython/__init__.py b/IPython/__init__.py index 7ebb80b..b5410f6 100644 --- a/IPython/__init__.py +++ b/IPython/__init__.py @@ -38,7 +38,7 @@ Python 3.7 was still supported with the 7.x branch. See IPython `README.rst` file for more information: - https://github.com/ipython/ipython/blob/master/README.rst + https://github.com/ipython/ipython/blob/main/README.rst """ ) diff --git a/IPython/core/completer.py b/IPython/core/completer.py index 59d3e99..cffd086 100644 --- a/IPython/core/completer.py +++ b/IPython/core/completer.py @@ -675,19 +675,23 @@ class Completer(Configurable): matches = [] match_append = matches.append n = len(text) - for lst in [keyword.kwlist, - builtin_mod.__dict__.keys(), - self.namespace.keys(), - self.global_namespace.keys()]: + for lst in [ + keyword.kwlist, + builtin_mod.__dict__.keys(), + list(self.namespace.keys()), + list(self.global_namespace.keys()), + ]: for word in lst: if word[:n] == text and word != "__builtins__": match_append(word) snake_case_re = re.compile(r"[^_]+(_[^_]+)+?\Z") - for lst in [self.namespace.keys(), - self.global_namespace.keys()]: - shortened = {"_".join([sub[0] for sub in word.split('_')]) : word - for word in lst if snake_case_re.match(word)} + for lst in [list(self.namespace.keys()), list(self.global_namespace.keys())]: + shortened = { + "_".join([sub[0] for sub in word.split("_")]): word + for word in lst + if snake_case_re.match(word) + } for word in shortened.keys(): if word[:n] == text and word != "__builtins__": match_append(shortened[word]) diff --git a/IPython/lib/tests/test_pretty.py b/IPython/lib/tests/test_pretty.py index 8608516..2d320bf 100644 --- a/IPython/lib/tests/test_pretty.py +++ b/IPython/lib/tests/test_pretty.py @@ -141,9 +141,12 @@ def test_pprint_heap_allocated_type(): Test that pprint works for heap allocated types. """ module_name = "xxlimited" if sys.version_info < (3, 10) else "xxlimited_35" + expected_output = ( + "xxlimited.Null" if sys.version_info < (3, 10, 6) else "xxlimited_35.Null" + ) xxlimited = pytest.importorskip(module_name) output = pretty.pretty(xxlimited.Null) - assert output == "xxlimited.Null" + assert output == expected_output def test_pprint_nomod(): diff --git a/IPython/terminal/shortcuts.py b/IPython/terminal/shortcuts.py index 615397a..6c1ba04 100644 --- a/IPython/terminal/shortcuts.py +++ b/IPython/terminal/shortcuts.py @@ -32,6 +32,22 @@ def cursor_in_leading_ws(): return (not before) or before.isspace() +# Needed for to accept autosuggestions in vi insert mode +def _apply_autosuggest(event): + """ + Apply autosuggestion if at end of line. + """ + b = event.current_buffer + d = b.document + after_cursor = d.text[d.cursor_position :] + lines = after_cursor.split("\n") + end_of_current_line = lines[0].strip() + suggestion = b.suggestion + if (suggestion is not None) and (suggestion.text) and (end_of_current_line == ""): + b.insert_text(suggestion.text) + else: + nc.end_of_line(event) + def create_ipython_shortcuts(shell): """Set up the prompt_toolkit keyboard shortcuts for IPython""" @@ -267,15 +283,6 @@ def create_ipython_shortcuts(shell): focused_insert_vi = has_focus(DEFAULT_BUFFER) & vi_insert_mode - # Needed for to accept autosuggestions in vi insert mode - def _apply_autosuggest(event): - b = event.current_buffer - suggestion = b.suggestion - if suggestion is not None and suggestion.text: - b.insert_text(suggestion.text) - else: - nc.end_of_line(event) - @kb.add("end", filter=has_focus(DEFAULT_BUFFER) & (ebivim | ~vi_insert_mode)) def _(event): _apply_autosuggest(event) diff --git a/IPython/tests/test_shortcuts.py b/IPython/tests/test_shortcuts.py new file mode 100644 index 0000000..42edb92 --- /dev/null +++ b/IPython/tests/test_shortcuts.py @@ -0,0 +1,40 @@ +import pytest +from IPython.terminal.shortcuts import _apply_autosuggest + +from unittest.mock import Mock + + +def make_event(text, cursor, suggestion): + event = Mock() + event.current_buffer = Mock() + event.current_buffer.suggestion = Mock() + event.current_buffer.cursor_position = cursor + event.current_buffer.suggestion.text = suggestion + event.current_buffer.document = Mock() + event.current_buffer.document.get_end_of_line_position = Mock(return_value=0) + event.current_buffer.document.text = text + event.current_buffer.document.cursor_position = cursor + return event + + +@pytest.mark.parametrize( + "text, cursor, suggestion, called", + [ + ("123456", 6, "123456789", True), + ("123456", 3, "123456789", False), + ("123456 \n789", 6, "123456789", True), + ], +) +def test_autosuggest_at_EOL(text, cursor, suggestion, called): + """ + test that autosuggest is only applied at end of line. + """ + + event = make_event(text, cursor, suggestion) + event.current_buffer.insert_text = Mock() + _apply_autosuggest(event) + if called: + event.current_buffer.insert_text.assert_called() + else: + event.current_buffer.insert_text.assert_not_called() + # event.current_buffer.document.get_end_of_line_position.assert_called() diff --git a/README.rst b/README.rst index ec16031..5107eae 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ -.. image:: https://codecov.io/github/ipython/ipython/coverage.svg?branch=master - :target: https://codecov.io/github/ipython/ipython?branch=master +.. image:: https://codecov.io/github/ipython/ipython/coverage.svg?branch=main + :target: https://codecov.io/github/ipython/ipython?branch=main .. image:: https://img.shields.io/pypi/v/IPython.svg :target: https://pypi.python.org/pypi/ipython diff --git a/docs/source/coredev/index.rst b/docs/source/coredev/index.rst index ee1eadb..3ba9475 100644 --- a/docs/source/coredev/index.rst +++ b/docs/source/coredev/index.rst @@ -14,12 +14,12 @@ For instructions on how to make a developer install see :ref:`devinstall`. Backporting Pull requests ========================= -All pull requests should usually be made against ``master``, if a Pull Request +All pull requests should usually be made against ``main``, if a Pull Request need to be backported to an earlier release; then it should be tagged with the correct ``milestone``. If you tag a pull request with a milestone **before** merging the pull request, -and the base ref is ``master``, then our backport bot should automatically create +and the base ref is ``main``, then our backport bot should automatically create a corresponding pull-request that backport on the correct branch. If you have write access to the IPython repository you can also just mention the @@ -78,7 +78,7 @@ for the release you are actually making:: PREV_RELEASE=4.2.1 MILESTONE=5.0 VERSION=5.0.0 - BRANCH=master + BRANCH=main For `reproducibility of builds `_, we recommend setting ``SOURCE_DATE_EPOCH`` prior to running the build; record the used value diff --git a/examples/IPython Kernel/Terminal Usage.ipynb b/examples/IPython Kernel/Terminal Usage.ipynb index e6bd4c0..935bdd4 100644 --- a/examples/IPython Kernel/Terminal Usage.ipynb +++ b/examples/IPython Kernel/Terminal Usage.ipynb @@ -196,7 +196,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The `%gui` magic can be similarly used to control Wx, Tk, glut and pyglet applications, [as can be seen in our examples](https://github.com/ipython/ipython/tree/master/examples/lib)." + "The `%gui` magic can be similarly used to control Wx, Tk, glut and pyglet applications, [as can be seen in our examples](https://github.com/ipython/ipython/tree/main/examples/lib)." ] }, { diff --git a/setup.py b/setup.py index 3c1dff9..bfdf5fb 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ Python 3.7 was still supported with the 7.x branch. See IPython `README.rst` file for more information: - https://github.com/ipython/ipython/blob/master/README.rst + https://github.com/ipython/ipython/blob/main/README.rst Python {py} detected. {pip} diff --git a/tools/github_stats.py b/tools/github_stats.py index f1a44fa..af00a7b 100644 --- a/tools/github_stats.py +++ b/tools/github_stats.py @@ -79,8 +79,8 @@ def issues_closed_since(period=timedelta(days=365), project="ipython/ipython", p filtered = [ i for i in allclosed if _parse_datetime(i['closed_at']) > since ] if pulls: filtered = [ i for i in filtered if _parse_datetime(i['merged_at']) > since ] - # filter out PRs not against master (backports) - filtered = [ i for i in filtered if i['base']['ref'] == 'master' ] + # filter out PRs not against main (backports) + filtered = [i for i in filtered if i["base"]["ref"] == "main"] else: filtered = [ i for i in filtered if not is_pull_request(i) ] diff --git a/tools/release_helper.sh b/tools/release_helper.sh index 54114d1..697ed85 100644 --- a/tools/release_helper.sh +++ b/tools/release_helper.sh @@ -31,7 +31,7 @@ MILESTONE=${input:-$MILESTONE} echo -n "VERSION (X.y.z) [$VERSION]:" read input VERSION=${input:-$VERSION} -echo -n "BRANCH (master|X.y) [$BRANCH]:" +echo -n "BRANCH (main|X.y) [$BRANCH]:" read input BRANCH=${input:-$BRANCH} diff --git a/tools/retar.py b/tools/retar.py index ccf1a13..f8da290 100644 --- a/tools/retar.py +++ b/tools/retar.py @@ -4,6 +4,8 @@ Un-targz and retargz a targz file to ensure reproducible build. usage: $ export SOURCE_DATE_EPOCH=$(date +%s) + # or + $ export SOURCE_DATE_EPOCH=$(git show -s --format=%ct HEAD) ... $ python retar.py