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

noahp/pre commit #66

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Since version 2.23 (released in August 2019), git-blame has a feature
# to ignore or bypass certain commits.
#
# This file contains a list of commits that are not likely what you
# are looking for in a blame, such as mass reformatting or renaming.
# You can set this file as a default ignore file for blame by running
# the following command.
#
# git config blame.ignoreRevsFile .git-blame-ignore-revs

080da73af700e06ef1e65d606076d7ac66f97325 # Run pre-commit run --all-files
64 changes: 64 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files # prevents giant files from being committed.
- id: check-case-conflict # checks for files that would conflict in case-insensitive filesystems.
- id: check-executables-have-shebangs # ensures that (non-binary) executables have a shebang.
- id: check-json # checks json files for parseable syntax.
- id: check-shebang-scripts-are-executable # ensures that (non-binary) files with a shebang are executable.
- id: check-merge-conflict # checks for files that contain merge conflict strings.
- id: check-symlinks # checks for symlinks which do not point to anything.
# - id: check-vcs-permalinks # ensures that links to vcs websites are permalinks.
- id: check-yaml # checks yaml files for parseable syntax.
args: ["--allow-multiple-documents"]
- id: destroyed-symlinks # detects symlinks which are changed to regular files with a content of a path which that symlink was pointing to.
- id: detect-private-key # detects the presence of private keys.
- id: end-of-file-fixer # ensures that a file is either empty, or ends with one newline.
- id: file-contents-sorter # sorts the lines in specified files (defaults to alphabetical). you must provide list of target files as input in your .pre-commit-config.yaml file.
- id: fix-byte-order-marker # removes utf-8 byte order marker.
- id: mixed-line-ending # replaces or checks mixed line ending.
- id: requirements-txt-fixer # sorts entries in requirements.txt.
- id: trailing-whitespace # trims trailing whitespace.

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.4
hooks:
- id: prettier
files: \.(js|ts|jsx|tsx|css|less|html|json|markdown|md|yaml|yml)$
exclude: .vscode

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.19.2
hooks:
- id: check-github-actions
- id: check-github-workflows

- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: v5.11.3
hooks:
- id: isort
args: [--profile=black]

- repo: https://github.com/pryorda/dockerfilelint-precommit-hooks
rev: v0.1.0
hooks:
- id: dockerfilelint

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.2
hooks:
- id: shellcheck

- repo: https://github.com/noahp/markdown-toc-cli
rev: 0.1.1
hooks:
- id: markdown-toc-cli
2 changes: 1 addition & 1 deletion puncover/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__author__ = 'behrens'
__author__ = "behrens"
20 changes: 12 additions & 8 deletions puncover/backtrace_helper.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import re

from puncover import collector

class BacktraceHelper():

class BacktraceHelper:
def __init__(self, collector):
self.collector = collector

Expand All @@ -24,8 +25,7 @@ def f(match):

return self.derive_functions_symbols_pattern.sub(f, text)


def deepest_call_tree(self, f, list_attribute, cache_attribute, visited = None):
def deepest_call_tree(self, f, list_attribute, cache_attribute, visited=None):
# TODO: find strongly connected components and count cycles correctly
if cache_attribute in f:
return f[cache_attribute]
Expand All @@ -35,18 +35,22 @@ def deepest_call_tree(self, f, list_attribute, cache_attribute, visited = None):

for c in f[list_attribute]:
if c not in visited:
candidate = self.deepest_call_tree(c, list_attribute, cache_attribute, visited)
candidate = self.deepest_call_tree(
c, list_attribute, cache_attribute, visited
)
if candidate[0] > result[0]:
result = candidate


result = (result[0] + f.get(collector.STACK_SIZE, 0), [f] + result[1])
f[cache_attribute] = result
return result


def deepest_callee_tree(self, f):
return self.deepest_call_tree(f, collector.CALLEES, collector.DEEPEST_CALLEE_TREE)
return self.deepest_call_tree(
f, collector.CALLEES, collector.DEEPEST_CALLEE_TREE
)

def deepest_caller_tree(self, f):
return self.deepest_call_tree(f, collector.CALLERS, collector.DEEPEST_CALLER_TREE)
return self.deepest_call_tree(
f, collector.CALLERS, collector.DEEPEST_CALLER_TREE
)
9 changes: 5 additions & 4 deletions puncover/builders.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import abc
import os
from os.path import dirname

from puncover.backtrace_helper import BacktraceHelper


class Builder:

def __init__(self, collector, src_root):
self.files = {}
self.collector = collector
Expand All @@ -25,7 +25,7 @@ def build(self):
self.build_call_trees()

def needs_build(self):
return any([os.path.getmtime(f) > t for f,t in self.files.items()])
return any([os.path.getmtime(f) > t for f, t in self.files.items()])

def build_if_needed(self):
if self.needs_build():
Expand All @@ -46,9 +46,10 @@ def build_call_trees(self):


class ElfBuilder(Builder):

def __init__(self, collector, src_root, elf_file, su_dir):
Builder.__init__(self, collector, src_root if src_root else dirname(dirname(elf_file)))
Builder.__init__(
self, collector, src_root if src_root else dirname(dirname(elf_file))
)
self.store_file_time(elf_file, store_empty=True)
self.elf_file = elf_file
self.su_dir = su_dir
Expand Down
Loading