Skip to content

Commit 2b57817

Browse files
authored
Merge pull request #5 from RECETOX/feat/pypi-stats
Feat/pypi stats
2 parents 2d52d93 + 401ba98 commit 2b57817

20 files changed

Lines changed: 1078 additions & 0 deletions

.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[DEFAULT]
2+
REPO_FILE_PATH=repository_list.tsv
3+
DEBUG=False

.editorconfig

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
charset = utf-8
11+
end_of_line = lf
12+
13+
[*.bat]
14+
indent_style = tab
15+
end_of_line = crlf
16+
17+
[LICENSE]
18+
insert_final_newline = false
19+
20+
[Makefile]
21+
indent_style = tab
22+
23+
[*.{yml, yaml}]
24+
indent_size = 2

.github/workflows/actions.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: specdatri reporting
2+
on:
3+
schedule:
4+
- cron: 0 0 * * 1 # At 00:00 on Monday
5+
jobs:
6+
build:
7+
runs-on: ubuntu-22.04
8+
steps:
9+
- name: checkout repo content
10+
uses: actions/checkout@v4
11+
- name: setup python
12+
uses: actions/setup-python@v5
13+
with:
14+
python-version: '3.12'
15+
- name: install python packages
16+
run: |
17+
python -m pip install --upgrade pip
18+
pip install -r requirements.txt
19+
- name: execute py script
20+
env:
21+
github_token: '${{ secrets.github_token }}'
22+
pepy_x_api_key: '${{ secrets.pepy_x_api_key }}'
23+
run: python main.py
24+
- name: commit files
25+
run: |
26+
git config --local user.email "action@github.com"
27+
git config --local user.name "GitHub Action"
28+
git add -A
29+
git diff-index --quiet HEAD || (git commit -a -m "updated files" --allow-empty)
30+
- name: push changes
31+
uses: ad-m/github-push-action@v0.8.0
32+
with:
33+
github_token: '${{ secrets.github_token }}'
34+
branch: main
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "Code Scanning with CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
- cron: '40 17 * * 3'
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-22.04
15+
permissions:
16+
security-events: write
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
- name: Initialize
21+
uses: github/codeql-action/init@v3
22+
with:
23+
languages: python
24+
- name: Perform CodeQL Analysis
25+
uses: github/codeql-action/analyze@v3

.pre-commit-config.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
exclude: '.*\.tsv$'
2+
default_stages: [pre-commit]
3+
4+
default_language_version:
5+
python: python3.12
6+
7+
repos:
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v5.0.0
10+
hooks:
11+
- id: trailing-whitespace
12+
- id: end-of-file-fixer
13+
- id: check-json
14+
- id: check-toml
15+
- id: check-xml
16+
- id: check-yaml
17+
- id: debug-statements
18+
- id: check-builtin-literals
19+
- id: check-case-conflict
20+
- id: check-docstring-first
21+
- id: detect-private-key
22+
23+
# Run the Ruff linter.
24+
- repo: https://github.com/astral-sh/ruff-pre-commit
25+
rev: v0.8.3
26+
hooks:
27+
# Linter
28+
- id: ruff
29+
args: [--fix, --exit-non-zero-on-fix]
30+
31+
# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
32+
ci:
33+
autoupdate_schedule: weekly
34+
skip: []
35+
submodules: false

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,44 @@
11
# specdatri_reporting
22
The code base includes a collection of scripts and GitHub Actions designed to gather various metrics on RECETOX's impact.
3+
4+
## Local development
5+
6+
### Project setup
7+
It is assumed you can clone and change directories into the development repo.
8+
Create a virtualenv or conda environment (whatever your poison).
9+
10+
Once in the repos directory, activate your env then run the following command to install the needed python libraries.
11+
12+
> pip install -r .\requirements\local.txt
13+
14+
### Simulating Github Actions
15+
16+
You need [act](https://nektosact.com/) to test your code in development mode.
17+
Install act for your chosen OS.
18+
At your terminal, run (This simulates a GitHub action on your local device):
19+
20+
> act --secret-file .env schedule
21+
22+
### Things to note
23+
24+
1: Do not push local development changes from `tmp` folder and `reports` folder. In fact do not edit them at all !!!
25+
26+
2: When testing with `act` do not use a token that has the permission to make push requests else your test data will mess with "production" data.
27+
28+
3: When testing with `act` know that the push may fail due to the fact that you can't directly push to main.
29+
30+
4: Always, I repeat always devlop on another branch not main and never push directly to main.
31+
32+
5: You need tokens to test the code locally, place said tokens in `example.env` and change the filename to `.env`
33+
34+
### Running tests:
35+
36+
#### Running with unittest
37+
> python -m unittest discover -s tests
38+
39+
#### Running with coverage
40+
> coverage run -m unittest discover -s tests
41+
42+
> coverage report -m
43+
44+
> coverage html

example.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github_token="your_github_token"
2+
pepy_x_api_key="your_pepy_x_api_key"

main.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import pandas as pd
2+
from pandas import DataFrame
3+
4+
from src.github import process_github_repositories
5+
from src.pypi import process_pypi_repositories
6+
from src.utils import get_config_var, get_env_var, log_function, setup_logger
7+
8+
logger = setup_logger()
9+
10+
11+
@log_function(logger)
12+
def load_repositories(
13+
file_path: str,
14+
) -> DataFrame:
15+
"""
16+
Reads a list of repositories from a TSV file and returns it as a DataFrame.
17+
18+
:param file_path: Path to the TSV file containing the list of repositories.
19+
:return: DataFrame containing the list of repositories.
20+
"""
21+
return pd.read_csv(file_path, sep="\t")
22+
23+
24+
@log_function(logger)
25+
def process_repositories(
26+
repositories_df: DataFrame,
27+
github_token: str,
28+
pepy_x_api_key: str,
29+
):
30+
"""
31+
Args:
32+
repositories_df (DataFrame): DataFrame containing the list of repositories.
33+
github_token (str): GitHub token to access the GitHub API.
34+
Returns:
35+
None
36+
"""
37+
for _, row in repositories_df.iterrows():
38+
source = row["source"].lower()
39+
repository = row["repository"]
40+
action = row["action"]
41+
project = row["project"]
42+
package = row["package"]
43+
if source == "github":
44+
owner, repo = repository.split("/")
45+
process_github_repositories(
46+
owner, repo, github_token, action, project, package
47+
)
48+
elif source == "pypi":
49+
process_pypi_repositories(
50+
package, pepy_x_api_key, action, project
51+
)
52+
else:
53+
logger.error(f"Unknown source: {source}")
54+
55+
56+
@log_function(logger)
57+
def main():
58+
repo_file_path = get_config_var("DEFAULT", "REPO_FILE_PATH")
59+
if repo_file_path:
60+
logger.info("REPO_FILE_PATH found in .config file")
61+
repositories_df = load_repositories(repo_file_path)
62+
github_token = get_env_var("github_token")
63+
pepy_x_api_key = get_env_var("pepy_x_api_key")
64+
process_repositories(repositories_df, github_token, pepy_x_api_key)
65+
logger.debug(f"Repositories DataFrame: \n{repositories_df}")
66+
else:
67+
logger.error("REPO_FILE_PATH not found in .config file")
68+
print("REPO_FILE_PATH not found in .config file")
69+
70+
71+
if __name__ == "__main__":
72+
main()

reports/.gitkeep

Whitespace-only changes.

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-r requirements/base.txt

0 commit comments

Comments
 (0)