Skip to content

Commit

Permalink
Merge pull request #475 from dgasmith/lint
Browse files Browse the repository at this point in the history
Lint Black, iSort, and Autoflake
  • Loading branch information
dgasmith authored Nov 8, 2019
2 parents 68be719 + 4503ff1 commit 1554ed1
Show file tree
Hide file tree
Showing 112 changed files with 4,741 additions and 4,395 deletions.
51 changes: 51 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.DEFAULT_GOAL := all
isort = isort -rc qcfractal
black = black qcfractal
autoflake = autoflake -ir --remove-all-unused-imports --ignore-init-module-imports --remove-unused-variables --exclude="*/tests/*,*/versions/*,*/models/*" qcfractal

.PHONY: install
install:
pip install -e .

.PHONY: format
format:
$(autoflake)
$(isort)
$(black)

.PHONY: lint
lint:
$(isort) --check-only
$(black) --check

.PHONY: check-dist
check-dist:
python setup.py check -ms
python setup.py sdist
twine check dist/*

.PHONY: mypy
mypy:
mypy qcfractal

.PHONY: test
test:
pytest -v --cov=qcfractal/

.PHONY: clean
clean:
rm -rf `find . -name __pycache__`
rm -f `find . -type f -name '*.py[co]' `
rm -f `find . -type f -name '*~' `
rm -f `find . -type f -name '.*~' `
rm -rf .cache
rm -rf .pytest_cache
rm -rf .mypy_cache
rm -rf htmlcov
rm -rf *.egg-info
rm -f .coverage
rm -f .coverage.*
rm -rf build
rm -rf dist
rm -f qcfractal/*.c qcfractal/*.so
python setup.py clean
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.black]
line-length = 120
target-version = ['py37']
7 changes: 5 additions & 2 deletions qcfractal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
"""

from . import interface

# Handle versioneer
from .extras import get_information

# Handle top level object imports
from .postgres_harness import PostgresHarness, TemporaryPostgres
from .queue import QueueManager
from .server import FractalServer
from .snowflake import FractalSnowflake, FractalSnowflakeHandler

# Import modules
from .storage_sockets import storage_socket_factory

__version__ = get_information('version')
__git_revision__ = get_information('git_revision')
__version__ = get_information("version")
__git_revision__ = get_information("git_revision")
del get_information
48 changes: 23 additions & 25 deletions qcfractal/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
try:
dispcmd = str([c] + args)
# remember shell=False, so use git.cmd on windows, not just git
p = subprocess.Popen([c] + args,
cwd=cwd,
env=env,
stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr else None))
p = subprocess.Popen(
[c] + args, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=(subprocess.PIPE if hide_stderr else None)
)
break
except EnvironmentError:
e = sys.exc_info()[1]
Expand All @@ -91,7 +89,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
return None, None
else:
if verbose:
print("unable to find command, tried %s" % (commands, ))
print("unable to find command, tried %s" % (commands,))
return None, None
stdout = p.communicate()[0].strip()
if sys.version_info[0] >= 3:
Expand All @@ -117,11 +115,11 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
dirname = os.path.basename(root)
if dirname.startswith(parentdir_prefix):
return {
"version": dirname[len(parentdir_prefix):],
"version": dirname[len(parentdir_prefix) :],
"full-revisionid": None,
"dirty": False,
"error": None,
"date": None
"date": None,
}
else:
rootdirs.append(root)
Expand Down Expand Up @@ -184,7 +182,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
TAG = "tag: "
tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
if not tags:
# Either we're using git < 1.8.3, or there really are no tags. We use
# a heuristic: assume all version tags have a digit. The old git %d
Expand All @@ -193,23 +191,23 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
# between branches and tags. By ignoring refnames without digits, we
# filter out many common branch names like "release" and
# "stabilization", as well as "HEAD" and "master".
tags = set([r for r in refs if re.search(r'\d', r)])
tags = set([r for r in refs if re.search(r"\d", r)])
if verbose:
print("discarding '%s', no digits" % ",".join(refs - tags))
if verbose:
print("likely tags: %s" % ",".join(sorted(tags)))
for ref in sorted(tags):
# sorting will prefer e.g. "2.0" over "2.0rc1"
if ref.startswith(tag_prefix):
r = ref[len(tag_prefix):]
r = ref[len(tag_prefix) :]
if verbose:
print("picking %s" % r)
return {
"version": r,
"full-revisionid": keywords["full"].strip(),
"dirty": False,
"error": None,
"date": date
"date": date,
}
# no suitable tags, so version is "0+unknown", but full hex is still there
if verbose:
Expand All @@ -219,7 +217,7 @@ def git_versions_from_keywords(keywords, tag_prefix, verbose):
"full-revisionid": keywords["full"].strip(),
"dirty": False,
"error": "no suitable tags",
"date": None
"date": None,
}


Expand All @@ -244,8 +242,8 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
# if there isn't one, this yields HEX[-dirty] (no NUM)
describe_out, rc = run_command(
GITS, ["describe", "--tags", "--dirty", "--always", "--long", "--match",
"%s*" % tag_prefix], cwd=root)
GITS, ["describe", "--tags", "--dirty", "--always", "--long", "--match", "%s*" % tag_prefix], cwd=root
)
# --long was added in git-1.5.5
if describe_out is None:
raise NotThisMethod("'git describe' failed")
Expand All @@ -268,16 +266,16 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
dirty = git_describe.endswith("-dirty")
pieces["dirty"] = dirty
if dirty:
git_describe = git_describe[:git_describe.rindex("-dirty")]
git_describe = git_describe[: git_describe.rindex("-dirty")]

# now we have TAG-NUM-gHEX or HEX

if "-" in git_describe:
# TAG-NUM-gHEX
mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
if not mo:
# unparseable. Maybe git-describe is misbehaving?
pieces["error"] = ("unable to parse git-describe output: '%s'" % describe_out)
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
return pieces

# tag
Expand All @@ -286,9 +284,9 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
if verbose:
fmt = "tag '%s' doesn't start with prefix '%s'"
print(fmt % (full_tag, tag_prefix))
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" % (full_tag, tag_prefix))
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (full_tag, tag_prefix)
return pieces
pieces["closest-tag"] = full_tag[len(tag_prefix):]
pieces["closest-tag"] = full_tag[len(tag_prefix) :]

# distance: number of commits since tag
pieces["distance"] = int(mo.group(2))
Expand Down Expand Up @@ -453,7 +451,7 @@ def render(pieces, style):
"full-revisionid": pieces.get("long"),
"dirty": None,
"error": pieces["error"],
"date": None
"date": None,
}

if not style or style == "default":
Expand All @@ -479,7 +477,7 @@ def render(pieces, style):
"full-revisionid": pieces["long"],
"dirty": pieces["dirty"],
"error": None,
"date": pieces.get("date")
"date": pieces.get("date"),
}


Expand All @@ -503,15 +501,15 @@ def get_versions():
# versionfile_source is the relative path from the top of the source
# tree (where the .git directory might live) to this file. Invert
# this to find the root from __file__.
for i in cfg.versionfile_source.split('/'):
for i in cfg.versionfile_source.split("/"):
root = os.path.dirname(root)
except NameError:
return {
"version": "0+unknown",
"full-revisionid": None,
"dirty": None,
"error": "unable to find root of source tree",
"date": None
"date": None,
}

try:
Expand All @@ -531,5 +529,5 @@ def get_versions():
"full-revisionid": None,
"dirty": None,
"error": "unable to compute version",
"date": None
"date": None,
}
23 changes: 6 additions & 17 deletions qcfractal/alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@

from logging.config import fileConfig

import yaml
from alembic import context
from sqlalchemy import engine_from_config, pool

from alembic import context
from qcfractal.config import FractalConfig
from qcfractal.storage_sockets.models import Base

# this is the Alembic Config object, which provides
Expand All @@ -30,8 +27,8 @@
# ... etc.

# Overwrite the ini-file sqlalchemy.url path
uri = context.get_x_argument(as_dictionary=True).get('uri')
config.set_main_option('sqlalchemy.url', uri)
uri = context.get_x_argument(as_dictionary=True).get("uri")
config.set_main_option("sqlalchemy.url", uri)


def run_migrations_offline():
Expand All @@ -47,10 +44,7 @@ def run_migrations_offline():
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True,
compare_type = compare_type
)
context.configure(url=url, target_metadata=target_metadata, literal_binds=True, compare_type=compare_type)

with context.begin_transaction():
context.run_migrations()
Expand All @@ -64,16 +58,11 @@ def run_migrations_online():
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
config.get_section(config.config_ini_section), prefix="sqlalchemy.", poolclass=pool.NullPool
)

with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata,
compare_type = compare_type
)
context.configure(connection=connection, target_metadata=target_metadata, compare_type=compare_type)

with context.begin_transaction():
context.run_migrations()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@

import os
import sys

sys.path.insert(1, os.path.dirname(os.path.abspath(__file__)))
from migration_helpers import msgpack_migrations
from qcelemental.util import msgpackext_dumps, msgpackext_loads

# revision identifiers, used by Alembic.
revision = '05ceea11b78a'
down_revision = '8b0cd9accaf2'
revision = "05ceea11b78a"
down_revision = "8b0cd9accaf2"
branch_labels = None
depends_on = None

Expand Down
5 changes: 3 additions & 2 deletions qcfractal/alembic/versions/1134312ad4a3_results_msgpack_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

import os
import sys

sys.path.insert(1, os.path.dirname(os.path.abspath(__file__)))
from migration_helpers import msgpack_migrations

# revision identifiers, used by Alembic.
revision = '1134312ad4a3'
down_revision = '84c94a48e491'
revision = "1134312ad4a3"
down_revision = "84c94a48e491"
branch_labels = None
depends_on = None

Expand Down
Loading

0 comments on commit 1554ed1

Please sign in to comment.