Skip to content

Commit

Permalink
[CI] Improve automated checks (#2702)
Browse files Browse the repository at this point in the history
* same stuff, but with some more spurious error supression

* fix issue in permissions found in this

* fix a few more spurious errors

* fix another issue

* semi-spurious error fixes

* .

* formatting

* move this to properly log

* distutils import + virtualenv

* more fixes
  • Loading branch information
Michael H authored and Kowlin committed Jun 2, 2019
1 parent 9116cd0 commit 16443c8
Show file tree
Hide file tree
Showing 20 changed files with 205 additions and 43 deletions.
148 changes: 148 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
[MASTER]

# Specify a configuration file.
#rcfile=

# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=pytest

# Pickle collected data for later comparisons.
persistent=no

# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=

# DO NOT CHANGE THIS VALUE # Use multiple processes to speed up Pylint.
jobs=1

# Allow loading of arbitrary C extensions. Extensions are imported into the
# active Python interpreter and may run arbitrary code.
unsafe-load-any-extension=no

# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code
extension-pkg-whitelist=

# Allow optimization of some AST trees. This will activate a peephole AST
# optimizer, which will apply various small optimizations. For instance, it can
# be used to obtain the result of joining multiple strings with the addition
# operator. Joining a lot of strings can lead to a maximum recursion error in
# Pylint and this flag can prevent that. It has one side effect, the resulting
# AST will be different than the one from reality.
optimize-ast=no


[MESSAGES CONTROL]

# Only show warnings with the listed confidence levels. Leave empty to show
# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED
confidence=

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time. See also the "--disable" option for examples.


enable=all

disable=C, # black is enforcing this for us already, incompatibly
W, # unbroaden this to the below specifics later on.
W0107, # uneccessary pass is stylisitc in most places
W0212, # Should likely refactor around protected access warnings later
W1203, # fstrings are too fast to care about enforcing this.
W0612, # unused vars can sometimes indicate an issue, but ...
W1401, # Should probably fix the reason this is disabled (start up screen)
W0511, # Nope, todos are fine for future people to see things to do.
W0613, # Too many places where we need to take unused args do to d.py ... also menus
W0221, # Overriden converters.
W0223, # abstractmethod not defined in mixins is expected
I, # ...
R # While some of these have merit, It's too large a burden to enable this right now.


[REPORTS]

output-format=parseable
files-output=no
reports=no


[LOGGING]

# Logging modules to check that the string format arguments are in logging
# function parameter format
logging-modules=logging


[TYPECHECK]

# Tells whether missing members accessed in mixin class should be ignored. A
# mixin class is detected if its name ends with "mixin" (case insensitive).
ignore-mixin-members=yes

# TODO: Write a plyint plugin to allow this with these mixin classes
# To use the abstractmethod we know will be defined in the final class.
ignored-classes=redbot.cogs.mod.movetocore.MoveToCore,
redbot.cogs.mod.kickban.KickBanMixin,
redbot.cogs.mod.mutes.MuteMixin,
redbot.cogs.mod.names.ModInfo,
redbot.cogs.mod.settings.ModSettings,
redbot.cogs.mod.events.Events

ignored-modules=distutils # https://github.com/PyCQA/pylint/issues/73


[VARIABLES]

# Tells whether we should check for unused import in __init__ files.
init-import=no

# A regular expression matching the name of dummy variables (i.e. expectedly
# not used).
dummy-variables-rgx=_$|dummy


[SIMILARITIES]

# Minimum lines number of a similarity.
min-similarity-lines=4

# Ignore comments when computing similarities.
ignore-comments=yes

# Ignore docstrings when computing similarities.
ignore-docstrings=yes

# Ignore imports when computing similarities.
ignore-imports=no


[MISCELLANEOUS]

# List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO


[CLASSES]

# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,__new__,__call__

# List of valid names for the first argument in a class method.
valid-classmethod-first-arg=cls

# List of valid names for the first argument in a metaclass class method.
valid-metaclass-classmethod-first-arg=mcs

# List of member names, which should be excluded from the protected access
# warning.
exclude-protected=

[EXCEPTIONS]

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception,discord.DiscordException
12 changes: 6 additions & 6 deletions redbot/cogs/audio/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import platform
import shutil
import asyncio
import asyncio.subprocess
import asyncio.subprocess # disables for # https://github.com/PyCQA/pylint/issues/1469
import logging
import re
import tempfile
Expand Down Expand Up @@ -42,7 +42,7 @@ class ServerManager:
def __init__(self) -> None:
self.ready = asyncio.Event()

self._proc: Optional[asyncio.subprocess.Process] = None
self._proc: Optional[asyncio.subprocess.Process] = None # pylint:disable=no-member
self._monitor_task: Optional[asyncio.Task] = None
self._shutdown: bool = False

Expand All @@ -67,7 +67,7 @@ async def start(self) -> None:
shutil.copyfile(BUNDLED_APP_YML, LAVALINK_APP_YML)

args = await self._get_jar_args()
self._proc = await asyncio.subprocess.create_subprocess_exec(
self._proc = await asyncio.subprocess.create_subprocess_exec( # pylint:disable=no-member
*args,
cwd=str(LAVALINK_DOWNLOAD_DIR),
stdout=asyncio.subprocess.PIPE,
Expand Down Expand Up @@ -117,7 +117,7 @@ async def _get_java_version() -> Tuple[int, int]:
"""
This assumes we've already checked that java exists.
"""
_proc: asyncio.subprocess.Process = await asyncio.create_subprocess_exec(
_proc: asyncio.subprocess.Process = await asyncio.create_subprocess_exec( # pylint:disable=no-member
"java", "-version", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
# java -version outputs to stderr
Expand Down Expand Up @@ -173,7 +173,7 @@ async def _monitor(self) -> None:
await self.start()
else:
log.critical(
"Your Java is borked. Please find the hs_err_pid{}.log file"
"Your Java is borked. Please find the hs_err_pid%d.log file"
" in the Audio data folder and report this issue.",
self._proc.pid,
)
Expand Down Expand Up @@ -222,7 +222,7 @@ async def _is_up_to_date(cls):
return True
args = await cls._get_jar_args()
args.append("--version")
_proc = await asyncio.subprocess.create_subprocess_exec(
_proc = await asyncio.subprocess.create_subprocess_exec( # pylint:disable=no-member
*args,
cwd=str(LAVALINK_DOWNLOAD_DIR),
stdout=asyncio.subprocess.PIPE,
Expand Down
8 changes: 5 additions & 3 deletions redbot/cogs/cleanup/cleanup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re
from datetime import datetime, timedelta
from typing import Union, List, Callable, Set
Expand All @@ -8,12 +9,13 @@
from redbot.core.bot import Red
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils.mod import slow_deletion, mass_purge
from redbot.cogs.mod.log import log
from redbot.core.utils.predicates import MessagePredicate
from .converters import RawMessageIds

_ = Translator("Cleanup", __file__)

log = logging.getLogger("red.cleanup")


@cog_i18n(_)
class Cleanup(commands.Cog):
Expand Down Expand Up @@ -302,13 +304,13 @@ async def between(
author = ctx.author
try:
mone = await channel.fetch_message(one)
except discord.errors.Notfound:
except discord.errors.NotFound:
return await ctx.send(
_("Could not find a message with the ID of {id}.".format(id=one))
)
try:
mtwo = await channel.fetch_message(two)
except discord.errors.Notfound:
except discord.errors.NotFound:
return await ctx.send(
_("Could not find a message with the ID of {id}.".format(id=two))
)
Expand Down
4 changes: 3 additions & 1 deletion redbot/cogs/economy/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ async def slot_machine(author, channel, bid):
sign = " "
if i == 1:
sign = ">"
slot += "{}{} {} {}\n".format(sign, *[c.value for c in row])
slot += "{}{} {} {}\n".format(
sign, *[c.value for c in row] # pylint: disable=no-member
)

payout = PAYOUTS.get(rows[1])
if not payout:
Expand Down
3 changes: 2 additions & 1 deletion redbot/cogs/mod/events.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import logging
from datetime import datetime
from collections import defaultdict, deque

import discord
from redbot.core import i18n, modlog, commands
from redbot.core.utils.mod import is_mod_or_superior
from . import log
from .abc import MixinMeta

_ = i18n.Translator("Mod", __file__)
log = logging.getLogger("red.mod")


class Events(MixinMeta):
Expand Down
3 changes: 2 additions & 1 deletion redbot/cogs/mod/kickban.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import contextlib
import logging
from collections import namedtuple
from datetime import datetime, timedelta
from typing import cast, Optional, Union
Expand All @@ -10,8 +11,8 @@
from redbot.core.utils.mod import is_allowed_by_hierarchy, get_audit_reason
from .abc import MixinMeta
from .converters import RawUserIds
from .log import log

log = logging.getLogger("red.mod")
_ = i18n.Translator("Mod", __file__)


Expand Down
4 changes: 0 additions & 4 deletions redbot/cogs/mod/log.py

This file was deleted.

3 changes: 2 additions & 1 deletion redbot/cogs/mod/movetocore.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import logging
import asyncio
import contextlib

import discord
from redbot.core import commands, checks, i18n
from redbot.core.utils.chat_formatting import box
from .abc import MixinMeta
from .log import log

log = logging.getLogger("red.mod")
_ = i18n.Translator("Mod", __file__)


Expand Down
6 changes: 3 additions & 3 deletions redbot/cogs/permissions/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
COMMAND = "COMMAND"
GLOBAL = 0

_OldConfigSchema = Dict[int, Dict[str, Dict[str, Dict[str, Dict[str, List[int]]]]]]
_NewConfigSchema = Dict[str, Dict[int, Dict[str, Dict[int, bool]]]]

# The strings in the schema are constants and should get extracted, but not translated until
# runtime.
translate = _
Expand Down Expand Up @@ -625,9 +628,6 @@ async def _maybe_update_schema(self) -> None:
await self.config.custom(COMMAND).set(new_cmd_rules)
await self.config.version.set(__version__)

_OldConfigSchema = Dict[int, Dict[str, Dict[str, Dict[str, Dict[str, List[int]]]]]]
_NewConfigSchema = Dict[str, Dict[int, Dict[str, Dict[int, bool]]]]

@staticmethod
def _get_updated_schema(
old_config: _OldConfigSchema
Expand Down
12 changes: 4 additions & 8 deletions redbot/cogs/streams/streamtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def make_embed(self, data):
status = "Untitled broadcast"
if is_rerun:
status += " - Rerun"
embed = discord.Embed(title=status, url=url)
embed = discord.Embed(title=status, url=url, color=0x6441A4)
embed.set_author(name=channel["display_name"])
embed.add_field(name="Followers", value=channel["followers"])
embed.add_field(name="Total views", value=channel["views"])
Expand All @@ -224,7 +224,6 @@ def make_embed(self, data):
embed.set_image(url=rnd(data["stream"]["preview"]["medium"]))
if channel["game"]:
embed.set_footer(text="Playing: " + channel["game"])
embed.color = 0x6441A4

return embed

Expand Down Expand Up @@ -260,14 +259,13 @@ def make_embed(self, data):
livestream = data["livestream"][0]
channel = livestream["channel"]
url = channel["channel_link"]
embed = discord.Embed(title=livestream["media_status"], url=url)
embed = discord.Embed(title=livestream["media_status"], url=url, color=0x98CB00)
embed.set_author(name=livestream["media_name"])
embed.add_field(name="Followers", value=channel["followers"])
embed.set_thumbnail(url=base_url + channel["user_logo"])
if livestream["media_thumbnail"]:
embed.set_image(url=rnd(base_url + livestream["media_thumbnail"]))
embed.set_footer(text="Playing: " + livestream["category_name"])
embed.color = 0x98CB00

return embed

Expand Down Expand Up @@ -310,7 +308,7 @@ def make_embed(self, data):
embed.set_thumbnail(url=default_avatar)
if data["thumbnail"]:
embed.set_image(url=rnd(data["thumbnail"]["url"]))
embed.color = 0x4C90F3
embed.color = 0x4C90F3 # pylint: disable=assigning-non-slot
if data["type"] is not None:
embed.set_footer(text="Playing: " + data["type"]["name"])
return embed
Expand Down Expand Up @@ -345,13 +343,12 @@ def make_embed(self, data):
)
url = "https://picarto.tv/" + data["name"]
thumbnail = data["thumbnails"]["web"]
embed = discord.Embed(title=data["title"], url=url)
embed = discord.Embed(title=data["title"], url=url, color=0x4C90F3)
embed.set_author(name=data["name"])
embed.set_image(url=rnd(thumbnail))
embed.add_field(name="Followers", value=data["followers"])
embed.add_field(name="Total views", value=data["viewers_total"])
embed.set_thumbnail(url=avatar)
embed.color = 0x132332
data["tags"] = ", ".join(data["tags"])

if not data["tags"]:
Expand All @@ -362,6 +359,5 @@ def make_embed(self, data):
else:
data["adult"] = ""

embed.color = 0x4C90F3
embed.set_footer(text="{adult}Category: {category} | Tags: {tags}".format(**data))
return embed
3 changes: 2 additions & 1 deletion redbot/core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def _is_submodule(parent, child):
return parent == child or child.startswith(parent + ".")


class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin):
# barely spurious warning caused by our intentional shadowing
class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: disable=no-member
"""Mixin for the main bot class.
This exists because `Red` inherits from `discord.AutoShardedClient`, which
Expand Down
Loading

0 comments on commit 16443c8

Please sign in to comment.