Skip to content

Commit 161fb63

Browse files
committed
Add pre-commit support with black and linting with flake8 #77
- Add .flake8 and .pre-commit-config.yaml - Add GitHub actions for linting - Blackened tests - Add code style badge in README.md - Bump version: v0.4.9 -> 0.4.10
1 parent a55df62 commit 161fb63

15 files changed

+379
-197
lines changed

.flake8

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
select = E,F,W
3+
exclude = .git,.idea,.*egg-info,*data,build,dist,test*,venv
4+
max-complexity = 10

.github/workflows/linting.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Linting
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v2
11+
- name: Run black
12+
uses: psf/black@stable
13+
with:
14+
options: ". --check"
15+
- name: Run flake8
16+
if: ${{ github.event_name == 'pull_request' }}
17+
# This uses a temporary fix by pinning markup_safe.
18+
# See https://github.com/grantmcconnaughey/lintly-flake8-github-action/pull/16
19+
uses: bniedzie/lintly-flake8-github-action@master
20+
with:
21+
token: ${{ secrets.GITHUB_TOKEN }}
22+
failIf: new
23+
args: "--config=.flake8 ."

.pre-commit-config.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
4+
hooks:
5+
- id: check-yaml
6+
- id: check-shebang-scripts-are-executable
7+
- id: end-of-file-fixer
8+
- id: trailing-whitespace
9+
- repo: https://github.com/psf/black
10+
rev: 22.3.0
11+
hooks:
12+
- id: black
13+
# It is recommended to specify the latest version of Python
14+
# supported by your project here, or alternatively use
15+
# pre-commit's default_language_version, see
16+
# https://pre-commit.com/#top_level-default_language_version
17+
language_version: python3.10
18+
- repo: https://github.com/pycqa/flake8
19+
rev: 4.0.1
20+
hooks:
21+
- id: flake8
22+
args:
23+
- "--config=.flake8"

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Retrieve statistics for a user's repositories and populate the information onto
55
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/astrochun/github-stats-pages/Python%20package?color=blue&label=build%20%28latest%29&logo=github)](https://github.com/astrochun/github-stats-pages/actions?query=workflow%3A%22Python+package%22)
66
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/github-stats-pages)
77
[![PyPI](https://img.shields.io/pypi/v/github-stats-pages?color=blue)](https://pypi.org/project/github-stats-pages)
8+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
89

910
![PyPI - Downloads](https://img.shields.io/pypi/dm/github-stats-pages?color=light%20green&label=PyPI-download)
1011

conftest.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33

44
def pytest_addoption(parser):
55
parser.addoption("--username", action="store", default="GitHub username")
6-
parser.addoption("--token", action="store",
7-
default="GitHub API personal access token")
6+
parser.addoption(
7+
"--token", action="store", default="GitHub API personal access token"
8+
)
89

910

10-
@pytest.fixture(scope='session')
11+
@pytest.fixture(scope="session")
1112
def username(request):
1213
name_value = request.config.option.username
1314
if name_value is None:
1415
pytest.skip()
1516
return name_value
1617

1718

18-
@pytest.fixture(scope='session')
19+
@pytest.fixture(scope="session")
1920
def token(request):
2021
name_value = request.config.option.token
2122
if name_value is None:

github_stats_pages/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.4.9"
1+
__version__ = "0.4.10"

github_stats_pages/gts_run.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
def run_each_repo(username, token, reponame, save_csv=True):
1111
if save_csv:
12-
os.system(f'gts {username}:{token} {reponame}')
12+
os.system(f"gts {username}:{token} {reponame}")
1313
else:
14-
os.system(f'gts {username}:{token} {reponame} no_csv')
14+
os.system(f"gts {username}:{token} {reponame} no_csv")
1515

1616

17-
def get_top_paths(username: str, token: str, reponame: str,
18-
save_csv: bool = True):
17+
def get_top_paths(
18+
username: str, token: str, reponame: str, save_csv: bool = True
19+
):
1920

2021
now = dt.now()
2122

@@ -25,16 +26,16 @@ def get_top_paths(username: str, token: str, reponame: str,
2526
if len(top_path_list) > 0:
2627
result = [p.raw_data for p in top_path_list]
2728
df = pd.DataFrame.from_records(result)
28-
pandas_write_buffer(df, ['path', 'count', 'uniques'], reponame)
29-
df.insert(loc=0, column='date', value=now.strftime('%Y-%m-%d'))
29+
pandas_write_buffer(df, ["path", "count", "uniques"], reponame)
30+
df.insert(loc=0, column="date", value=now.strftime("%Y-%m-%d"))
3031

3132
if save_csv:
3233
outfile = f"{now.strftime('%Y-%m-%d-%Hh-%Mm')}-paths-stats.csv"
3334
path = Path(outfile)
3435
if not path.exists():
3536
df.to_csv(path, index=False, header=True)
3637
else:
37-
df.to_csv(path, mode='a', index=False, header=False)
38+
df.to_csv(path, mode="a", index=False, header=False)
3839
else:
3940
print(f"Empty top paths for {reponame}")
4041

@@ -45,4 +46,3 @@ def pandas_write_buffer(df, columns, reponame):
4546
print(f"> {reponame} - Top paths")
4647
print(buffer.getvalue())
4748
buffer.close()
48-

github_stats_pages/repo_list.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,29 @@
33
import json
44
import pandas as pd
55

6-
SHORTEN_COLUMNS = ['id', 'name', 'html_url', 'description', 'language',
7-
'fork', 'archived', 'stargazers_count', 'watchers_count',
8-
'has_issues', 'has_downloads', 'has_wiki', 'has_pages',
9-
'forks_count', 'disabled', 'open_issues_count', 'license',
10-
'forks', 'open_issues', 'watchers', 'default_branch']
6+
SHORTEN_COLUMNS = [
7+
"id",
8+
"name",
9+
"html_url",
10+
"description",
11+
"language",
12+
"fork",
13+
"archived",
14+
"stargazers_count",
15+
"watchers_count",
16+
"has_issues",
17+
"has_downloads",
18+
"has_wiki",
19+
"has_pages",
20+
"forks_count",
21+
"disabled",
22+
"open_issues_count",
23+
"license",
24+
"forks",
25+
"open_issues",
26+
"watchers",
27+
"default_branch",
28+
]
1129

1230

1331
def get_repo_list(user: str) -> Tuple[list, pd.DataFrame]:
@@ -22,7 +40,7 @@ def get_repo_list(user: str) -> Tuple[list, pd.DataFrame]:
2240
print("get_repo_list - Retrieving repository list ...")
2341

2442
endpoint = f"https://api.github.com/users/{user}/repos"
25-
params = {'per_page': 100}
43+
params = {"per_page": 100}
2644
response = requests.get(endpoint, params=params)
2745
repository_list: List[Dict] = json.loads(response.content)
2846

0 commit comments

Comments
 (0)