Skip to content

Commit

Permalink
Add autoflake to fix flake issues
Browse files Browse the repository at this point in the history
  • Loading branch information
naddeoa authored and lalmei committed Apr 16, 2021
1 parent 5460a3f commit 36195d1
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 67 deletions.
13 changes: 13 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[flake8]
exclude =
.tox
build
dist
.eggs
docs
src/whylogs/proto
tests
max-line-length = 160
extend-ignore = E203, W503
max-complexity = 20

8 changes: 2 additions & 6 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Please take a look at this doc before contributing to whylogs python.



## Code format

The following run the linter (flake8) and formatter (black). It fails if it finds issues but they won't be automatically resolved.
Expand Down Expand Up @@ -124,12 +126,6 @@ bump2version dev --verbose --dry-run [--allow-dirty]
bump2version dev --verbose
```

To run tests against different Python, we use tox:
```
make test-all
```
You can keep bumping the local version if you need to (you can't republish a version twice so this is needed).

### 2. Pushing to master branch

* If you are planning to push to `master` branch, please first create a dev version (see the above guide).
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
src.python := $(shell find ./src -type f -name "*.py")
tst.python := $(shell find ./tests -type f -name "*.py")
tst.notebooks.python := $(shell find ./test_notebooks -type f -name "*.py")
src.python.pyc := $(shell find ./src -type f -name "*.pyc")
src.proto.dir := ./proto/src
src.proto := $(shell find $(src.proto.dir) -type f -name "*.proto")
Expand Down Expand Up @@ -68,7 +69,7 @@ lint: ## check code with flake8

lint-fix: ## automatically fix linting issues
@$(call i, Running the linter)
poetry run autopep8 -r --in-place .
poetry run autoflake --in-place --remove-unused-variables $(src.python) $(tst.python) $(tst.notebooks.python)

format: ## Check formatting with black
@$(call i, Checking formatting)
Expand Down
58 changes: 49 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ sphinx-rtd-theme = "^0.5.2"
autoapi = "^2.0.1"
sphinx-autoapi = "^1.8.0"
sphinx-autodoc-typehints = "^1.12.0"
watchdog = {extras = ["watchmedo"], version = "^2.0.2"}
watchdog = { extras = ["watchmedo"], version = "^2.0.2" }
isort = "^5.8.0"
autopep8 = "^1.5.6"
autoflake = "^1.4"
flake8 = "^3.9.1"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand All @@ -61,4 +62,8 @@ multi_line_output = 3

[tool.black]
line-length = 160
target-version = "py39"
target-version = ["py38"]
include_trailing_comma = "True"
force_grid_wrap = 0
use_parentheses = "True"
ensure_newline_before_comments = "True"
13 changes: 0 additions & 13 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,6 @@ build_dir = build/sphinx
no-vcs = 1
formats = bdist_wheel

[flake8]
# Some sane defaults for the code style checker flake8
exclude =
.tox
build
dist
.eggs
docs
src/whylogs/proto
tests
max-line-length = 160
max-complexity = 20

[coverage:run]
branch = True
source = whylogs
Expand Down
2 changes: 0 additions & 2 deletions src/whylogs/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,11 @@ def load_config(path_to_config: str = None):
return session_config
except IOError as e:
logger.warning("Failed to load YAML config", e)
pass
else:
try:
with open(path_to_config, "rt") as f:
session_config = SessionConfig.from_yaml(f)
return session_config
except IOError as e:
logger.warning("Failed to load YAML config", e)
pass
return None
1 change: 0 additions & 1 deletion src/whylogs/mlflow/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def _close(self):
name,
self._active_run_id,
)
pass
logger.debug("Finished uploading all the loggers")
self._active_run_id = None

Expand Down
1 change: 0 additions & 1 deletion test_notebooks/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys

import pytest

Expand Down
6 changes: 4 additions & 2 deletions test_notebooks/notebook_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
import subprocess

import nbformat
import pytest
from nbconvert.preprocessors import CellExecutionError, ExecutePreprocessor

TEST_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_DIR = os.path.join(TEST_DIR, os.pardir)


def process_notebook(notebook_filename, html_directory="notebook-html"):
"""Checks if an IPython notebook runs without error from start to finish. If so, writes the notebook to HTML (with outputs) and overwrites the .ipynb file (without outputs)."""
"""
Checks if an IPython notebook runs without error from start to finish. If so, writes the
notebook to HTML (with outputs) and overwrites the .ipynb file (without outputs).
"""

with open(notebook_filename) as f:
nb = nbformat.read(f, as_version=4)
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/app/test_log_rotation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import datetime
import os
import shutil
import time
import unittest

import pytest
from freezegun import freeze_time
Expand Down
8 changes: 3 additions & 5 deletions tests/unit/app/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


def test_get_global_session():
_session = None
session = get_or_create_session()

global_session = get_session()
Expand All @@ -23,18 +22,18 @@ def test_get_global_session():

def test_reset():

session = get_or_create_session()
get_or_create_session()
reset_default_session()
global_session = get_session()
assert global_session.project is not None


def test_session_log_dataframe():
_session = None
pass

session = session_from_config(SessionConfig("default-project", "default-pipeline", [], False))
df = util.testing.makeDataFrame()
profile = session.log_dataframe(df)
session.log_dataframe(df)

assert session.logger() is not None

Expand Down Expand Up @@ -86,7 +85,6 @@ def test_close_session():


def test_logger_cache():
_session = None
session = get_or_create_session()
with session.logger("cache-test", with_rotation_time="s") as logger:
logger.log({"name": 1})
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/app/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ def test_non_valid_type(tmpdir):

config = WriterConfig(type="blob", formats=["json"], output_path=tmpdir)
with pytest.raises(ValueError):
writer = writer_from_config(config)
writer_from_config(config)
1 change: 0 additions & 1 deletion tests/unit/cli/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import shutil

from click.testing import CliRunner

Expand Down
4 changes: 1 addition & 3 deletions tests/unit/core/metrics/test_model_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def tests_model_metrics_to_protobuf_classification():
predictions_1 = ["cat", "dog", "dog"]
scores_1 = [0.1, 0.2, 0.4]

expected_1 = [[1, 0, 0], [0, 1, 1], [0, 0, 0]]

mod_met.compute_confusion_matrix(predictions_1, targets_1, scores_1)

message = mod_met.to_protobuf()
Expand Down Expand Up @@ -83,7 +81,7 @@ def test_merge_metrics_with_none_confusion_matrix():
metrics = ModelMetrics()
other = ModelMetrics()
other.confusion_matrix = None
new_metrics = metrics.merge(other)
metrics.merge(other)


def test_merge_metrics_model():
Expand Down
1 change: 0 additions & 1 deletion tests/unit/core/statistics/test_hllsketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def test_serialize_then_merge_does_not_fail():

def test_protobuf_then_merge():
hll = hllsketch.HllSketch()
vals = [1, 2, 3]
hll2 = hllsketch.HllSketch.from_protobuf(hll.to_protobuf())
hll2.merge(hll2)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/core/test_annotation_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_track_json_annotation():

now = datetime.datetime.utcnow()
shared_session_id = uuid4().hex
num_bb_features = len(BB_ATTRIBUTES)
len(BB_ATTRIBUTES)

test_annotation_path = os.path.join(TEST_DATA_PATH, "files", "yolo_bounding_box.jsonl")

Expand Down
6 changes: 2 additions & 4 deletions tests/unit/core/test_datasetprofile_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ def test_dataset_profile_metrics():
predictions_1 = ["cat", "dog", "dog"]
scores_1 = [0.1, 0.2, 0.4]

expected_1 = [[1, 0, 0], [0, 1, 1], [0, 0, 0]]

x1.track_metrics(predictions_1, targets_1, scores_1)

assert x1.model_profile.metrics.confusion_matrix.labels is not None
Expand All @@ -46,12 +44,12 @@ def test_read_java_protobuf():


def test_parse_from_protobuf_with_regression():
dir_path = os.path.dirname(os.path.realpath(__file__))
os.path.dirname(os.path.realpath(__file__))
prof = DatasetProfile.read_protobuf(os.path.join(TEST_DATA_PATH, "metrics", "regression_java.bin"))
assert prof.name == "my-model-name"
assert prof.model_profile is not None
assert prof.model_profile.metrics is not None
confusion_M = prof.model_profile.metrics.confusion_matrix
prof.model_profile.metrics.confusion_matrix
regression_met = prof.model_profile.metrics.regression_metrics
assert regression_met is not None
# metrics
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/core/test_rect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import math

from whylogs.core.annotation_profiling import Rectangle


Expand Down
Loading

0 comments on commit 36195d1

Please sign in to comment.