Skip to content
Open
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
9 changes: 5 additions & 4 deletions src/wily/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Main command line."""

import sys
import traceback
from pathlib import Path

Expand Down Expand Up @@ -406,12 +407,12 @@ def clean(ctx, yes):

if not exists(config):
logger.info(_("Wily cache does not exist, nothing to remove."))
exit(0)
sys.exit(0)

if not yes:
p = input(_("Are you sure you want to delete wily cache? [y/N]"))
if p.lower() != "y":
exit(0)
sys.exit(0)

from wily.cache import clean

Expand Down Expand Up @@ -446,7 +447,7 @@ def handle_no_cache(context):
)
p = input(_("Do you want to run setup and index your project now? [y/N]"))
if p.lower() != "y":
exit(1)
sys.exit(1)
else:
revisions = input(_("How many previous git revisions do you want to index? : "))
revisions = int(revisions)
Expand All @@ -461,6 +462,6 @@ def handle_no_cache(context):
except Exception as runtime:
logger.error(f"Oh no, Wily crashed! See {WILY_LOG_NAME} for information.")
logger.info(
f"If you think this crash was unexpected, please raise an issue at https://github.com/tonybaloney/wily/issues and copy the log file into the issue report along with some information on what you were doing."
"If you think this crash was unexpected, please raise an issue at https://github.com/tonybaloney/wily/issues and copy the log file into the issue report along with some information on what you were doing."
)
logger.debug(traceback.format_exc())
10 changes: 5 additions & 5 deletions src/wily/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def exists(config):
return False
index_path = pathlib.Path(config.cache_path) / "index.json"
if index_path.exists():
with open(index_path) as out:
with open(index_path, encoding="utf8") as out:
index = json.load(out)
if index["version"] != __version__:
# TODO: Inspect the versions properly.
Expand All @@ -54,7 +54,7 @@ def create_index(config):
"""Create the root index."""
filename = pathlib.Path(config.cache_path) / "index.json"
index = {"version": __version__}
with open(filename, "w") as out:
with open(filename, "w", encoding="utf8") as out:
out.write(json.dumps(index, indent=2))


Expand Down Expand Up @@ -138,7 +138,7 @@ def store(config, archiver, revision, stats):
filename = root / (revision.key + ".json")
if filename.exists():
raise RuntimeError(f"File {filename} already exists, index may be corrupt.")
with open(filename, "w") as out:
with open(filename, "w", encoding="utf8") as out:
out.write(json.dumps(stats, indent=2))
return filename

Expand Down Expand Up @@ -167,9 +167,9 @@ def store_archiver_index(config, archiver, index):
index = sorted(index, key=lambda k: k["date"], reverse=True)

filename = root / "index.json"
with open(filename, "w") as out:
with open(filename, "w", encoding="utf8") as out:
out.write(json.dumps(index, indent=2))
logger.debug(f"Created index output")
logger.debug("Created index output")
return filename


Expand Down
5 changes: 3 additions & 2 deletions src/wily/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import multiprocessing
import os
import pathlib
import sys

from progress.bar import Bar

Expand Down Expand Up @@ -70,15 +71,15 @@ def build(config, archiver, operators):
revisions = archiver.revisions(config.path, config.max_revisions)
except InvalidGitRepositoryError:
# TODO: This logic shouldn't really be here (SoC)
logger.info(f"Defaulting back to the filesystem archiver, not a valid git repo")
logger.info("Defaulting back to the filesystem archiver, not a valid git repo")
archiver = FilesystemArchiver(config)
revisions = archiver.revisions(config.path, config.max_revisions)
except Exception as e:
if hasattr(e, "message"):
logger.error(f"Failed to setup archiver: '{e.message}'")
else:
logger.error(f"Failed to setup archiver: '{type(e)} - {e}'")
exit(1)
sys.exit(1)

state = State(config, archiver=archiver)
# Check for existence of cache, else provision
Expand Down
3 changes: 2 additions & 1 deletion src/wily/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import multiprocessing
import os
import sys
from pathlib import Path

import radon.cli.harvest
Expand Down Expand Up @@ -75,7 +76,7 @@ def diff(config, files, metrics, changes_only=True, detail=True, revision=None):
logger.error(
f"Revision {revision} is not in the cache, make sure you have run wily build."
)
exit(1)
sys.exit(1)

logger.info(
f"Comparing current with {format_revision(target_revision.revision.key)} by {target_revision.revision.author_name} on {format_date(target_revision.revision.date)}."
Expand Down
1 change: 0 additions & 1 deletion src/wily/commands/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

TODO: Add multiple lines for multiple files
"""
import pathlib

import plotly.graph_objs as go
import plotly.offline
Expand Down
7 changes: 4 additions & 3 deletions src/wily/commands/rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""
import operator as op
import os
import sys
from pathlib import Path

import radon.cli.harvest
Expand All @@ -17,7 +18,7 @@
from wily import format_date, format_revision, logger
from wily.archivers import resolve_archiver
from wily.config import DEFAULT_GRID_STYLE, DEFAULT_PATH
from wily.operators import MetricType, resolve_metric_as_tuple
from wily.operators import resolve_metric_as_tuple
from wily.state import State


Expand Down Expand Up @@ -65,7 +66,7 @@ def rank(config, path, metric, revision_index, limit, threshold, descending):
logger.error(
f"Revision {revision_index} is not in the cache, make sure you have run wily build."
)
exit(1)
sys.exit(1)

logger.info(
f"-----------Rank for {metric.description} for {format_revision(target_revision.revision.key)} by {target_revision.revision.author_name} on {format_date(target_revision.revision.date)}.------------"
Expand Down Expand Up @@ -123,4 +124,4 @@ def rank(config, path, metric, revision_index, limit, threshold, descending):
logger.error(
f"Total value below the specified threshold: {total} < {threshold}"
)
exit(1)
sys.exit(1)
1 change: 0 additions & 1 deletion src/wily/commands/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pathlib import Path
from shutil import copytree
from string import Template
from typing import List

import tabulate

Expand Down
2 changes: 1 addition & 1 deletion src/wily/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from functools import lru_cache
from typing import Any, List

import wily.operators as operators
from wily import operators
from wily.archivers import ARCHIVER_GIT

logger = logging.getLogger(__name__)
Expand Down
5 changes: 2 additions & 3 deletions src/wily/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from dataclasses import asdict, dataclass
from typing import List

import wily.cache as cache
from wily import logger
from wily import cache, logger
from wily.archivers import Revision, resolve_archiver
from wily.operators import get_metric

Expand Down Expand Up @@ -88,7 +87,7 @@ def get_paths(self, config, archiver, operator):
self._data = cache.get(
config=config, archiver=archiver, revision=self.revision.key
)["operator_data"]
logger.debug(f"Fetching keys")
logger.debug("Fetching keys")
return list(self._data[operator].keys())

def store(self, config, archiver, stats):
Expand Down
15 changes: 7 additions & 8 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import shutil
import tempfile
from textwrap import dedent
from time import time

import pytest
from click.testing import CliRunner
Expand All @@ -19,7 +18,7 @@ def gitdir(tmpdir):
testpath = tmppath / "src" / "test.py"
(tmppath / "src").mkdir()
# Write a test file to the repo
with open(testpath, "w") as test_txt:
with open(testpath, "w", encoding="utf8") as test_txt:
test_txt.write("import abc")

index = repo.index
Expand All @@ -46,7 +45,7 @@ class Class1(object):
def method(self):
b = 1 + 5
"""
with open(testpath, "w") as test_txt:
with open(testpath, "w", encoding="utf8") as test_txt:
test_txt.write(dedent(first_test))

index.add([str(testpath)])
Expand All @@ -70,7 +69,7 @@ def method(self):
return 'banana'
"""

with open(testpath, "w") as test_txt:
with open(testpath, "w", encoding="utf8") as test_txt:
test_txt.write(dedent(second_test))

index.add([str(testpath)])
Expand Down Expand Up @@ -141,7 +140,7 @@ def ipynbgitdir(tmpdir):
testpath = tmppath / "src" / "test.ipynb"
(tmppath / "src").mkdir()
# Write a test file to the repo
with open(testpath, "w") as test_txt:
with open(testpath, "w", encoding="utf8") as test_txt:
test_txt.write('{"cells": [],' + _NB_FOOTER + "}")

index = repo.index
Expand Down Expand Up @@ -178,7 +177,7 @@ def ipynbgitdir(tmpdir):
+ _NB_FOOTER
+ "}"
)
with open(testpath, "w") as test_txt:
with open(testpath, "w", encoding="utf8") as test_txt:
test_txt.write(dedent(first_test))

index.add([str(testpath)])
Expand Down Expand Up @@ -228,7 +227,7 @@ def ipynbgitdir(tmpdir):
+ "}"
)

with open(testpath, "w") as test_txt:
with open(testpath, "w", encoding="utf8") as test_txt:
test_txt.write(dedent(second_test))

index.add([str(testpath)])
Expand All @@ -251,7 +250,7 @@ def ipynbbuilddir(ipynbgitdir):
ipynb_cells = true
"""
config_path = tmppath / "wily.cfg"
with open(config_path, "w") as config_f:
with open(config_path, "w", encoding="utf8") as config_f:
config_f.write(config)

runner = CliRunner()
Expand Down
6 changes: 4 additions & 2 deletions test/integration/test_all_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def method(self):
print(1)
"""

with open(pathlib.Path(gitdir) / "src" / "test.py", "w") as test_py:
with open(
pathlib.Path(gitdir) / "src" / "test.py", "w", encoding="utf8"
) as test_py:
test_py.write(dedent(complex_test))

result = runner.invoke(
Expand Down Expand Up @@ -115,7 +117,7 @@ def single_comments(): pass
author = Actor("An author", "[email protected]")
committer = Actor("A committer", "[email protected]")

with open(testpath, "w") as test_py:
with open(testpath, "w", encoding="utf8") as test_py:
test_py.write(dedent(code_with_metric_named_objects))

with Repo.init(path=tmpdir) as repo:
Expand Down
12 changes: 6 additions & 6 deletions test/integration/test_archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def test_git_end_to_end(tmpdir):
committer = Actor("A committer", "[email protected]")

# First commit
with open(tmppath / ".gitignore", "w") as ignore:
with open(tmppath / ".gitignore", "w", encoding="utf8") as ignore:
ignore.write(".wily/")
index.add([".gitignore"])
commit1 = index.commit("commit1", author=author, committer=committer)

# Second commit
with open(tmppath / "test.py", "w") as file1:
with open(tmppath / "test.py", "w", encoding="utf8") as file1:
file1.write("print(1)")
index.add(["test.py"])
commit2 = index.commit("commit2", author=author, committer=committer)
Expand Down Expand Up @@ -74,14 +74,14 @@ def test_dirty_git(tmpdir):
committer = Actor("A committer", "[email protected]")

# First commit
with open(tmppath / ".gitignore", "w") as ignore:
with open(tmppath / ".gitignore", "w", encoding="utf8") as ignore:
ignore.write(".wily/")

index.add([".gitignore"])
commit1 = index.commit("commit1", author=author, committer=committer)

# Write a test file to the repo
with open(tmppath / "blah.py", "w") as ignore:
with open(tmppath / "blah.py", "w", encoding="utf8") as ignore:
ignore.write("*.py[co]\n")
index.add(["blah.py"])
repo.close()
Expand All @@ -104,14 +104,14 @@ def test_detached_head(tmpdir):
committer = Actor("A committer", "[email protected]")

# First commit
with open(tmppath / "test.py", "w") as ignore:
with open(tmppath / "test.py", "w", encoding="utf8") as ignore:
ignore.write("print('hello world')")

index.add(["test.py"])
commit1 = index.commit("commit1", author=author, committer=committer)

# Second commit
with open(tmppath / "test.py", "w") as ignore:
with open(tmppath / "test.py", "w", encoding="utf8") as ignore:
ignore.write("print('hello world')\nprint(1)")

index.add(["test.py"])
Expand Down
14 changes: 7 additions & 7 deletions test/integration/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_build_crash(tmpdir):
tmppath = pathlib.Path(tmpdir)

# Write a test file to the repo
with open(tmppath / "test.py", "w") as test_txt:
with open(tmppath / "test.py", "w", encoding="utf8") as test_txt:
test_txt.write("import abc")

index = repo.index
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_build(tmpdir, cache_path):
tmppath = pathlib.Path(tmpdir)

# Write a test file to the repo
with open(tmppath / "test.py", "w") as test_txt:
with open(tmppath / "test.py", "w", encoding="utf8") as test_txt:
test_txt.write("import abc")

index = repo.index
Expand Down Expand Up @@ -141,11 +141,11 @@ def test_build_with_config(tmpdir, cache_path):
operators = raw, maintainability
"""
config_path = tmppath / "wily.cfg"
with open(config_path, "w") as config_f:
with open(config_path, "w", encoding="utf8") as config_f:
config_f.write(config)

# Write a test file to the repo
with open(tmppath / "test.py", "w") as test_txt:
with open(tmppath / "test.py", "w", encoding="utf8") as test_txt:
test_txt.write("import abc")

index = repo.index
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_build_twice(tmpdir, cache_path):
tmppath = pathlib.Path(tmpdir)

# Write a test file to the repo
with open(tmppath / "test.py", "w") as test_txt:
with open(tmppath / "test.py", "w", encoding="utf8") as test_txt:
test_txt.write("import abc")

index = repo.index
Expand All @@ -215,7 +215,7 @@ def test_build_twice(tmpdir, cache_path):
assert rev_path.exists()

# Write a test file to the repo
with open(tmppath / "test.py", "w") as test_txt:
with open(tmppath / "test.py", "w", encoding="utf8") as test_txt:
test_txt.write("import abc\nfoo = 1")

index.add(["test.py"])
Expand Down Expand Up @@ -254,7 +254,7 @@ def test_build_dirty_repo(builddir):
Test that build fails cleanly with a dirty repo
"""
tmppath = pathlib.Path(builddir)
with open(tmppath / "test.py", "w") as test_txt:
with open(tmppath / "test.py", "w", encoding="utf8") as test_txt:
test_txt.write("import abc\nfoo = 1")

runner = CliRunner()
Expand Down
Loading