Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into windows-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
picnixz committed Mar 19, 2024
2 parents 81a8ff0 + d8cf71c commit 2e6f9f5
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 50 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exclude =
.git,
.tox,
.venv,
node_modules/*,
tests/roots/*,
build/*,
doc/_build/*,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
script: core.setOutput('version', context.ref.replace("refs/tags/v", ""))

- name: Create GitHub release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
name: "Sphinx ${{ steps.get_version.outputs.version }}"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
- name: Lint with Ruff
run: ruff check . --output-format github

- name: Format with Ruff
run: ruff format . --diff

flake8:
runs-on: ubuntu-latest

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,3 @@ jobs:
run: python -m pytest -vv
env:
PYTHONWARNINGS: "error" # treat all warnings as errors

2 changes: 1 addition & 1 deletion .github/workflows/transifex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Compile message catalogs
run: python utils/babel_runner.py compile
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6
with:
commit-message: "[internationalisation] Update translations"
branch: bot/pull-translations
Expand Down
68 changes: 67 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ select = [
# mccabe ('C90')
# "C901", # `{name}` is too complex ({complexity} > {max_complexity})
# flake8-commas ('COM')
"COM812", # Trailing comma missing
"COM818", # Trailing comma on bare tuple prohibited
"COM819", # Trailing comma prohibited
# flake8-copyright ('CPY')
Expand Down Expand Up @@ -422,3 +421,70 @@ inline-quotes = "single"
forced-separate = [
"tests",
]

[format]
quote-style = "single"
exclude = [
"doc/**/*",
"sphinx/__init__.py",
"sphinx/addnodes.py",
"sphinx/application.py",
"sphinx/builders/**/*",
"sphinx/cmd/**/*",
"sphinx/config.py",
"sphinx/deprecation.py",
"sphinx/directives/**/*",
"sphinx/domains/**/*",
"sphinx/environment/**/*",
"sphinx/errors.py",
"sphinx/events.py",
"sphinx/ext/**/*",
"sphinx/extension.py",
"sphinx/highlighting.py",
"sphinx/io.py",
"sphinx/jinja2glue.py",
"sphinx/locale/__init__.py",
"sphinx/parsers.py",
"sphinx/project.py",
"sphinx/pycode/**/*",
"sphinx/pygments_styles.py",
"sphinx/registry.py",
"sphinx/roles.py",
"sphinx/search/**/*",
"sphinx/templates/**/*",
"sphinx/testing/**/*",
"sphinx/theming.py",
"sphinx/transforms/**/*",
"sphinx/util/**/*",
"sphinx/versioning.py",
"sphinx/writers/**/*",
"tests/certs/**/*",
"tests/conftest.py",
"tests/roots/**/*",
"tests/test_addnodes.py",
"tests/test_application.py",
"tests/test_builders/**/*",
"tests/test_config/**/*",
"tests/test_directives/**/*",
"tests/test_domains/**/*",
"tests/test_environment/**/*",
"tests/test_errors.py",
"tests/test_events.py",
"tests/test_extensions/**/*",
"tests/test_highlighting.py",
"tests/test_intl/**/*",
"tests/test_markup/**/*",
"tests/test_project.py",
"tests/test_pycode/**/*",
"tests/test_quickstart.py",
"tests/test_roles.py",
"tests/test_search.py",
"tests/test_theming/**/*",
"tests/test_toctree.py",
"tests/test_transforms/**/*",
"tests/test_util/**/*",
"tests/test_versioning.py",
"tests/test_writers/**/*",
"tests/utils.py",
"utils/**/*",
]
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Deprecated
Features added
--------------

* #12131: Added :confval:`show_warning_types` configuration option.
Patch by Chris Sewell.

* #11701: HTML Search: Adopt the new `<search>`_ element.
Patch by Bénédikt Tran.

Expand Down Expand Up @@ -112,6 +115,8 @@ Bugs fixed
* #12052: Remove ``<script>`` and ``<style>`` tags from the content of search result
summary snippets.
Patch by James Addison.
* #11578: HTML Search: Order non-main index entries after other results.
Patch by Brad King.

Testing
-------
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
PYTHON ?= python3

.PHONY: all
all: style-check type-check test
all: format style-check type-check doclinter test

.PHONY: check
check: style-check type-check doclinter

.PHONY: clean
clean: clean
Expand Down Expand Up @@ -42,8 +45,13 @@ clean: clean

.PHONY: style-check
style-check:
@flake8 .
@ruff check .

.PHONY: format
format:
@ruff format .

.PHONY: type-check
type-check:
@mypy
Expand Down
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
release = version
show_authors = True
nitpicky = True
show_warning_types = True

html_theme = 'sphinx13'
html_theme_path = ['_themes']
Expand Down
14 changes: 11 additions & 3 deletions doc/usage/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,19 @@ General configuration

.. versionadded:: 0.5

.. confval:: show_warning_types

If ``True``, the type of each warning is added as a suffix to the warning message,
e.g., ``WARNING: [...] [index]`` or ``WARNING: [...] [toc.circular]``.
The default is ``False``.

.. versionadded:: 7.3.0

.. confval:: suppress_warnings

A list of warning types to suppress arbitrary warning messages.

Sphinx supports following warning types:
Sphinx core supports following warning types:

* ``app.add_node``
* ``app.add_directive``
Expand Down Expand Up @@ -359,11 +367,11 @@ General configuration
* ``toc.not_readable``
* ``toc.secnum``

Then extensions can also define their own warning types.

You can choose from these types. You can also give only the first
component to exclude all warnings attached to it.

Now, this option should be considered *experimental*.

.. versionadded:: 1.4

.. versionchanged:: 1.5
Expand Down
1 change: 1 addition & 0 deletions sphinx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class Config:
'template_bridge': _Opt(None, 'html', frozenset((str,))),
'keep_warnings': _Opt(False, 'env', ()),
'suppress_warnings': _Opt([], 'env', ()),
'show_warning_types': _Opt(False, 'env', frozenset((bool,))),
'modindex_common_prefix': _Opt([], 'html', ()),
'rst_epilog': _Opt(None, 'env', frozenset((str,))),
'rst_prolog': _Opt(None, 'env', frozenset((str,))),
Expand Down
10 changes: 0 additions & 10 deletions sphinx/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ def build_uri(self) -> str:
return base_url + self.inliner.rfc_url % int(ret[0])


_amp_re = re.compile(r'(?<!&)&(?![&\s])')


class GUILabel(SphinxRole):
amp_re = re.compile(r'(?<!&)&(?![&\s])')

Expand All @@ -269,10 +266,6 @@ def run(self) -> tuple[list[Node], list[system_message]]:
return super().run()


_litvar_re = re.compile('{([^}]+)}')
parens_re = re.compile(r'(\\*{|\\*})')


class EmphasizedLiteral(SphinxRole):
parens_re = re.compile(r'(\\\\|\\{|\\}|{|})')

Expand Down Expand Up @@ -322,9 +315,6 @@ def parse(self, text: str) -> list[Node]:
return result


_abbr_re = re.compile(r'\((.*)\)$', re.DOTALL)


class Abbreviation(SphinxRole):
abbr_re = re.compile(r'\((.*)\)$', re.DOTALL)

Expand Down
4 changes: 2 additions & 2 deletions sphinx/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,10 @@ def freeze(self) -> dict[str, Any]:
for title, titleid in titlelist:
alltitles.setdefault(title, []).append((fn2index[docname], titleid))

index_entries: dict[str, list[tuple[int, str]]] = {}
index_entries: dict[str, list[tuple[int, str, bool]]] = {}
for docname, entries in self._index_entries.items():
for entry, entry_id, main_entry in entries:
index_entries.setdefault(entry.lower(), []).append((fn2index[docname], entry_id))
index_entries.setdefault(entry.lower(), []).append((fn2index[docname], entry_id, main_entry == "main"))

return dict(docnames=docnames, filenames=filenames, titles=titles, terms=terms,
objects=objects, objtypes=objtypes, objnames=objnames,
Expand Down
72 changes: 46 additions & 26 deletions sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ const _displayNextItem = (
// search finished, update title and status message
else _finishSearch(resultCount);
};
// Helper function used by query() to order search results.
// Each input is an array of [docname, title, anchor, descr, score, filename].
// Order the results by score (in opposite order of appearance, since the
// `_displayNextItem` function uses pop() to retrieve items) and then alphabetically.
const _orderResultsByScoreThenName = (a, b) => {
const leftScore = a[4];
const rightScore = b[4];
if (leftScore === rightScore) {
// same score: sort alphabetically
const leftTitle = a[1].toLowerCase();
const rightTitle = b[1].toLowerCase();
if (leftTitle === rightTitle) return 0;
return leftTitle > rightTitle ? -1 : 1; // inverted is intentional
}
return leftScore > rightScore ? 1 : -1;
};

/**
* Default splitQuery function. Can be overridden in ``sphinx.search`` with a
Expand Down Expand Up @@ -297,16 +313,19 @@ const Search = {
// console.info("required: ", [...searchTerms]);
// console.info("excluded: ", [...excludedTerms]);

// array of [docname, title, anchor, descr, score, filename]
let results = [];
// Collect multiple result groups to be sorted separately and then ordered.
// Each is an array of [docname, title, anchor, descr, score, filename].
const normalResults = [];
const nonMainIndexResults = [];

_removeChildren(document.getElementById("search-progress"));

const queryLower = query.toLowerCase().trim();
for (const [title, foundTitles] of Object.entries(allTitles)) {
if (title.toLowerCase().trim().includes(queryLower) && (queryLower.length >= title.length/2)) {
for (const [file, id] of foundTitles) {
let score = Math.round(100 * queryLower.length / title.length)
results.push([
normalResults.push([
docNames[file],
titles[file] !== title ? `${titles[file]} > ${title}` : title,
id !== null ? "#" + id : "",
Expand All @@ -321,46 +340,47 @@ const Search = {
// search for explicit entries in index directives
for (const [entry, foundEntries] of Object.entries(indexEntries)) {
if (entry.includes(queryLower) && (queryLower.length >= entry.length/2)) {
for (const [file, id] of foundEntries) {
let score = Math.round(100 * queryLower.length / entry.length)
results.push([
for (const [file, id, isMain] of foundEntries) {
const score = Math.round(100 * queryLower.length / entry.length);
const result = [
docNames[file],
titles[file],
id ? "#" + id : "",
null,
score,
filenames[file],
]);
];
if (isMain) {
normalResults.push(result);
} else {
nonMainIndexResults.push(result);
}
}
}
}

// lookup as object
objectTerms.forEach((term) =>
results.push(...Search.performObjectSearch(term, objectTerms))
normalResults.push(...Search.performObjectSearch(term, objectTerms))
);

// lookup as search terms in fulltext
results.push(...Search.performTermsSearch(searchTerms, excludedTerms));
normalResults.push(...Search.performTermsSearch(searchTerms, excludedTerms));

// let the scorer override scores with a custom scoring function
if (Scorer.score) results.forEach((item) => (item[4] = Scorer.score(item)));

// now sort the results by score (in opposite order of appearance, since the
// display function below uses pop() to retrieve items) and then
// alphabetically
results.sort((a, b) => {
const leftScore = a[4];
const rightScore = b[4];
if (leftScore === rightScore) {
// same score: sort alphabetically
const leftTitle = a[1].toLowerCase();
const rightTitle = b[1].toLowerCase();
if (leftTitle === rightTitle) return 0;
return leftTitle > rightTitle ? -1 : 1; // inverted is intentional
}
return leftScore > rightScore ? 1 : -1;
});
if (Scorer.score) {
normalResults.forEach((item) => (item[4] = Scorer.score(item)));
nonMainIndexResults.forEach((item) => (item[4] = Scorer.score(item)));
}

// Sort each group of results by score and then alphabetically by name.
normalResults.sort(_orderResultsByScoreThenName);
nonMainIndexResults.sort(_orderResultsByScoreThenName);

// Combine the result groups in (reverse) order.
// Non-main index entries are typically arbitrary cross-references,
// so display them after other results.
let results = [...nonMainIndexResults, ...normalResults];

// remove duplicate search results
// note the reversing of results, so that in the case of duplicates, the highest-scoring entry is kept
Expand Down
Loading

0 comments on commit 2e6f9f5

Please sign in to comment.