Skip to content

Commit

Permalink
Merge branch 'main' into impr/3995/NO_COLOR+FORCE_COLOR
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas authored Jan 25, 2025
2 parents cd55074 + 05e83c4 commit a2afa05
Show file tree
Hide file tree
Showing 30 changed files with 458 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/primer_run_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
${{ runner.os }}-${{ matrix.python-version }}-${{
steps.commitstring.outputs.commitstring }}-primer
- name: Upload commit string
uses: actions/upload-artifact@v4.5.0
uses: actions/upload-artifact@v4.6.0
if: matrix.batchIdx == 0
with:
name: primer_commitstring_${{ matrix.python-version }}
Expand All @@ -123,7 +123,7 @@ jobs:
then echo "::warning ::$WARNINGS"
fi
- name: Upload output
uses: actions/upload-artifact@v4.5.0
uses: actions/upload-artifact@v4.6.0
with:
name:
primer_output_main_${{ matrix.python-version }}_batch${{ matrix.batchIdx }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/primer_run_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ jobs:
then echo "::warning ::$WARNINGS"
fi
- name: Upload output of PR
uses: actions/upload-artifact@v4.5.0
uses: actions/upload-artifact@v4.6.0
with:
name:
primer_output_pr_${{ matrix.python-version }}_batch${{ matrix.batchIdx }}
path:
tests/.pylint_primer_tests/output_${{ matrix.python-version }}_pr_batch${{
matrix.batchIdx }}.txt
- name: Upload output of 'main'
uses: actions/upload-artifact@v4.5.0
uses: actions/upload-artifact@v4.6.0
with:
name:
primer_output_main_${{ matrix.python-version }}_batch${{ matrix.batchIdx }}
Expand All @@ -218,7 +218,7 @@ jobs:
- name: Upload PR number
if:
startsWith(steps.python.outputs.python-version, '3.9') && matrix.batchIdx == 0
uses: actions/upload-artifact@v4.5.0
uses: actions/upload-artifact@v4.6.0
with:
name: pr_number
path: pr_number.txt
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
pip list | grep 'astroid\|pylint'
python -m pytest -vv --minimal-messages-config tests/test_functional.py
- name: Upload coverage artifact
uses: actions/upload-artifact@v4.5.0
uses: actions/upload-artifact@v4.6.0
with:
name: coverage-${{ matrix.python-version }}
include-hidden-files: true
Expand Down Expand Up @@ -161,7 +161,7 @@ jobs:
run: >-
echo "datetime="$(date "+%Y%m%d_%H%M") >> $GITHUB_OUTPUT
- name: Upload benchmark artifact
uses: actions/upload-artifact@v4.5.0
uses: actions/upload-artifact@v4.6.0
with:
name:
benchmark-${{ runner.os }}-${{ matrix.python-version }}_${{
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
doc/data/messages/m/missing-final-newline/bad/crlf.py
)$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.8.6"
rev: "v0.9.2"
hooks:
- id: ruff
args: ["--fix"]
Expand Down Expand Up @@ -171,7 +171,7 @@ repos:
setup.cfg
)$
- repo: https://github.com/PyCQA/bandit
rev: 1.8.0
rev: 1.8.2
hooks:
- id: bandit
args: ["-r", "-lll"]
Expand Down
7 changes: 7 additions & 0 deletions doc/additional_tools/pyreverse/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ Filtering and Scope
**Default:** ``PUB_ONLY``


--max-depth
-----------
*Maximum depth in package/module hierarchy to display. A depth of 0 shows only top-level packages, 1 shows one level of subpackages, etc. If not specified, all packages/modules are shown.*

**Default:** ``None``


--show-ancestors
----------------
*Show <ancestor> generations of ancestor classes not in <projects>.*
Expand Down
1 change: 1 addition & 0 deletions doc/data/messages/u/unused-import/details.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
By default, this check is skipped for ``__init__.py`` files, as they often contain imports from submodules for the convenience of end users. While these imports are not used within ``__init__.py``, they serve the purpose of providing intuitive import paths for the module's important classes and constants.
1 change: 1 addition & 0 deletions doc/data/messages/u/unused-import/related.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- :ref:`--init-import <variables-options>`
12 changes: 12 additions & 0 deletions doc/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,15 @@ localized using the following rules:
- macOS: "~/Library/Caches/pylint"
- Windows: "C:\Users\<username>\AppData\Local\pylint"
* ".pylint.d" directory in the current directory

How does the website pylint dot org relate to this project?
-----------------------------------------------------------

Historically, pylint dot org served as the primary website for Pylint. However,
we no longer have access to the domain. The current owners are monetizing
this by displaying advertisements alongside outdated documentation without
contributing to pylint at all. For the latest and official Pylint documentation,
please visit `pylint.readthedocs.io <https://pylint.readthedocs.io/en/stable/>`_.

Please see `issue 8934 <https://github.com/pylint-dev/pylint/issues/8934>`_
for more details.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/10073.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixes "skipped files" count calculation; the previous method was displaying an arbitrary number.

Closes #10073
4 changes: 4 additions & 0 deletions doc/whatsnew/fragments/10077.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Add --max-depth option to pyreverse to control diagram complexity. A depth of 0 shows only top-level packages, 1 shows one level of subpackages, etc.
This helps manage visualization of large codebases by limiting the depth of displayed packages and classes.

Refs #10077
3 changes: 2 additions & 1 deletion pylint/config/config_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pylint.lint import PyLinter


def _config_initialization(
def _config_initialization( # pylint: disable=too-many-statements
linter: PyLinter,
args_list: list[str],
reporter: reporters.BaseReporter | reporters.MultiReporter | None = None,
Expand All @@ -33,6 +33,7 @@ def _config_initialization(
"""Parse all available options, read config files and command line arguments and
set options accordingly.
"""
linter.verbose = verbose_mode
config_file = Path(config_file) if config_file else None

# Set the current module to the configuration file
Expand Down
18 changes: 18 additions & 0 deletions pylint/lint/expand_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ def expand_modules(
if _is_ignored_file(
something, ignore_list, ignore_list_re, ignore_list_paths_re
):
result[something] = {
"path": something,
"name": "",
"isarg": False,
"basepath": something,
"basename": "",
"isignored": True,
}
continue
module_package_path = discover_package_path(something, source_roots)
additional_search_path = [".", module_package_path, *path]
Expand Down Expand Up @@ -138,6 +146,7 @@ def expand_modules(
"isarg": True,
"basepath": filepath,
"basename": modname,
"isignored": False,
}
has_init = (
not (modname.endswith(".__init__") or modname == "__init__")
Expand All @@ -153,6 +162,14 @@ def expand_modules(
if _is_in_ignore_list_re(
os.path.basename(subfilepath), ignore_list_re
) or _is_in_ignore_list_re(subfilepath, ignore_list_paths_re):
result[subfilepath] = {
"path": subfilepath,
"name": "",
"isarg": False,
"basepath": subfilepath,
"basename": "",
"isignored": True,
}
continue

modpath = _modpath_from_file(
Expand All @@ -167,5 +184,6 @@ def expand_modules(
"isarg": isarg,
"basepath": filepath,
"basename": modname,
"isignored": False,
}
return result, errors
33 changes: 25 additions & 8 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from pylint.message import Message, MessageDefinition, MessageDefinitionStore
from pylint.reporters import ReporterWarning
from pylint.reporters.base_reporter import BaseReporter
from pylint.reporters.progress_reporters import ProgressReporter
from pylint.reporters.text import ColorizedTextReporter, TextReporter
from pylint.reporters.ureports import nodes as report_nodes
from pylint.typing import (
Expand Down Expand Up @@ -398,8 +399,7 @@ def __init__(
self.option_groups_descs[opt_group[0]] = opt_group[1]
self._option_groups: tuple[tuple[str, str], ...] = (
*option_groups,
("Messages control", "Options controlling analysis messages"),
("Reports", "Options related to output formatting and reporting"),
*PyLinter.option_groups_descs.items(),
)
self.fail_on_symbols: list[str] = []
"""List of message symbols on which pylint should fail, set by --fail-on."""
Expand Down Expand Up @@ -429,6 +429,7 @@ def __init__(
self.current_file: str | None = None
self._ignore_file = False
self._ignore_paths: list[Pattern[str]] = []
self.verbose = False

self.register_checker(self)

Expand Down Expand Up @@ -762,6 +763,8 @@ def check(self, files_or_modules: Sequence[str]) -> None:
sys.path = original_sys_path
return

progress_reporter = ProgressReporter(self.verbose)

# 1) Get all FileItems
with augmented_sys_path(extra_packages_paths):
if self.config.from_stdin:
Expand All @@ -775,18 +778,26 @@ def check(self, files_or_modules: Sequence[str]) -> None:
with augmented_sys_path(extra_packages_paths):
with self._astroid_module_checker() as check_astroid_module:
# 2) Get the AST for each FileItem
ast_per_fileitem = self._get_asts(fileitems, data)
ast_per_fileitem = self._get_asts(fileitems, data, progress_reporter)

# 3) Lint each ast
self._lint_files(ast_per_fileitem, check_astroid_module)
self._lint_files(
ast_per_fileitem, check_astroid_module, progress_reporter
)

def _get_asts(
self, fileitems: Iterator[FileItem], data: str | None
self,
fileitems: Iterator[FileItem],
data: str | None,
progress_reporter: ProgressReporter,
) -> dict[FileItem, nodes.Module | None]:
"""Get the AST for all given FileItems."""
ast_per_fileitem: dict[FileItem, nodes.Module | None] = {}

progress_reporter.start_get_asts()

for fileitem in fileitems:
progress_reporter.get_ast_for_file(fileitem.filepath)
self.set_current_module(fileitem.name, fileitem.filepath)

try:
Expand Down Expand Up @@ -820,9 +831,12 @@ def _lint_files(
self,
ast_mapping: dict[FileItem, nodes.Module | None],
check_astroid_module: Callable[[nodes.Module], bool | None],
progress_reporter: ProgressReporter,
) -> None:
"""Lint all AST modules from a mapping.."""
progress_reporter.start_linting()
for fileitem, module in ast_mapping.items():
progress_reporter.lint_file(fileitem.filepath)
if module is None:
continue
try:
Expand Down Expand Up @@ -928,6 +942,7 @@ def _get_file_descr_from_stdin(self, filepath: str) -> Iterator[FileItem]:
self.config.ignore_patterns,
self.config.ignore_paths,
):
self.stats.skipped += 1
return

try:
Expand All @@ -950,7 +965,9 @@ def _iterate_file_descrs(
"""
for descr in self._expand_files(files_or_modules).values():
name, filepath, is_arg = descr["name"], descr["path"], descr["isarg"]
if self.should_analyze_file(name, filepath, is_argument=is_arg):
if descr["isignored"]:
self.stats.skipped += 1
elif self.should_analyze_file(name, filepath, is_argument=is_arg):
yield FileItem(name, filepath, descr["basename"])

def _expand_files(
Expand Down Expand Up @@ -1177,6 +1194,7 @@ def generate_reports(self, verbose: bool = False) -> int | None:

if self.config.reports:
self.reporter.display_reports(sect)

score_value = self._report_evaluation(verbose)
# save results if persistent run
if self.config.persistent:
Expand Down Expand Up @@ -1220,8 +1238,7 @@ def _report_evaluation(self, verbose: bool = False) -> int | None:

if verbose:
checked_files_count = self.stats.node_count["module"]
unchecked_files_count = self.stats.undocumented["module"]
msg += f"\nChecked {checked_files_count} files, skipped {unchecked_files_count} files"
msg += f"\nChecked {checked_files_count} files, skipped {self.stats.skipped} files/modules"

if self.config.score:
sect = report_nodes.EvaluationSection(msg)
Expand Down
16 changes: 16 additions & 0 deletions pylint/pyreverse/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,22 @@
"help": "Include standard library objects in representation of classes.",
},
),
(
"max-depth",
{
"dest": "max_depth",
"action": "store",
"default": None,
"metavar": "<depth>",
"type": "int",
"group": OPTIONS_GROUPS["FILTERING"],
"help": (
"Maximum depth in package/module hierarchy to display. A depth of 0 shows only "
"top-level packages, 1 shows one level of subpackages, etc. If not specified, "
"all packages/modules are shown."
),
},
),
# Display Options
(
"module-names",
Expand Down
Loading

0 comments on commit a2afa05

Please sign in to comment.