Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove outdated information from the PYLINT_HOME help #5204

Merged
merged 4 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 8 additions & 26 deletions pylint/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@
import sys
from datetime import datetime

import platformdirs

from pylint.config.configuration_mixin import ConfigurationMixIn
from pylint.config.find_default_config_files import find_default_config_files
from pylint.config.find_default_config_files import (
find_default_config_files,
find_pylintrc,
)
from pylint.config.man_help_formatter import _ManHelpFormatter
from pylint.config.option import Option
from pylint.config.option_manager_mixin import OptionsManagerMixIn
from pylint.config.option_parser import OptionParser
from pylint.config.options_provider_mixin import OptionsProviderMixIn, UnsupportedAction
from pylint.constants import DEFAULT_PYLINT_HOME, OLD_DEFAULT_PYLINT_HOME
from pylint.utils import LinterStats

__all__ = [
Expand All @@ -68,9 +70,9 @@
if USER_HOME == "~":
USER_HOME = os.path.dirname(PYLINT_HOME)
elif USER_HOME == "~":
PYLINT_HOME = ".pylint.d"
PYLINT_HOME = OLD_DEFAULT_PYLINT_HOME
else:
PYLINT_HOME = platformdirs.user_cache_dir("pylint")
PYLINT_HOME = DEFAULT_PYLINT_HOME
# The spam prevention is due to pylint being used in parallel by
# pre-commit, and the message being spammy in this context
# Also if you work with old version of pylint that recreate the
Expand All @@ -80,7 +82,7 @@
PYLINT_HOME,
datetime.now().strftime(prefix_spam_prevention + "_%Y-%m-%d.temp"),
)
old_home = os.path.join(USER_HOME, ".pylint.d")
old_home = os.path.join(USER_HOME, OLD_DEFAULT_PYLINT_HOME)
if os.path.exists(old_home) and not os.path.exists(spam_prevention_file):
print(
f"PYLINTHOME is now '{PYLINT_HOME}' but obsolescent '{old_home}' is found; "
Expand Down Expand Up @@ -140,24 +142,4 @@ def save_results(results, base):
print(f"Unable to create file {data_file}: {ex}", file=sys.stderr)


def find_pylintrc():
"""search the pylint rc file and return its path if it find it, else None"""
for config_file in find_default_config_files():
if config_file.endswith("pylintrc"):
return config_file

return None


PYLINTRC = find_pylintrc()

ENV_HELP = """
The following environment variables are used:
* PYLINTHOME
Path to the directory where persistent data for the run will be stored. If
not found, it defaults to ~/.pylint.d/ or .pylint.d (in the current working
directory).
* PYLINTRC
Path to the configuration file. See the documentation for the method used
to search for configuration file.
"""
11 changes: 10 additions & 1 deletion pylint/config/find_default_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import configparser
import os
from typing import Iterator, Optional

import toml
from toml import TomlDecodeError
Expand Down Expand Up @@ -30,7 +31,7 @@ def _cfg_has_config(path):
return any(section.startswith("pylint.") for section in parser.sections())


def find_default_config_files():
def find_default_config_files() -> Iterator[str]:
"""Find all possible config files."""
rc_names = ("pylintrc", ".pylintrc")
config_names = rc_names + ("pyproject.toml", "setup.cfg")
Expand Down Expand Up @@ -67,3 +68,11 @@ def find_default_config_files():

if os.path.isfile("/etc/pylintrc"):
yield "/etc/pylintrc"


def find_pylintrc() -> Optional[str]:
"""search the pylint rc file and return its path if it find it, else None"""
for config_file in find_default_config_files():
if config_file.endswith("pylintrc"):
return config_file
return None
6 changes: 6 additions & 0 deletions pylint/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys

import astroid
import platformdirs

from pylint.__pkginfo__ import __version__

Expand Down Expand Up @@ -39,6 +40,11 @@
# on all project using [MASTER] in their rcfile.
MAIN_CHECKER_NAME = "master"

# pylint: disable-next=fixme
# TODO Remove in 3.0 with all the surrounding code
OLD_DEFAULT_PYLINT_HOME = ".pylint.d"
DEFAULT_PYLINT_HOME = platformdirs.user_cache_dir("pylint")


class WarningScope:
LINE = "line-based-msg"
Expand Down
19 changes: 16 additions & 3 deletions pylint/lint/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import sys
import warnings

from pylint import __pkginfo__, config, extensions, interfaces
from pylint.constants import full_version
from pylint import __pkginfo__, extensions, interfaces
from pylint.constants import DEFAULT_PYLINT_HOME, OLD_DEFAULT_PYLINT_HOME, full_version
from pylint.lint.pylinter import PyLinter
from pylint.lint.utils import ArgumentPreprocessingError, preprocess_options
from pylint.utils import print_full_documentation, utils
Expand Down Expand Up @@ -269,7 +269,20 @@ def __init__(
# load command line plugins
linter.load_plugin_modules(self._plugins)
# add some help section
linter.add_help_section("Environment variables", config.ENV_HELP, level=1)
linter.add_help_section(
"Environment variables",
f"""
The following environment variables are used:
* PYLINTHOME
Path to the directory where persistent data for the run will be stored. If
not found, it defaults to '{DEFAULT_PYLINT_HOME}' or '{OLD_DEFAULT_PYLINT_HOME}'
(in the current working directory).
* PYLINTRC
Path to the configuration file. See the documentation for the method used
to search for configuration file.
""",
level=1,
)
linter.add_help_section(
"Output",
"Using the default text output, the message format is : \n"
Expand Down
5 changes: 3 additions & 2 deletions tests/lint/unittest_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
MSG_STATE_CONFIDENCE,
MSG_STATE_SCOPE_CONFIG,
MSG_STATE_SCOPE_MODULE,
OLD_DEFAULT_PYLINT_HOME,
)
from pylint.exceptions import InvalidMessageError
from pylint.lint import ArgumentPreprocessingError, PyLinter, Run, preprocess_options
Expand Down Expand Up @@ -668,13 +669,13 @@ def pop_pylintrc() -> None:
def test_pylint_home() -> None:
uhome = os.path.expanduser("~")
if uhome == "~":
expected = ".pylint.d"
expected = OLD_DEFAULT_PYLINT_HOME
else:
expected = platformdirs.user_cache_dir("pylint")
assert config.PYLINT_HOME == expected

try:
pylintd = join(tempfile.gettempdir(), ".pylint.d")
pylintd = join(tempfile.gettempdir(), OLD_DEFAULT_PYLINT_HOME)
os.environ["PYLINTHOME"] = pylintd
try:
reload(config)
Expand Down