Skip to content

Commit

Permalink
Add pre-commit linter (#54)
Browse files Browse the repository at this point in the history
* Add pre-commit linter and checks

* Add precommit as dev dependency

* Add merged session.py
  • Loading branch information
michaelshin committed May 19, 2023
1 parent f78ce4e commit 21d26cc
Show file tree
Hide file tree
Showing 51 changed files with 799 additions and 220 deletions.
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.267'
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-ast
- id: check-yaml
- id: check-added-large-files
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
1 change: 0 additions & 1 deletion deepview_profile/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import enum
import sys

import deepview_profile
Expand Down
15 changes: 7 additions & 8 deletions deepview_profile/analysis/request_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from concurrent.futures import ThreadPoolExecutor

from deepview_profile.analysis.runner import analyze_project
from deepview_profile.config import Config
from deepview_profile.exceptions import AnalysisError
from deepview_profile.nvml import NVML
import deepview_profile.protocol_gen.innpv_pb2 as pm
Expand Down Expand Up @@ -135,7 +134,7 @@ def _handle_analysis_request(self, analysis_request, context):
except AnalysisError as ex:
self._enqueue_response(self._send_analysis_error, ex, context)

except:
except Exception:
logger.exception(
'Exception occurred when handling analysis request.')
self._enqueue_response(
Expand Down Expand Up @@ -164,38 +163,38 @@ def _send_breakdown_response(self, breakdown, context):
# Called from the main executor. Do not call directly!
try:
self._message_sender.send_breakdown_response(breakdown, context)
except:
except Exception:
logger.exception(
'Exception occurred when sending a breakdown response.')

def _send_analysis_error(self, exception, context):
# Called from the main executor. Do not call directly!
try:
self._message_sender.send_analysis_error(exception, context)
except:
except Exception:
logger.exception(
'Exception occurred when sending an analysis error.')

def _send_throughput_response(self, throughput, context):
# Called from the main executor. Do not call directly!
try:
self._message_sender.send_throughput_response(throughput, context)
except:
except Exception:
logger.exception(
'Exception occurred when sending a throughput response.')

def _send_habitat_response(self, habitat_resp, context):
# Called from the main executor. Do not call directly!
try:
self._message_sender.send_habitat_response(habitat_resp, context)
except:
except Exception:
logger.exception(
'Exception occurred when sending a DeepView.Predict response.')

def _send_energy_response(self, energy_resp, context):
# Called from the main executor. Do not call directly!
try:
self._message_sender.send_energy_response(energy_resp, context)
except:
except Exception:
logger.exception(
'Exception occurred when sending an energy response.')
'Exception occurred when sending an energy response.')
Loading

0 comments on commit 21d26cc

Please sign in to comment.