Skip to content

Commit 33e989c

Browse files
authored
🔧 MAINT: pre-commit configured and executed (#55)
* pre-commit: add config * pre-commit: run black autoformatting * pre-commit: run prettier autoformatting * pre-commit: run reorder-python-imports * pre-commit: run requirements-txt-fixer * pre-commit: add permissive .flake8 config * pre-commit: run flake8, fix a single issue * ci: add pre-commit test * ci: accept workflow_dispatch trigger (run workflow button) * docs: add config reference link to .readthedocs.yml * flake8: initialize a variable
1 parent 8180a51 commit 33e989c

File tree

16 files changed

+218
-107
lines changed

16 files changed

+218
-107
lines changed

.flake8

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[flake8]
2+
# Ignore style and complexity
3+
# E: style errors
4+
# W: style warnings
5+
# C: complexity
6+
# F401: module imported but unused
7+
# F403: import *
8+
# F811: redefinition of unused `name` from line `N`
9+
# F841: local variable assigned but never used
10+
# E402: module level import not at top of file
11+
# I100: Import statements are in the wrong order
12+
# I101: Imported names are in the wrong order. Should be
13+
ignore = E, C, W, F401, F403, F811, F841, E402, I100, I101, D400
14+
# builtins = ...
15+
# exclude = ...

.github/workflows/tests.yaml

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,73 @@
11
name: continuous-integration
22

3-
on: [push, pull_request]
3+
on:
4+
pull_request:
5+
push:
6+
workflow_dispatch:
47

58
jobs:
9+
pre-commit:
10+
runs-on: ubuntu-20.04
11+
timeout-minutes: 2
612

7-
tests:
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.8
18+
19+
# ref: https://github.com/pre-commit/action
20+
- uses: pre-commit/action@v2.0.3
21+
- name: Help message if pre-commit fail
22+
if: ${{ failure() }}
23+
run: |
24+
echo "You can install pre-commit hooks to automatically run formatting"
25+
echo "on each commit with:"
26+
echo " pre-commit install"
27+
echo "or you can run by hand on staged files with"
28+
echo " pre-commit run"
29+
echo "or after-the-fact on already committed files with"
30+
echo " pre-commit run --all-files"
831
32+
tests:
933
runs-on: ubuntu-latest
1034

1135
steps:
12-
- uses: actions/checkout@v2
13-
# Only testing 3.8 to avoid too many github API calls
14-
- name: Set up Python 3.8
15-
uses: actions/setup-python@v1
16-
with:
17-
python-version: 3.8
18-
- name: Install dependencies
19-
run: |
20-
python -m pip install --upgrade pip
21-
pip install -e .[testing]
22-
- name: Run tests
23-
env:
24-
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25-
run: pytest
36+
- uses: actions/checkout@v2
37+
# Only testing 3.8 to avoid too many github API calls
38+
- name: Set up Python 3.8
39+
uses: actions/setup-python@v1
40+
with:
41+
python-version: 3.8
42+
- name: Install dependencies
43+
run: |
44+
python -m pip install --upgrade pip
45+
pip install -e .[testing]
46+
- name: Run tests
47+
env:
48+
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
run: pytest
2650

2751
docs:
28-
2952
runs-on: ubuntu-latest
3053

3154
steps:
32-
- uses: actions/checkout@v2
33-
- name: Set up Python 3.8
34-
uses: actions/setup-python@v1
35-
with:
36-
python-version: 3.8
37-
- name: Install dependencies
38-
run: |
39-
python -m pip install --upgrade pip
40-
pip install -e .[sphinx]
55+
- uses: actions/checkout@v2
56+
- name: Set up Python 3.8
57+
uses: actions/setup-python@v1
58+
with:
59+
python-version: 3.8
60+
- name: Install dependencies
61+
run: |
62+
python -m pip install --upgrade pip
63+
pip install -e .[sphinx]
4164
42-
- name: Build docs
43-
run: |
44-
cd docs
45-
make html
65+
- name: Build docs
66+
run: |
67+
cd docs
68+
make html
4669
4770
publish:
48-
4971
name: Publish to PyPi
5072
needs: [tests]
5173
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')

.pre-commit-config.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# pre-commit is a tool to perform a predefined set of tasks manually and/or
2+
# automatically before git commits are made.
3+
#
4+
# Config reference: https://pre-commit.com/#pre-commit-configyaml---top-level
5+
#
6+
# Common tasks
7+
#
8+
# - Run on all files: pre-commit run --all-files
9+
# - Register git hooks: pre-commit install --install-hooks
10+
#
11+
repos:
12+
# Autoformat: Python code
13+
- repo: https://github.com/ambv/black
14+
rev: stable
15+
hooks:
16+
- id: black
17+
18+
# Autoformat: markdown, yaml
19+
- repo: https://github.com/pre-commit/mirrors-prettier
20+
rev: v2.3.0
21+
hooks:
22+
- id: prettier
23+
exclude: tests/.*
24+
25+
# Autoformat: https://github.com/asottile/reorder_python_imports
26+
- repo: https://github.com/asottile/reorder_python_imports
27+
rev: v2.5.0
28+
hooks:
29+
- id: reorder-python-imports
30+
31+
# Misc...
32+
- repo: https://github.com/pre-commit/pre-commit-hooks
33+
rev: v3.4.0
34+
# ref: https://github.com/pre-commit/pre-commit-hooks#hooks-available
35+
hooks:
36+
# Autoformat: Makes sure files end in a newline and only a newline.
37+
- id: end-of-file-fixer
38+
exclude: tests/.*
39+
40+
# Autoformat: Sorts entries in requirements.txt.
41+
- id: requirements-txt-fixer
42+
43+
# Lint: Check for files with names that would conflict on a
44+
# case-insensitive filesystem like MacOS HFS+ or Windows FAT.
45+
- id: check-case-conflict
46+
47+
# Lint: Checks that non-binary executables have a proper shebang.
48+
- id: check-executables-have-shebangs
49+
50+
# Lint: Python code
51+
- repo: https://github.com/pycqa/flake8
52+
rev: "3.9.2"
53+
hooks:
54+
- id: flake8

.readthedocs.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
# Read the Docs builds and publish our documentation
2+
#
3+
# Config reference: https://docs.readthedocs.io/en/stable/config-file/v2.html
4+
#
15
version: 2
26

37
python:
48
version: 3
59
install:
6-
- method: pip
7-
path: .
8-
extra_requirements:
9-
- sphinx
10+
- method: pip
11+
path: .
12+
extra_requirements:
13+
- sphinx

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This package does two things:
1010
2. A CLI to render this activity as markdown, suitable for generating changelogs or
1111
community updates.
1212

13-
*Note: This is a really young tool so it might change a bit over time.*
13+
_Note: This is a really young tool so it might change a bit over time._
1414

1515
## Installation
1616

docs/conf.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
# This file only contains a selection of the most common options. For a full
44
# list see the documentation:
55
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6-
76
# -- Path setup --------------------------------------------------------------
8-
97
# If extensions (or modules to document with autodoc) are in another directory,
108
# add these directories to sys.path here. If the directory is relative to the
119
# documentation root, use os.path.abspath to make it absolute, like shown here.
1210
#
1311
# import os
1412
# import sys
1513
# sys.path.insert(0, os.path.abspath('.'))
16-
17-
1814
# -- Project information -----------------------------------------------------
1915

2016
project = "GitHub Activity"

docs/index.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ For repositories that use multiple branches, it may be necessary to filter PRs b
6060
### Splitting PRs by tags and prefixes
6161

6262
Often you wish to split your PRs into multiple categories so that they are easier
63-
to scan and parse. You may also *only* want to keep some PRs (e.g. features, or API
63+
to scan and parse. You may also _only_ want to keep some PRs (e.g. features, or API
6464
changes) while excluding others from your changelog.
6565

6666
`github-activity` uses the GitHub tags as well as PR prefixes to automatically
@@ -71,6 +71,7 @@ Below is a list of the supported PR types, as well as the tags / title prefixes
7171
that will be used to identify the right category.
7272

7373
```{include} tags_list.txt
74+
7475
```
7576

7677
```{tip}
@@ -85,21 +86,21 @@ left-most column above.
8586
You will quickly hit your API limit unless you use a personal access token. Here are
8687
instructions to generate and use a GitHub access token for use with `github-activity`.
8788

88-
* Create your own access token. Go to the [new GitHub access token page](https://github.com/settings/tokens/new)
89+
- Create your own access token. Go to the [new GitHub access token page](https://github.com/settings/tokens/new)
8990
and follow the instructions. Note that while working with a public repository,
9091
you don't need to set any scopes on the token you create.
91-
* When using `github-activity` from the command line, use the `--auth` parameter and pass
92+
- When using `github-activity` from the command line, use the `--auth` parameter and pass
9293
in your access token. This is easiest if you set it as an **environment variable**,
9394
such as `MY_ACCESS_TOKEN`. You can then add it to your call like so:
9495

9596
```
9697
github-activity jupyter/notebook --since v2019-09-01 --auth $MY_ACCESS_TOKEN
9798
```
98-
* If you do not explicitly pass an access token to `github-activity`, it will search
99+
100+
- If you do not explicitly pass an access token to `github-activity`, it will search
99101
for an environment variable called `GITHUB_ACCESS_TOKEN`. If it finds this variable,
100102
it will use this in the API calls to GitHub.
101103

102-
103104
## How does this tool define contributions in the reports?
104105

105106
GitHub Activity tries to automatically determine the unique list of contributors within
@@ -108,14 +109,14 @@ a given window of time. There are many ways to define this, and there isn't nece
108109

109110
We try to balance the two extremes of "anybody who shows up is recognized as contributing"
110111
and "nobody is recognized as contributing". We've chosen a few rules that try to reflect
111-
sustained engagement in issues/PRs, or contributions in the form of help in *others'* issues
112+
sustained engagement in issues/PRs, or contributions in the form of help in _others'_ issues
112113
or contributing code.
113114

114115
Here are the rules we follow for finding a list of contributors within a time window. A
115116
contributor is anyone who has:
116117

117-
* Had their PR merged in that window
118-
* Commented on >= 2 issues that weren't theirs
119-
* Commented >= 6 times on any one issue
118+
- Had their PR merged in that window
119+
- Commented on >= 2 issues that weren't theirs
120+
- Commented >= 6 times on any one issue
120121

121122
We'd love feedback on whether this is a good set of rules to use.

docs/sample_notebook_activity.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ Below is a sample activity report that was generated with `github-activity`.
88
The raw markdown is pasted below.
99

1010
## 6.0.0...6.0.1
11-
([full changelog](https://github.com/jupyter/notebook/compare/6.0.0...6.0.1))
1211

12+
([full changelog](https://github.com/jupyter/notebook/compare/6.0.0...6.0.1))
1313

1414
### Merged PRs
15-
* Attempt to re-establish websocket connection to Gateway [#4777](https://github.com/jupyter/notebook/pull/4777) ([@esevan](https://github.com/esevan))
16-
* add missing react-dom js to package data [#4772](https://github.com/jupyter/notebook/pull/4772) ([@minrk](https://github.com/minrk))
17-
* Release 6.0 [#4708](https://github.com/jupyter/notebook/pull/4708) ([@lresende](https://github.com/lresende))
15+
16+
- Attempt to re-establish websocket connection to Gateway [#4777](https://github.com/jupyter/notebook/pull/4777) ([@esevan](https://github.com/esevan))
17+
- add missing react-dom js to package data [#4772](https://github.com/jupyter/notebook/pull/4772) ([@minrk](https://github.com/minrk))
18+
- Release 6.0 [#4708](https://github.com/jupyter/notebook/pull/4708) ([@lresende](https://github.com/lresende))
1819

1920
### Contributors to this release
21+
2022
([GitHub contributors page for this release](https://github.com/jupyter/notebook/graphs/contributors?from=2019-07-16&to=2019-08-22&type=c))
2123

2224
[@0todd0000](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3A0todd0000+updated%3A2019-07-16..2019-08-22&type=Issues) | [@aarchiba](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Aaarchiba+updated%3A2019-07-16..2019-08-22&type=Issues) | [@adejonghm](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Aadejonghm+updated%3A2019-07-16..2019-08-22&type=Issues) | [@benthayer](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Abenthayer+updated%3A2019-07-16..2019-08-22&type=Issues) | [@blink1073](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ablink1073+updated%3A2019-07-16..2019-08-22&type=Issues) | [@Carreau](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3ACarreau+updated%3A2019-07-16..2019-08-22&type=Issues) | [@choldgraf](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Acholdgraf+updated%3A2019-07-16..2019-08-22&type=Issues) | [@esevan](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Aesevan+updated%3A2019-07-16..2019-08-22&type=Issues) | [@Flid](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3AFlid+updated%3A2019-07-16..2019-08-22&type=Issues) | [@gnestor](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Agnestor+updated%3A2019-07-16..2019-08-22&type=Issues) | [@hadim](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ahadim+updated%3A2019-07-16..2019-08-22&type=Issues) | [@jasongrout](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ajasongrout+updated%3A2019-07-16..2019-08-22&type=Issues) | [@johncbowers](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ajohncbowers+updated%3A2019-07-16..2019-08-22&type=Issues) | [@jph00](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ajph00+updated%3A2019-07-16..2019-08-22&type=Issues) | [@kevin-bates](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Akevin-bates+updated%3A2019-07-16..2019-08-22&type=Issues) | [@lresende](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Alresende+updated%3A2019-07-16..2019-08-22&type=Issues) | [@meeseeksmachine](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ameeseeksmachine+updated%3A2019-07-16..2019-08-22&type=Issues) | [@minrk](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Aminrk+updated%3A2019-07-16..2019-08-22&type=Issues) | [@mpacer](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ampacer+updated%3A2019-07-16..2019-08-22&type=Issues) | [@parkerwill](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Aparkerwill+updated%3A2019-07-16..2019-08-22&type=Issues) | [@reichenbch](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Areichenbch+updated%3A2019-07-16..2019-08-22&type=Issues) | [@SylvainCorlay](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3ASylvainCorlay+updated%3A2019-07-16..2019-08-22&type=Issues) | [@takluyver](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Atakluyver+updated%3A2019-07-16..2019-08-22&type=Issues)
@@ -39,4 +41,4 @@ Here is the raw markdown for the report as a reference:
3941
([GitHub contributors page for this release](https://github.com/jupyter/notebook/graphs/contributors?from=2019-07-16&to=2019-08-22&type=c))
4042
4143
[@0todd0000](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3A0todd0000+updated%3A2019-07-16..2019-08-22&type=Issues) | [@aarchiba](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Aaarchiba+updated%3A2019-07-16..2019-08-22&type=Issues) | [@adejonghm](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Aadejonghm+updated%3A2019-07-16..2019-08-22&type=Issues) | [@benthayer](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Abenthayer+updated%3A2019-07-16..2019-08-22&type=Issues) | [@blink1073](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ablink1073+updated%3A2019-07-16..2019-08-22&type=Issues) | [@Carreau](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3ACarreau+updated%3A2019-07-16..2019-08-22&type=Issues) | [@choldgraf](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Acholdgraf+updated%3A2019-07-16..2019-08-22&type=Issues) | [@esevan](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Aesevan+updated%3A2019-07-16..2019-08-22&type=Issues) | [@Flid](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3AFlid+updated%3A2019-07-16..2019-08-22&type=Issues) | [@gnestor](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Agnestor+updated%3A2019-07-16..2019-08-22&type=Issues) | [@hadim](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ahadim+updated%3A2019-07-16..2019-08-22&type=Issues) | [@jasongrout](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ajasongrout+updated%3A2019-07-16..2019-08-22&type=Issues) | [@johncbowers](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ajohncbowers+updated%3A2019-07-16..2019-08-22&type=Issues) | [@jph00](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ajph00+updated%3A2019-07-16..2019-08-22&type=Issues) | [@kevin-bates](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Akevin-bates+updated%3A2019-07-16..2019-08-22&type=Issues) | [@lresende](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Alresende+updated%3A2019-07-16..2019-08-22&type=Issues) | [@meeseeksmachine](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ameeseeksmachine+updated%3A2019-07-16..2019-08-22&type=Issues) | [@minrk](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Aminrk+updated%3A2019-07-16..2019-08-22&type=Issues) | [@mpacer](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Ampacer+updated%3A2019-07-16..2019-08-22&type=Issues) | [@parkerwill](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Aparkerwill+updated%3A2019-07-16..2019-08-22&type=Issues) | [@reichenbch](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Areichenbch+updated%3A2019-07-16..2019-08-22&type=Issues) | [@SylvainCorlay](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3ASylvainCorlay+updated%3A2019-07-16..2019-08-22&type=Issues) | [@takluyver](https://github.com/search?q=repo%3Ajupyter%2Fnotebook+involves%3Atakluyver+updated%3A2019-07-16..2019-08-22&type=Issues)
42-
```
44+
```

github_activity/cache.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import pandas as pd
1+
import sys
22
from pathlib import Path
33

4+
import pandas as pd
5+
46
DEFAULT_PATH_CACHE = Path("~/data_github_activity").expanduser()
57

68

github_activity/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import argparse
22
import os
33
import sys
4-
from subprocess import run, PIPE
4+
from subprocess import PIPE
5+
from subprocess import run
56

6-
from .github_activity import generate_activity_md, _parse_target
77
from .git import _git_installed_check
8+
from .github_activity import _parse_target
9+
from .github_activity import generate_activity_md
810

911
DESCRIPTION = "Generate a markdown changelog of GitHub activity within a date window."
1012
parser = argparse.ArgumentParser(description=DESCRIPTION)

0 commit comments

Comments
 (0)