add pre-commit; add line-count functions & badge

This commit is contained in:
checktheroads 2019-12-31 12:03:23 -07:00
parent cb1e1794e1
commit af42e3bcd0
8 changed files with 185 additions and 2 deletions

11
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,11 @@
repos:
# - repo: https://github.com/pre-commit/pre-commit-hooks
# rev: v2.3.0
# hooks:
# - id: flake8
- repo: local
hooks:
- id: line_count
name: Line Count
entry: hooks.sh
language: script

View file

@ -26,6 +26,7 @@ flake8-print = "*"
flake8-return = "*" flake8-return = "*"
pep8-naming = "*" pep8-naming = "*"
flake8-docstrings = "*" flake8-docstrings = "*"
pre-commit = "*"
[packages] [packages]
aredis = "==1.1.5" aredis = "==1.1.5"

44
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "ec1e8f837bd15e6e5867287b1cb9d37cf9795490ec3717899c706e918b6b33d9" "sha256": "a99eac0076ede424ed44b8be6eb1694cc358a78593fe373aa2372084c8699d92"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -609,6 +609,13 @@
], ],
"version": "==1.4.3" "version": "==1.4.3"
}, },
"aspy.yaml": {
"hashes": [
"sha256:463372c043f70160a9ec950c3f1e4c3a82db5fca01d334b6bc89c7164d744bdc",
"sha256:e7c742382eff2caed61f87a39d13f99109088e5e93f04d76eb8d4b28aa143f45"
],
"version": "==1.3.0"
},
"attrs": { "attrs": {
"hashes": [ "hashes": [
"sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c", "sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c",
@ -632,6 +639,13 @@
"index": "pypi", "index": "pypi",
"version": "==19.3b0" "version": "==19.3b0"
}, },
"cfgv": {
"hashes": [
"sha256:edb387943b665bf9c434f717bf630fa78aecd53d5900d2e05da6ad6048553144",
"sha256:fbd93c9ab0a523bf7daec408f3be2ed99a980e20b2d19b50fc184ca6b820d289"
],
"version": "==2.0.1"
},
"click": { "click": {
"hashes": [ "hashes": [
"sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13", "sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13",
@ -800,6 +814,13 @@
], ],
"version": "==3.0.5" "version": "==3.0.5"
}, },
"identify": {
"hashes": [
"sha256:6f44e637caa40d1b4cb37f6ed3b262ede74901d28b1cc5b1fc07360871edd65d",
"sha256:72e9c4ed3bc713c7045b762b0d2e2115c572b85abfc1f4604f5a4fd4c6642b71"
],
"version": "==1.4.9"
},
"importlib-metadata": { "importlib-metadata": {
"hashes": [ "hashes": [
"sha256:073a852570f92da5f744a3472af1b61e28e9f78ccf0c9117658dc32b15de7b45", "sha256:073a852570f92da5f744a3472af1b61e28e9f78ccf0c9117658dc32b15de7b45",
@ -833,6 +854,12 @@
], ],
"version": "==8.0.2" "version": "==8.0.2"
}, },
"nodeenv": {
"hashes": [
"sha256:ad8259494cf1c9034539f6cced78a1da4840a4b157e23640bc4a0c0546b0cb7a"
],
"version": "==1.3.3"
},
"pbr": { "pbr": {
"hashes": [ "hashes": [
"sha256:139d2625547dbfa5fb0b81daebb39601c478c21956dc57e2e07b74450a8c506b", "sha256:139d2625547dbfa5fb0b81daebb39601c478c21956dc57e2e07b74450a8c506b",
@ -848,6 +875,14 @@
"index": "pypi", "index": "pypi",
"version": "==0.9.1" "version": "==0.9.1"
}, },
"pre-commit": {
"hashes": [
"sha256:9f152687127ec90642a2cc3e4d9e1e6240c4eb153615cb02aa1ad41d331cbb6e",
"sha256:c2e4810d2d3102d354947907514a78c5d30424d299dc0fe48f5aa049826e9b50"
],
"index": "pypi",
"version": "==1.20.0"
},
"pycodestyle": { "pycodestyle": {
"hashes": [ "hashes": [
"sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56", "sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56",
@ -928,6 +963,13 @@
], ],
"version": "==0.10.0" "version": "==0.10.0"
}, },
"virtualenv": {
"hashes": [
"sha256:0d62c70883c0342d59c11d0ddac0d954d0431321a41ab20851facf2b222598f3",
"sha256:55059a7a676e4e19498f1aad09b8313a38fcc0cdbe4fdddc0e9b06946d21b4bb"
],
"version": "==16.7.9"
},
"zipp": { "zipp": {
"hashes": [ "hashes": [
"sha256:3718b1cbcd963c7d4c5511a8240812904164b7f381b647143a89d3b98f9bcd8e", "sha256:3718b1cbcd963c7d4c5511a8240812904164b7f381b647143a89d3b98f9bcd8e",

View file

@ -15,7 +15,7 @@ This branch is *very much* under construction. There's a 99% chance that hypergl
[**Documentation**](https://hyperglass.readthedocs.io)   |   [**Screenshots**](https://hyperglass.readthedocs.io/en/latest/screenshots/)   |   [**Live Demo**](https://hyperglass.allroads.io/) [**Documentation**](https://hyperglass.readthedocs.io)   |   [**Screenshots**](https://hyperglass.readthedocs.io/en/latest/screenshots/)   |   [**Live Demo**](https://hyperglass.allroads.io/)
[![Build Status](https://travis-ci.org/checktheroads/hyperglass.svg?branch=master)](https://travis-ci.org/checktheroads/hyperglass) [![Build Status](https://travis-ci.org/checktheroads/hyperglass.svg?branch=master)](https://travis-ci.org/checktheroads/hyperglass)
![GitHub issues](https://img.shields.io/github/issues/checktheroads/hyperglass.svg) ![LOC](https://raw.githubusercontent.com/checktheroads/hyperglass/v1.0.0/line_count.svg?sanitize=true)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
</div> </div>

34
develop.py Normal file
View file

@ -0,0 +1,34 @@
"""Devloper functions."""
import os
def count_lines(directory):
"""Count lines of code.
Arguments:
directory {str} -- Path to count
Returns:
{int} -- Line count
"""
lines = 0
excluded = ("\n",)
for thing in os.listdir(directory):
thing = os.path.join(directory, thing)
if os.path.isfile(thing):
if thing.endswith(".py"):
with open(thing, "r") as f:
readlines = [
line
for line in f.readlines()
if line not in excluded and not line.startswith("#")
]
lines += len(readlines)
for thing in os.listdir(directory):
thing = os.path.join(directory, thing)
if os.path.isdir(thing):
lines += count_lines(thing)
return lines

10
hooks.sh Executable file
View file

@ -0,0 +1,10 @@
#!/usr/bin/env bash
LC=$(./manage.py line-count-badge)
echo $LC
if [[ ! $? == 0 ]]; then
exit 1
fi
exit 0

23
line_count.svg Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="120" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<mask id="anybadge_1">
<rect width="120" height="20" rx="3" fill="#fff"/>
</mask>
<g mask="url(#anybadge_1)">
<path fill="#555" d="M0 0h90v20H0z"/>
<path fill="#007ec6" d="M90 0h30v20H90z"/>
<path fill="url(#b)" d="M0 0h120v20H0z"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="46.0" y="15" fill="#010101" fill-opacity=".3">Lines of Code</text>
<text x="45.0" y="14">Lines of Code</text>
</g>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="106.0" y="15" fill="#010101" fill-opacity=".3">3051</text>
<text x="105.0" y="14">3051</text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -842,5 +842,67 @@ def generate_secret(length):
) )
@hg.command("line-count", help="Get line count for source code.")
@click.option(
"-d",
"--directory",
type=str,
default="hyperglass",
help="Source code directory",
)
def line_count(directory):
"""Get lines of code.
Arguments:
directory {str} -- Source code directory
"""
from develop import count_lines
count = count_lines(directory)
click.echo(
NL
+ click.style("Line Count: ", fg="blue")
+ click.style(str(count), fg="green", bold=True)
+ NL
)
@hg.command("line-count-badge", help="Generates line count badge")
@click.option(
"-d",
"--directory",
type=str,
default="hyperglass",
help="Source code directory",
)
def line_count_badge(directory):
"""Generate shields.io-like badge for lines of code.
Arguments:
directory {str} -- Source code directory
Returns:
{int} -- Exit status
"""
import anybadge
from develop import count_lines
this_dir = Path.cwd()
file_name = "line_count.svg"
badge_file = this_dir / file_name
if badge_file.exists():
badge_file.unlink()
count = count_lines(directory)
badge = anybadge.Badge(label="Lines of Code", value=count, default_color="#007ec6")
badge.write_badge(file_name)
click.echo(
click.style("Created line count badge. Lines: ", fg="white")
+ click.style(str(count), fg="green", bold=True)
)
return 0
if __name__ == "__main__": if __name__ == "__main__":
hg() hg()