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

Increase maximum line length to 88 #196

Merged
merged 1 commit into from
Jul 7, 2023
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
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ score=no
[FORMAT]

# Maximum number of characters on a single line.
max-line-length=79
max-line-length=88


[DESIGN]
Expand Down
4 changes: 1 addition & 3 deletions apport/REThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
class REThread(threading.Thread):
"""Thread with return values and exception propagation."""

def __init__(
self, group=None, target=None, name=None, args=(), kwargs=None
):
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None):
"""Initialize Thread, identical to threading.Thread.__init__()."""
if kwargs is None:
kwargs = {}
Expand Down
92 changes: 23 additions & 69 deletions apport/crashdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,14 @@
self.format_version = 3

init = (
not os.path.exists(path)
or path == ":memory:"
or os.path.getsize(path) == 0
not os.path.exists(path) or path == ":memory:" or os.path.getsize(path) == 0
)
self.duplicate_db = dbapi2.connect(path, timeout=7200)

if init:
cur = self.duplicate_db.cursor()
cur.execute("CREATE TABLE version (format INTEGER NOT NULL)")
cur.execute(
"INSERT INTO version VALUES (?)", [self.format_version]
)
cur.execute("INSERT INTO version VALUES (?)", [self.format_version])

cur.execute(
"""CREATE TABLE crashes (
Expand Down Expand Up @@ -160,9 +156,7 @@
it can be explicitly passed to this function if it is already
available.
"""
assert (
self.duplicate_db
), "init_duplicate_db() needs to be called before"
assert self.duplicate_db, "init_duplicate_db() needs to be called before"

if not report:
report = self.download(crash_id)
Expand Down Expand Up @@ -197,8 +191,7 @@
if (
not ex_ver
or not report_package_version
or packaging.compare_versions(report_package_version, ex_ver)
< 0
or packaging.compare_versions(report_package_version, ex_ver) < 0
):
master_id = ex_id
master_ver = ex_ver
Expand Down Expand Up @@ -246,9 +239,7 @@
# if we don't have one already
if sig:
cur = self.duplicate_db.cursor()
cur.execute(
"SELECT count(*) FROM crashes WHERE crash_id == ?", [crash_id]
)
cur.execute("SELECT count(*) FROM crashes WHERE crash_id == ?", [crash_id])
count_id = cur.fetchone()[0]
if count_id == 0:
cur.execute(
Expand Down Expand Up @@ -341,9 +332,7 @@
version specifies the package version the crash was fixed in (None for
'still unfixed').
"""
assert (
self.duplicate_db
), "init_duplicate_db() needs to be called before"
assert self.duplicate_db, "init_duplicate_db() needs to be called before"

cur = self.duplicate_db.cursor()
n = cur.execute(
Expand All @@ -360,22 +349,16 @@

This happens when a report got rejected or manually duplicated.
"""
assert (
self.duplicate_db
), "init_duplicate_db() needs to be called before"
assert self.duplicate_db, "init_duplicate_db() needs to be called before"

cur = self.duplicate_db.cursor()
cur.execute("DELETE FROM crashes WHERE crash_id = ?", [crash_id])
cur.execute(
"DELETE FROM address_signatures WHERE crash_id = ?", [crash_id]
)
cur.execute("DELETE FROM address_signatures WHERE crash_id = ?", [crash_id])
self.duplicate_db.commit()

def duplicate_db_change_master_id(self, old_id, new_id):
"""Change a crash ID."""
assert (
self.duplicate_db
), "init_duplicate_db() needs to be called before"
assert self.duplicate_db, "init_duplicate_db() needs to be called before"

cur = self.duplicate_db.cursor()
cur.execute(
Expand Down Expand Up @@ -407,9 +390,7 @@
then moved to the given name in an almost atomic way.
"""
# hard to change, pylint: disable=consider-using-with
assert (
self.duplicate_db
), "init_duplicate_db() needs to be called before"
assert self.duplicate_db, "init_duplicate_db() needs to be called before"

# first create the temporary new dir; if that fails, nothing has been
# changed and we fail early
Expand Down Expand Up @@ -449,9 +430,7 @@
cur_hash = None
cur_file = None

cur.execute(
"SELECT signature, crash_id from crashes ORDER BY signature"
)
cur.execute("SELECT signature, crash_id from crashes ORDER BY signature")
for sig, crash_id in cur.fetchall():
h = self.duplicate_sig_hash(sig)
if h is None:
Expand Down Expand Up @@ -480,9 +459,7 @@
# Format 3 added a primary key which can't be done as an upgrade in
# SQLite
if cur_format < 3:
raise SystemError(
"Cannot upgrade database from format earlier than 3"
)
raise SystemError("Cannot upgrade database from format earlier than 3")

Check warning on line 462 in apport/crashdb.py

View check run for this annotation

Codecov / codecov/patch

apport/crashdb.py#L462

Added line #L462 was not covered by tests

cur = self.duplicate_db.cursor()

Expand Down Expand Up @@ -538,8 +515,7 @@
cur = self.duplicate_db.cursor()

cur.execute(
"SELECT crash_id FROM address_signatures WHERE signature == ?",
[sig],
"SELECT crash_id FROM address_signatures WHERE signature == ?", [sig]
)
existing_ids = cur.fetchall()
assert len(existing_ids) <= 1
Expand All @@ -558,9 +534,7 @@

This is mainly useful for debugging and test suites.
"""
assert (
self.duplicate_db
), "init_duplicate_db() needs to be called before"
assert self.duplicate_db, "init_duplicate_db() needs to be called before"

dump = {}
cur = self.duplicate_db.cursor()
Expand All @@ -580,14 +554,10 @@
An invalid ID gets removed from the duplicate db, and a crash which got
fixed is marked as such in the database.
"""
assert (
self.duplicate_db
), "init_duplicate_db() needs to be called before"
assert self.duplicate_db, "init_duplicate_db() needs to be called before"

cur = self.duplicate_db.cursor()
cur.execute(
"SELECT fixed_version FROM crashes WHERE crash_id = ?", [crash_id]
)
cur.execute("SELECT fixed_version FROM crashes WHERE crash_id = ?", [crash_id])
db_fixed_version = cur.fetchone()
if not db_fixed_version:
return
Expand All @@ -597,10 +567,7 @@

# crash got rejected
if real_fixed_version == "invalid":
print(
f"DEBUG: bug {crash_id} was invalidated,"
f" removing from database"
)
print(f"DEBUG: bug {crash_id} was invalidated," f" removing from database")

Check warning on line 570 in apport/crashdb.py

View check run for this annotation

Codecov / codecov/patch

apport/crashdb.py#L570

Added line #L570 was not covered by tests
self.duplicate_db_remove(crash_id)
return

Expand Down Expand Up @@ -634,8 +601,7 @@
else:
cur = self.duplicate_db.cursor()
cur.execute(
"INSERT INTO address_signatures VALUES (?, ?)",
(_u(sig), crash_id),
"INSERT INTO address_signatures VALUES (?, ?)", (_u(sig), crash_id)
)
self.duplicate_db.commit()

Expand All @@ -645,9 +611,7 @@
This is necessary when having to mark a bug as a duplicate if it
already is in the duplicate DB.
"""
assert (
self.duplicate_db
), "init_duplicate_db() needs to be called before"
assert self.duplicate_db, "init_duplicate_db() needs to be called before"

cur = self.duplicate_db.cursor()
cur.execute("DELETE FROM crashes WHERE crash_id = ?", [dup])
Expand Down Expand Up @@ -680,9 +644,7 @@
# Abstract functions that need to be implemented by subclasses
#

def upload(
self, report, progress_callback=None, user_message_callback=None
):
def upload(self, report, progress_callback=None, user_message_callback=None):
"""Upload given problem report return a handle for it.

This should happen noninteractively.
Expand Down Expand Up @@ -936,9 +898,7 @@
'bug_pattern_url', 'dupdb_url', and 'problem_types'.
"""
if not conf:
conf = os.environ.get(
"APPORT_CRASHDB_CONF", "/etc/apport/crashdb.conf"
)
conf = os.environ.get("APPORT_CRASHDB_CONF", "/etc/apport/crashdb.conf")
settings = {}
with open(conf, encoding="utf-8") as f:
# legacy, pylint: disable=exec-used
Expand All @@ -953,10 +913,7 @@
try:
with open(cfpath, encoding="utf-8") as f:
# legacy, pylint: disable=exec-used
exec(
compile(f.read(), cfpath, "exec"),
settings["databases"],
)
exec(compile(f.read(), cfpath, "exec"), settings["databases"])

Check warning on line 916 in apport/crashdb.py

View check run for this annotation

Codecov / codecov/patch

apport/crashdb.py#L916

Added line #L916 was not covered by tests
except Exception as error: # pylint: disable=broad-except
# ignore broken files
sys.stderr.write(f"Invalid file {cfpath}: {error}\n")
Expand All @@ -973,9 +930,6 @@
spec is a crash db configuration dictionary as described in get_crashdb().
"""
m = __import__(
f"apport.crashdb_impl.{spec['impl']}",
globals(),
locals(),
["CrashDatabase"],
f"apport.crashdb_impl.{spec['impl']}", globals(), locals(), ["CrashDatabase"]
)
return m.CrashDatabase(auth_file, spec)
20 changes: 6 additions & 14 deletions apport/crashdb_impl/debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,20 @@
"""Check if this report can be uploaded to this database.
Checks for the proper settings of apport.
"""
if (
not self.options.get("sender")
and "UnreportableReason" not in report
):
if not self.options.get("sender") and "UnreportableReason" not in report:

Check warning on line 47 in apport/crashdb_impl/debian.py

View check run for this annotation

Codecov / codecov/patch

apport/crashdb_impl/debian.py#L47

Added line #L47 was not covered by tests
report[
"UnreportableReason"
] = "Please configure sender settings in /etc/apport/crashdb.conf"

# At this time, we are not ready to take CrashDumps
if "Stacktrace" in report and not report.has_useful_stacktrace():
report["UnreportableReason"] = (
"Incomplete backtrace."
" Please install the debug symbol packages"
)
report[

Check warning on line 54 in apport/crashdb_impl/debian.py

View check run for this annotation

Codecov / codecov/patch

apport/crashdb_impl/debian.py#L54

Added line #L54 was not covered by tests
"UnreportableReason"
] = "Incomplete backtrace. Please install the debug symbol packages"

return apport.crashdb.CrashDatabase.accepts(self, report)

def upload(
self, report, progress_callback=None, user_message_callback=None
):
def upload(self, report, progress_callback=None, user_message_callback=None):

Check warning on line 60 in apport/crashdb_impl/debian.py

View check run for this annotation

Codecov / codecov/patch

apport/crashdb_impl/debian.py#L60

Added line #L60 was not covered by tests
"""Upload given problem report return a handle for it.

In Debian, we use BTS, which is heavily email oriented. This method
Expand All @@ -82,9 +76,7 @@
with tempfile.NamedTemporaryFile() as temp:
temp.file.write(f"Package: {buggy_package}\n".encode("UTF-8"))
temp.file.write(f"Version: {buggy_version}\n\n\n".encode("UTF-8"))
temp.file.write(
("=============================\n\n").encode("UTF-8")
)
temp.file.write(("=============================\n\n").encode("UTF-8"))

Check warning on line 79 in apport/crashdb_impl/debian.py

View check run for this annotation

Codecov / codecov/patch

apport/crashdb_impl/debian.py#L79

Added line #L79 was not covered by tests

# Let's remove the CoreDump first

Expand Down
24 changes: 6 additions & 18 deletions apport/crashdb_impl/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
if self.__access_token:
headers["Authorization"] = f"token {self.__access_token}"
try:
result = requests.post(
url, headers=headers, data=data, timeout=5.0
)
result = requests.post(url, headers=headers, data=data, timeout=5.0)

Check warning on line 50 in apport/crashdb_impl/github.py

View check run for this annotation

Codecov / codecov/patch

apport/crashdb_impl/github.py#L50

Added line #L50 was not covered by tests
except requests.RequestException as err:
self.message_callback(
"Failed connection",
Expand Down Expand Up @@ -89,9 +87,7 @@
url = response["verification_uri"]
code = response["user_code"]

self.message_callback(
"Login required", prompt.format(url=url, code=code)
)
self.message_callback("Login required", prompt.format(url=url, code=code))

self.__authentication_data = {
"client_id": self.__client_id,
Expand Down Expand Up @@ -121,8 +117,7 @@
waittime = self.__cooldown - (current_time - self.__last_request)
if current_time + waittime > self.__expiry:
self.message_callback(
"Failed login",
"Github authentication expired. Please try again.",
"Failed login", "Github authentication expired. Please try again."
)
raise RuntimeError("Github authentication expired")
if waittime > 0:
Expand Down Expand Up @@ -183,10 +178,7 @@
return github

def upload(
self,
report: apport.Report,
progress_callback=None,
user_message_callback=None,
self, report: apport.Report, progress_callback=None, user_message_callback=None
) -> IssueHandle:
"""Upload given problem report return a handle for it.
In Github, we open an issue.
Expand All @@ -199,9 +191,7 @@
raise RuntimeError("Failed to login to Github")

data = self._format_report(report)
if not (
self.repository_name is None and self.repository_owner is None
):
if not (self.repository_name is None and self.repository_owner is None):
response = self.github.api_open_issue(
self.repository_owner, self.repository_name, data
)
Expand All @@ -216,9 +206,7 @@

return IssueHandle(url=response["html_url"])

def get_comment_url(
self, report: apport.Report, handle: IssueHandle
) -> str:
def get_comment_url(self, report: apport.Report, handle: IssueHandle) -> str:
"""Return a URL that should be opened after report has been uploaded
and upload() returned handle.
"""
Expand Down