Skip to content

Commit

Permalink
bug 1567990: add black scaffolding and reformat scripts/
Browse files Browse the repository at this point in the history
  • Loading branch information
willkg committed Jul 23, 2019
1 parent f550a19 commit c493570
Show file tree
Hide file tree
Showing 8 changed files with 1,603 additions and 238 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ default:
@echo ""
@echo " shell - open a shell in the app container"
@echo " clean - remove all build, test, coverage and Python artifacts"
@echo " lint - check style with flake8"
@echo " lint - lint code"
@echo " lintfix - reformat code"
@echo " test - run unit tests"
@echo " testshell - open a shell for running tests"
@echo " docs - generate Sphinx HTML documentation, including API docs"
Expand Down Expand Up @@ -66,6 +67,10 @@ docs: my.env .docker-build-docs
lint: my.env
${DC} run --rm --no-deps app shell ./docker/run_lint.sh

.PHONY: lintfix
lintfix: my.env
${DC} run --rm --no-deps app shell ./docker/run_lint.sh --fix

my.env:
@if [ ! -f my.env ]; \
then \
Expand Down
29 changes: 21 additions & 8 deletions docker/run_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# Runs linting.

# Usage: docker/run_lint.sh [--fix]
#
# Runs linting and code fixing.
#
# This should be called from inside a container.

set -e

echo ">>> flake8 ($(python --version))"
cd /app
flake8
BLACKARGS=("--line-length=88" "--target-version=py36" scripts)

if [[ $1 == "--fix" ]]; then
echo ">>> black fix"
black "${BLACKARGS[@]}"

else
echo ">>> flake8 ($(python --version))"
cd /app
flake8

echo ">>> black"
black --check "${BLACKARGS[@]}"

echo ">>> eslint (js)"
cd /app/webapp-django
/webapp-frontend-deps/node_modules/.bin/eslint .
echo ">>> eslint (js)"
cd /app/webapp-django
/webapp-frontend-deps/node_modules/.bin/eslint .
fi
10 changes: 10 additions & 0 deletions requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,13 @@ zipp==0.5.1 \
importlib-metadata==0.17 \
--hash=sha256:a9f185022cfa69e9ca5f7eabfd5a58b689894cb78a11e3c8c89398a8ccbb8e7f \
--hash=sha256:df1403cd3aebeb2b1dcd3515ca062eecb5bd3ea7611f18cba81130c68707e879
toml==0.10.0 \
--hash=sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c \
--hash=sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e \
--hash=sha256:f1db651f9657708513243e61e6cc67d101a39bad662eaa9b5546f789338e07a3
click==7.0 \
--hash=sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13 \
--hash=sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7
appdirs==1.4.3 \
--hash=sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92 \
--hash=sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e
3 changes: 3 additions & 0 deletions requirements/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,6 @@ google-cloud-pubsub==0.42.1 \
sentry-sdk==0.9.5 \
--hash=sha256:692aa93637273365166041ee8e06ccd6b61d5f06560765d78828edbaac83fae1 \
--hash=sha256:7c9db0e419fb0fb31c1b1d2ec9247667d2b77bd4f3136119ee6f1464e9b088a4
black==19.3b0 \
--hash=sha256:09a9dcb7c46ed496a9850b76e4e825d6049ecd38b611f1224857a79bd985a8cf \
--hash=sha256:68950ffd4d9169716bcb8719a56c07a2f4485354fec061cdd5910aa07369731c
1,679 changes: 1,499 additions & 180 deletions scripts/insert_missing_versions.py

Large diffs are not rendered by default.

32 changes: 20 additions & 12 deletions scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_remote_name():


def make_tag(bug_number, remote_name, tag_name, commits_since_tag):
message = '\n'.join(commits_since_tag)
message = "\n".join(commits_since_tag)

if bug_number:
# Add bug number to tag
Expand All @@ -91,18 +91,24 @@ def make_tag(bug_number, remote_name, tag_name, commits_since_tag):
print("=" * 80)

# Create tag
input(">>> Ready to tag \"{}\"? Ctrl-c to cancel".format(tag_name))
input('>>> Ready to tag "{}"? Ctrl-c to cancel'.format(tag_name))
print(">>> Creating tag...")
subprocess.check_call(["git", "tag", "-s", tag_name, "-m", message])

# Push tag
input(">>> Ready to push to remote \"{}\"? Ctrl-c to cancel".format(remote_name))
input('>>> Ready to push to remote "{}"? Ctrl-c to cancel'.format(remote_name))
print(">>> Pushing...")
subprocess.check_call(["git", "push", "--tags", remote_name, tag_name])


def make_bug(remote_name, project_name, tag_name, commits_since_tag, bugzilla_product,
bugzilla_component):
def make_bug(
remote_name,
project_name,
tag_name,
commits_since_tag,
bugzilla_product,
bugzilla_component,
):
summary = f"{project_name} deploy: {tag_name}"
print(">>> Creating deploy bug...")
print(">>> Summary")
Expand Down Expand Up @@ -141,7 +147,7 @@ def make_bug(remote_name, project_name, tag_name, commits_since_tag, bugzilla_pr

def run():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='cmd')
subparsers = parser.add_subparsers(dest="cmd")
subparsers.required = True

make_bug_parser = subparsers.add_parser("make-bug", help="Make a deploy bug")
Expand Down Expand Up @@ -192,9 +198,7 @@ def run():
last_tag = check_output(
"git for-each-ref --sort=-taggerdate --count=1 --format %(tag) refs/tags"
)
last_tag_message = check_output(
f"git tag -l --format=\"%(contents)\" {last_tag}"
)
last_tag_message = check_output(f'git tag -l --format="%(contents)" {last_tag}')
print(f">>> Last tag was: {last_tag}")
print(">>> Message:")
print("=" * 80)
Expand Down Expand Up @@ -237,15 +241,19 @@ def run():
tag_name = datetime.datetime.now().strftime("%Y.%m.%d")

# If it's already taken, append a -N
existing_tags = check_output(f"git tag -l \"{tag_name}*\"").splitlines()
existing_tags = check_output(f'git tag -l "{tag_name}*"').splitlines()
if existing_tags:
index = len([x for x in existing_tags if x.startswith(tag_name)]) + 1
tag_name = f"{tag_name}-{index}"

if args.cmd == "make-bug":
make_bug(
remote_name, project_name, tag_name, commits_since_tag, args.product,
args.component
remote_name,
project_name,
tag_name,
commits_since_tag,
args.product,
args.component,
)
elif args.cmd == "make-tag":
make_tag(args.bug, remote_name, tag_name, commits_since_tag)
Expand Down
70 changes: 36 additions & 34 deletions scripts/update_siggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,17 @@


#: List of files in socorro/signature/ to ignore and not copy over
IGNORE = [
'__init__.py',
'README.rst',
'siglists/README.rst',
]
IGNORE = ["__init__.py", "README.rst", "siglists/README.rst"]


#: Name of the file that has the socorro sha in it--this helps us
#: determine what's changed since the last update.
SOCORRO_SHA_FILE = 'socorro_sha.txt'
SOCORRO_SHA_FILE = "socorro_sha.txt"


def main(argv=None):
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument(
'dest', help='location of siggen code'
)
parser.add_argument("dest", help="location of siggen code")

# Figure out destination directory
if argv is None:
Expand All @@ -43,48 +37,56 @@ def main(argv=None):

dest_dir = args.dest.rstrip(os.sep)

if os.path.exists(os.path.join(dest_dir, 'siggen')):
dest_dir = os.path.join(dest_dir, 'siggen')
if os.path.exists(os.path.join(dest_dir, "siggen")):
dest_dir = os.path.join(dest_dir, "siggen")

# Get git sha of destination
dest_sha_file = os.path.join(dest_dir, SOCORRO_SHA_FILE)
if os.path.exists(dest_sha_file):
dest_sha = open(dest_sha_file, 'r').read().strip()
dest_sha = open(dest_sha_file, "r").read().strip()
else:
dest_sha = ''
dest_sha = ""

# Get git sha of source
source_sha = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
source_sha = source_sha.decode('utf-8')
source_sha = subprocess.check_output(["git", "rev-parse", "HEAD"]).strip()
source_sha = source_sha.decode("utf-8")

print('Dest sha: %s' % dest_sha)
print('Source sha: %s' % source_sha)
print("Dest sha: %s" % dest_sha)
print("Source sha: %s" % source_sha)
if dest_sha:
git_log = subprocess.check_output([
'git', 'log', '%s..%s' % (dest_sha, source_sha), '--oneline', 'socorro/signature'
])
git_log = subprocess.check_output(
[
"git",
"log",
"%s..%s" % (dest_sha, source_sha),
"--oneline",
"socorro/signature",
]
)
# Generate log of old sha -> new sha
if git_log:
for line in git_log.splitlines():
print(line.decode('utf-8'))
print(line.decode("utf-8"))
else:
print('No differences.')
print("No differences.")
return 0
else:
print('No previous sha to determine git commits.')
print("No previous sha to determine git commits.")

confirm = input('Continue to copy? [y/N]: ')
if confirm.strip().lower() != 'y':
print('Exiting...')
confirm = input("Continue to copy? [y/N]: ")
if confirm.strip().lower() != "y":
print("Exiting...")
return 1

# Copy the files from source to destination
source_dir = os.path.join(os.path.dirname(__file__), os.pardir, 'socorro', 'signature')
source_dir = os.path.join(
os.path.dirname(__file__), os.pardir, "socorro", "signature"
)
for dirpath, dirnames, filenames in os.walk(source_dir):
relative_dirpath = dirpath[len(source_dir):].lstrip(os.sep)
relative_dirpath = dirpath[len(source_dir) :].lstrip(os.sep)

for fn in filenames:
if fn.startswith('.'):
if fn.startswith("."):
continue

# Figure out the filename relative to the source directory
Expand All @@ -97,16 +99,16 @@ def main(argv=None):
dest = os.path.join(dest_dir, fn)

# Copy the files
print('Copy: %s -> %s' % (source, dest))
print("Copy: %s -> %s" % (source, dest))
shutil.copyfile(source, dest)

# Update sha in destination
print('Generating socorro_sha file')
with open(dest_sha_file, 'w') as fp:
print("Generating socorro_sha file")
with open(dest_sha_file, "w") as fp:
fp.write(source_sha)

print('Done!')
print("Done!")


if __name__ == '__main__':
if __name__ == "__main__":
sys.exit(main())
11 changes: 8 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[flake8]
# W504: Line break occurred after binary operator
ignore = W504
ignore =
# E203: Whitespace before ':'; doesn't work with black
E203,
# E501: line too long
E501,
# W503: line break before operator; this doesn't work with black
W503
exclude =
.git/,
__pycache__,
Expand All @@ -12,7 +17,7 @@ exclude =
build/,
depot_tools/,
breakpad/
max-line-length = 100
max-line-length = 88

[tool:pytest]
# -rsxX - show skipped, failed, and passed tests
Expand Down

0 comments on commit c493570

Please sign in to comment.