chore: monthly updates for Aug'23; bump version

- revised readme, better theming support, improved wording where needed
- granular config for ruff linter & pyright type checker, re-format code
- update dependencies, bump version
This commit is contained in:
Jovial Joe Jayarson 2023-08-17 11:26:22 +05:30
parent ba3aa17f4e
commit ac8e6017f5
5 changed files with 146 additions and 90 deletions

152
README.md
View File

@ -1,22 +1,33 @@
<center> <p align="center">
<img
src="https://socialify.git.ci/athul/waka-readme/image?description=1&font=Source%20Code%20Pro&forks=1&issues=1&name=1&owner=1&pulls=1&stargazers=1&theme=Auto"
alt="waka-readme"
width="640"
height="320"
/>
</p>
![waka-readme](https://socialify.git.ci/athul/waka-readme/image?description=1&forks=1&name=1&pulls=1&stargazers=1&theme=Light) # Dev Metrics in Readme [![Unit Tests](https://github.com/athul/waka-readme/actions/workflows/testing.yml/badge.svg?branch=master)](https://github.com/athul/waka-readme/actions/workflows/testing.yml)
</center> [WakaTime](https://wakatime.com) coding metrics on your profile readme.
# Dev Metrics in Readme [![Unit Tests](https://github.com/athul/waka-readme/actions/workflows/testing.yml/badge.svg?branch=master)](https://github.com/athul/waka-readme/actions/workflows/testing.yml) ![Python Version](https://img.shields.io/badge/Python-^3.11-blue) <!-- prettier-ignore-start -->
<picture>
[WakaTime](https://wakatime.com) weekly metrics on your profile readme. <source srcset="https://github.com/athul/waka-readme/assets/38415384/60a6bcd0-01f8-421a-8730-7e872d216e09"
media="(prefers-color-scheme: dark)" />
![Project Preview](https://user-images.githubusercontent.com/8397274/87243943-e6b45c00-c457-11ea-94c9-2aa0bf241be8.png) <img src="https://github.com/athul/waka-readme/assets/38415384/29541cbc-0e39-47c4-93c2-514032b47276"
alt="new_secrets_actions" />
</picture>
<!-- prettier-ignore-end -->
:speech_balloon: **Forum** | [GitHub discussions][gh_discuss] :speech_balloon: **Forum** | [GitHub discussions][gh_discuss]
## New to WakaTime? ## New to WakaTime?
> Nope? Skip to [prep work](#prep-work). > Nope? Skip to [#Prep work](#prep-work).
WakaTime gives you an idea of the time you spent on coding. This helps you boost your productivity and competitive edge. WakaTime gives you an idea of the time you spent on coding.
This helps you boost your productivity and competitive edge (aka _flex_ :muscle:).
1. Head over to <https://wakatime.com/> and create an account. 1. Head over to <https://wakatime.com/> and create an account.
2. After logging in get your WakaTime API Key from <https://wakatime.com/api-key/>. 2. After logging in get your WakaTime API Key from <https://wakatime.com/api-key/>.
@ -24,7 +35,7 @@ WakaTime gives you an idea of the time you spent on coding. This helps you boost
4. Paste in your API key to start telemetry. 4. Paste in your API key to start telemetry.
:information_source: **Info** | You can read [WakaTime help][waka_help] to know more about configurations. :information_source: **Info** | You can read [WakaTime help][waka_help] to know more about configurations.
Alternatively, you can also fetch data from WakaTime compatible services like [Wakapi][wakapi] or [Hakatime][hakatime]. Alternatively, you can fetch data from WakaTime compatible services such as [Wakapi][wakapi] or [Hakatime][hakatime].
## Prep Work ## Prep Work
@ -39,24 +50,43 @@ A GitHub repository and a `README.md` file is required. We'll be making use of r
`<!--START_SECTION: -->` and `<!--END_SECTION: -->` are placeholders and must be retained as is. Whereas "`waka`" can be replaced by any alphanumeric string. See [#Tweaks](#tweaks) section for more. `<!--START_SECTION: -->` and `<!--END_SECTION: -->` are placeholders and must be retained as is. Whereas "`waka`" can be replaced by any alphanumeric string. See [#Tweaks](#tweaks) section for more.
- Navigate to your repo's `Settings > Secrets` and add a new secret _named_ `WAKATIME_API_KEY` with your API key as it's _value_. - Navigate to your repo's `Settings`:
- Go to `Secrets` (at `https://github.com/USERNAME/USERNAME/settings/secrets/actions/new` by replacing the `USERNAME` with your own username) and add a new secret "_Named_" `WAKATIME_API_KEY` with your API key as it's "_Secret_".
> Or use the url <https://github.com/USERNAME/USERNAME/settings/secrets/actions/new> by replacing the `USERNAME` with your own username. <!-- prettier-ignore-start -->
> <picture>
> ![new_secrets_actions][new_secrets_actions] <source srcset="https://github.com/athul/waka-readme/assets/38415384/04dee9dc-65a1-43f9-9df4-7545646b9a72"
media="(prefers-color-scheme: dark)" />
<img src="https://github.com/athul/waka-readme/assets/38415384/9110cc3e-66cc-46ed-89d4-36644aa258e1"
alt="new_secrets_actions" />
</picture>
<!-- prettier-ignore-end -->
- If you're not using [profile repository][profile_readme], add another secret _named_ `GH_TOKEN` and insert your [GitHub token][gh_access_token]\* in place of _value_. > If you're not using [profile repository][profile_readme], add another secret "_Named_" `GH_TOKEN` and in place of "_Secret_" insert your [GitHub token][gh_access_token].
- Create a new workflow file (`waka-readme.yml`) inside `.github/workflows/` folder of your repository. You can create it from a template using the _actions tab_ of your repository too. - Go to `Workflow permissions` under `Actions` (at `https://github.com/USERNAME/USERNAME/settings/actions` by replacing the `USERNAME` with your own username) and set `Read and write permissions`.
- Clear any existing contents, add the following lines and save the `waka-readme.yml` workflow file.
<!-- prettier-ignore-start -->
<picture>
<source srcset="https://github.com/athul/waka-readme/assets/38415384/a1b86a0b-4065-4ff1-847b-b52e681bf247"
media="(prefers-color-scheme: dark)" />
<img src="https://github.com/athul/waka-readme/assets/38415384/de9cb7d0-fd40-43cf-8fed-7c6f57207788"
alt="new_secrets_actions" />
</picture>
<!-- prettier-ignore-end -->
- Create a new workflow file named `waka-readme.yml` inside `.github/workflows/` folder of your repository.
- Clear all existing contents, add following lines and save the file.
```yml ```yml
name: Waka Readme name: Waka Readme
on: on:
workflow_dispatch: # for manual workflow trigger # for manual workflow trigger
workflow_dispatch:
schedule: schedule:
- cron: "0 0 * * *" # runs at every 12AM UTC # runs at 12 AM UTC (5:30 AM IST)
- cron: "0 0 * * *"
jobs: jobs:
update-readme: update-readme:
@ -66,17 +96,13 @@ A GitHub repository and a `README.md` file is required. We'll be making use of r
- uses: athul/waka-readme@master - uses: athul/waka-readme@master
with: with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
# following flags are required, only if this is not on
# profile readme, remove the leading `#` to use them
#GH_TOKEN: ${{ secrets.GH_TOKEN }}
#REPOSITORY: <gh_username/gh_username>
``` ```
Refer [#Example](#example) section for a full blown workflow file. Refer [#Example](#example) section for a full blown workflow file.
## Tweaks ## Tweaks
There are many flags that you can tweak as you wish! There are many flags that you can modify as you see fit.
### Meta Tweaks ### Meta Tweaks
@ -112,9 +138,9 @@ There are many flags that you can tweak as you wish!
| `AUTHOR_NAME` | `NOT_SET`, author name | | `AUTHOR_NAME` | `NOT_SET`, author name |
| `AUTHOR_EMAIL` | `NOT_SET`, author email | | `AUTHOR_EMAIL` | `NOT_SET`, author email |
All of these flags are _optional_. The first option is the _default_ value of the _flag_, subsequent options are valid values available for the _flag_.
# Example ## Example
**`waka-readme.yml`** **`waka-readme.yml`**
@ -122,9 +148,10 @@ All of these flags are _optional_.
name: Waka Readme name: Waka Readme
on: on:
# for manual workflow trigger
workflow_dispatch: workflow_dispatch:
schedule: schedule:
# Runs at 12am UTC # runs at 12 AM UTC (5:30 AM IST)
- cron: "0 0 * * *" - cron: "0 0 * * *"
jobs: jobs:
@ -134,43 +161,38 @@ jobs:
steps: steps:
- uses: athul/waka-readme@master - uses: athul/waka-readme@master
with: with:
GH_TOKEN: ${{ secrets.GH_TOKEN }} GH_TOKEN: ${{ secrets.GH_TOKEN }} # optional if on profile readme
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} # required
# meta ### meta
API_BASE_URL: https://wakatime.com/api API_BASE_URL: https://wakatime.com/api # optional
REPOSITORY: athul/athul REPOSITORY: YOUR_GITHUB_USERNAME/YOUR_REPOSITORY_NAME # optional
# content ### content
SHOW_TITLE: true SHOW_TITLE: true # optional
SECTION_NAME: waka SECTION_NAME: waka # optional
BLOCKS: -> BLOCKS: -> # optional
CODE_LANG: all_time CODE_LANG: rust # optional
TIME_RANGE: true TIME_RANGE: all_time # optional
LANG_COUNT: 10 LANG_COUNT: 10 # optional
SHOW_TIME: true SHOW_TIME: true # optional
SHOW_TOTAL: true SHOW_TOTAL: true # optional
SHOW_MASKED_TIME: false SHOW_MASKED_TIME: false # optional
STOP_AT_OTHER: true STOP_AT_OTHER: true # optional
# commit ### commit
COMMIT_MESSAGE: Updated waka-readme graph with new metrics COMMIT_MESSAGE: Updated waka-readme graph with new metrics # optional
TARGET_BRANCH: master TARGET_BRANCH: master # optional
TARGET_PATH: README.md TARGET_PATH: README.md # optional
COMMITTER_NAME: GitHubActionBot COMMITTER_NAME: GitHubActionBot # optional
COMMITTER_EMAIL: action-bot@github.org COMMITTER_EMAIL: action-bot@github.com # optional
AUTHOR_NAME: Athul AUTHOR_NAME: YOUR_NAME # optional
AUTHOR_EMAIL: athul@example.org AUTHOR_EMAIL: YOUR@EMAIL.com # optional
# you can populate email-id with secretes instead # you can populate email-id with secretes instead
``` ```
> Note: _Rendered `markdown`:_
>
> - Flags `REPOSITORY` and `GH_TOKEN` are required, ONLY if you're NOT using [profile readme][profile_readme].
> - `WAKATIME_API_KEY` is a required secret.
> - Every other environment variables is optional.
> - The above example does not show proper default values, refer [#Tweaks](#tweaks) for the same.
**`README.md`** <!-- prettier-ignore-start -->
```md ```rust
From: 10 July 2020 - To: 06 August 2022 From: 10 July 2020 - To: 06 August 2022
Total Time: 1,464 hrs 54 mins Total Time: 1,464 hrs 54 mins
@ -183,6 +205,15 @@ Nim 64 hrs 31 mins >------------------------ 04.11 %
Other 47 hrs 58 mins >------------------------ 03.05 % Other 47 hrs 58 mins >------------------------ 03.05 %
``` ```
<!-- prettier-ignore-end -->
## Notes
- Flags `REPOSITORY` and `GH_TOKEN` are required ONLY if, you are NOT using [profile readme][profile_readme].
- If you are using `GH_TOKEN`, make sure set the [fine grained token](https://github.com/settings/tokens?type=beta) scope to repository contents with `read-and-write` access. See [#141 (comment)](https://github.com/athul/waka-readme/issues/141#issuecomment-1679831949).
- `WAKATIME_API_KEY` is a **required** secret. All other environment variables are optional.
- The above example does NOT show proper default values, refer [#Tweaks](#tweaks) for the same.
## Why only the language stats (and not other data) from the API? ## Why only the language stats (and not other data) from the API?
I am a fan of minimal designs and the profile readme is a great way to show off your skills and interests. The WakaTime API, gets us a **lot of data** about a person's **coding activity including the editors and Operating Systems you used and the projects you worked on**. Some of these projects maybe secretive and should not be shown out to the public. Using up more data via the Wakatime API will clutter the profile readme and hinder your chances on displaying what you provide **value to the community** like the pinned Repositories. I believe that **Coding Stats is nerdiest of all** since you can tell the community that you are **_exercising these languages or learning a new language_**, this will also show that you spend some amount of time to learn and exercise your development skills. That's what matters in the end :heart: I am a fan of minimal designs and the profile readme is a great way to show off your skills and interests. The WakaTime API, gets us a **lot of data** about a person's **coding activity including the editors and Operating Systems you used and the projects you worked on**. Some of these projects maybe secretive and should not be shown out to the public. Using up more data via the Wakatime API will clutter the profile readme and hinder your chances on displaying what you provide **value to the community** like the pinned Repositories. I believe that **Coding Stats is nerdiest of all** since you can tell the community that you are **_exercising these languages or learning a new language_**, this will also show that you spend some amount of time to learn and exercise your development skills. That's what matters in the end :heart:
@ -193,6 +224,5 @@ I am a fan of minimal designs and the profile readme is a great way to show off
[waka_plugins]: https://wakatime.com/plugins [waka_plugins]: https://wakatime.com/plugins
[waka_help]: https://wakatime.com/help/editors [waka_help]: https://wakatime.com/help/editors
[profile_readme]: https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/customizing-your-profile/managing-your-profile-readme [profile_readme]: https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/customizing-your-profile/managing-your-profile-readme
[new_secrets_actions]: https://user-images.githubusercontent.com/52720626/151221742-bc37d139-2bb3-4554-b27c-46b107d1f408.png
[gh_access_token]: https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token [gh_access_token]: https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token
[gh_discuss]: https://github.com/athul/waka-readme/discussions [gh_discuss]: https://github.com/athul/waka-readme/discussions

21
main.py
View File

@ -28,24 +28,23 @@ Contents := Title + Byline + Body
""" """
# standard # standard
from dataclasses import dataclass
from random import SystemRandom
from functools import partial
from datetime import datetime
from base64 import b64encode from base64 import b64encode
from dataclasses import dataclass
from datetime import datetime
from functools import partial
import logging as logger import logging as logger
import os
from random import SystemRandom
import re
import sys
from time import sleep from time import sleep
from typing import Any from typing import Any
import sys
import re
import os
# external # external
from github import ContentFile, Github, GithubException, InputGitAuthor, Repository
from requests.exceptions import RequestException
from requests import get as rq_get
from faker import Faker from faker import Faker
from github import ContentFile, Github, GithubException, InputGitAuthor, Repository
from requests import get as rq_get
from requests.exceptions import RequestException
################### setup ################### ################### setup ###################

View File

@ -4,20 +4,19 @@
[project] [project]
name = "waka-readme" name = "waka-readme"
version = "0.2.3" version = "0.2.4"
description = "Wakatime Weekly Metrics on your Profile Readme." description = "Wakatime Weekly Metrics on your Profile Readme."
authors = [{ name = "Athul Cyriac Ajay", email = "athul8720@gmail.com" }]
license = { text = "MIT" } license = { text = "MIT" }
readme = "README.md" readme = "README.md"
keywords = ["readme", "profile-page", "wakatime"] keywords = ["readme", "profile-page", "wakatime"]
authors = [{ name = "Athul Cyriac Ajay", email = "athul8720@gmail.com" }]
maintainers = [{ name = "Jovial Joe Jayarson" }]
classifiers = [ classifiers = [
"Development Status :: 5 - Production/Stable", "Development Status :: 5 - Production/Stable",
"Programming Language :: Python", "Programming Language :: Python",
"Typing :: Typed", "Typing :: Typed",
] ]
requires-python = ">=3.11" requires-python = ">=3.11"
dependencies = ["faker>=19.1.0", "pygithub>=1.59.0", "requests>=2.31.0"] dependencies = ["faker>=19.3.0", "pygithub>=1.59.1", "requests>=2.31.0"]
[project.urls] [project.urls]
Homepage = "https://github.com/athul/waka-readme" Homepage = "https://github.com/athul/waka-readme"
@ -25,32 +24,62 @@ Documentation = "https://github.com/athul/waka-readme#readme"
Repository = "https://github.com/athul/waka-readme" Repository = "https://github.com/athul/waka-readme"
Changelog = "https://github.com/athul/waka-readme/commits/master" Changelog = "https://github.com/athul/waka-readme/commits/master"
############################# #############################
# Optional Dependencies # # Optional Dependencies #
############################# #############################
[project.optional-dependencies] [project.optional-dependencies]
dev = ["loguru>=0.7.0", "python-dotenv>=1.0.0"] dev = ["loguru>=0.7.0", "python-dotenv>=1.0.0"]
tooling = ["bandit>=1.7.5", "black>=23.7.0", "ruff>=0.0.278"] tooling = [
"bandit>=1.7.5",
"black>=23.7.0",
"ruff>=0.0.284",
"pyright>=1.1.323",
]
#################### ####################
# Configurations # # Configurations #
#################### ####################
[tool.bandit]
exclude_dirs = [".github", "tests", ".venv", ".vscode"]
[tool.black] [tool.black]
line-length = 100 line-length = 100
target-version = ["py311"] target-version = ["py311"]
[tool.bandit] [tool.pyright]
exclude_dirs = [".github", ".pytest_cache", ".tox", ".vscode", "site", "tests"] exclude = ["**/__pycache__", ".venv/"]
pythonVersion = "3.11"
pythonPlatform = "All"
typeCheckingMode = "strict"
[tool.ruff] [tool.ruff]
select = [
# Pyflakes
"F",
# pycodestyle
"W",
"E",
# mccabe
# C90
# isort
"I",
# pep8-naming
"N",
# pydocstyle
"D",
]
line-length = 100 line-length = 100
target-version = "py311"
extend-exclude = ["**/__pycache__"]
[tool.ruff.isort]
# case-sensitive = true
combine-as-imports = true
force-sort-within-sections = true
force-wrap-aliases = true
relative-imports-order = "closest-to-furthest"
[tool.ruff.pydocstyle] [tool.ruff.pydocstyle]
convention = "google" convention = "google"
[tool.ruff.isort]
force-sort-within-sections = true
relative-imports-order = "closest-to-furthest"

View File

@ -1,6 +1,4 @@
""" """Initialize test module."""
Initialize test module
"""
# standard # standard
import logging import logging

View File

@ -1,12 +1,12 @@
"""Unit Tests.""" """Unit Tests."""
# standard # standard
from importlib import import_module
from dataclasses import dataclass # , field from dataclasses import dataclass # , field
from importlib import import_module
from itertools import product from itertools import product
import unittest
import sys
import os import os
import sys
import unittest
# from pathlib import Path # from pathlib import Path
# from inspect import cleandoc # from inspect import cleandoc