Skip to content

Commit 2401754

Browse files
authored
Merge pull request #3 from InnerSourceCommons/packaging
ci: update workflows
2 parents 75951f3 + 3d4e9a5 commit 2401754

7 files changed

Lines changed: 105 additions & 34 deletions

File tree

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Pylint
1+
name: checker
22

33
on: [push]
44

@@ -14,10 +14,13 @@ jobs:
1414
uses: actions/setup-python@v2
1515
with:
1616
python-version: ${{ matrix.python-version }}
17-
- name: Install dependencies
17+
- name: install dependencies
1818
run: |
1919
python -m pip install --upgrade pip
20-
pip install pylint
21-
- name: Analysing the code with pylint
20+
make install
21+
- name: flake8 lint
2222
run: |
23-
pylint `ls -R|grep .py$|xargs`
23+
make lint
24+
- name: check code format
25+
run: |
26+
make check-format
Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
# This workflow will upload a Python Package using Twine when a release is created
2-
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3-
4-
# This workflow uses actions that are not certified by GitHub.
5-
# They are provided by a third-party and are governed by
6-
# separate terms of service, privacy policy, and support
7-
# documentation.
8-
9-
name: Upload Python Package
1+
name: upload Python package
102

113
on:
124
release:
@@ -23,14 +15,12 @@ jobs:
2315
uses: actions/setup-python@v2
2416
with:
2517
python-version: '3.x'
26-
- name: Install dependencies
18+
- name: install dependencies
2719
run: |
2820
python -m pip install --upgrade pip
29-
pip install build
30-
- name: Build package
31-
run: python -m build
32-
#- name: Publish package
33-
# uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
34-
# with:
35-
# user: __token__
36-
# password: ${{ secrets.PYPI_API_TOKEN }}
21+
make install
22+
- name: publish to pypi
23+
uses: pypa/gh-action-pypi-publish@master
24+
with:
25+
skip_existing: true
26+
password: ${{ secrets.PYPI_TOKEN }}

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!make
2+
3+
define USAGE
4+
Commands:
5+
check-format Check code formats
6+
install Install requirements.txt dependencies
7+
lint Run linter (flake8)
8+
test Run tests and validate project
9+
endef
10+
11+
export USAGE
12+
13+
help:
14+
@echo "$$USAGE"
15+
16+
lint:
17+
@flake8 --ignore E501,W503,E203
18+
19+
install:
20+
@pip3 install -r requirements.txt
21+
22+
check-format:
23+
@black --check .

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build-system]
2+
requires = [
3+
"setuptools>=42",
4+
"wheel"
5+
]
6+
build-backend = "setuptools.build_meta"

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
flake8==4.0.1
2+
black==21.10b0
3+
bump2version==1.0.1
4+

setup.cfg

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[metadata]
2+
name = repo-activity-score
3+
version = 0.0.1
4+
author = André Correia & InnerSourceCommons
5+
author_email = andrecorreia@pm.me
6+
description = Python implementation of the InnerSourceCommons Repository Activity Score pattern algorithm
7+
long_description = file: README.md
8+
long_description_content_type = text/markdown
9+
url = https://github.com/InnerSourceCommons/repo-activity-score
10+
project_urls =
11+
Bug Tracker = https://github.com/InnerSourceCommons/repo-activity-score/issues
12+
classifiers =
13+
Programming Language :: Python :: 3
14+
License :: OSI Approved :: MIT License
15+
Operating System :: OS Independent
16+
17+
[options]
18+
package_dir =
19+
= src
20+
packages = find:
21+
python_requires = >=3.6
22+
23+
[options.packages.find]
24+
where = src

src/repo_score/score.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,62 @@
22
import math
33
import functools
44

5+
56
def calculate_score(repo):
67
# initial score is 50 to give active repos with low GitHub KPIs (forks, watchers, stars) a better starting point
78
iScore = float(50)
89

910
# weighting: forks and watches count most, then stars, add some little score for open issues, too
1011
iScore += repo["forks_count"] * 5
11-
iScore += 'subscribers_count' in repo or 0
12+
iScore += "subscribers_count" in repo or 0
1213
iScore += repo["stargazers_count"] / 3
1314
iScore += repo["open_issues_count"] / 5
1415

1516
# updated in last 3 months: adds a bonus multiplier between 0..1 to overall score (1 = updated today, 0 = updated more than 100 days ago)
16-
iDaysSinceLastUpdate = (datetime.datetime.now().timestamp() - datetime.datetime.strptime(repo['updated_at'], '%Y-%m-%dT%H:%M:%SZ').timestamp()) / 86400
17+
iDaysSinceLastUpdate = (
18+
datetime.datetime.now().timestamp()
19+
- datetime.datetime.strptime(
20+
repo["updated_at"], "%Y-%m-%dT%H:%M:%SZ"
21+
).timestamp()
22+
) / 86400
1723
iScore = iScore * ((1 + (100 - min(iDaysSinceLastUpdate, 100))) / 100)
1824

1925
# evaluate participation stats for the previous 3 months
20-
if repo['_InnerSourceMetadata']: repo['_InnerSourceMetadata'] or {}
26+
if repo["_InnerSourceMetadata"]:
27+
repo["_InnerSourceMetadata"] or {}
2128

22-
if 'participation' in repo['_InnerSourceMetadata']:
29+
if "participation" in repo["_InnerSourceMetadata"]:
2330
# average commits: adds a bonus multiplier between 0..1 to overall score (1 = >10 commits per week, 0 = less than 3 commits per week)
24-
sliced = repo['_InnerSourceMetadata']['participation'][len(repo['_InnerSourceMetadata']['participation']) - 13:]
31+
sliced = repo["_InnerSourceMetadata"]["participation"][
32+
len(repo["_InnerSourceMetadata"]["participation"]) - 13 :
33+
]
2534

26-
iAverageCommitsPerWeek = functools.reduce(lambda a, b: a+b, sliced) / 13
35+
iAverageCommitsPerWeek = functools.reduce(lambda a, b: a + b, sliced) / 13
2736

2837
iScore = iScore * ((1 + (min(max(iAverageCommitsPerWeek - 3, 0), 7))) / 7)
2938

3039
# boost calculation:
3140
# all repositories updated in the previous year will receive a boost of maximum 1000 declining by days since last update
32-
iBoost = (1000 - min(iDaysSinceLastUpdate, 365) * 2.74)
41+
iBoost = 1000 - min(iDaysSinceLastUpdate, 365) * 2.74
3342
# gradually scale down boost according to repository creation date to mix with "real" engagement stats
34-
iDaysSinceCreation = (datetime.datetime.now().timestamp() - datetime.datetime.strptime(repo['created_at'], '%Y-%m-%dT%H:%M:%SZ').timestamp()) / 86400
43+
iDaysSinceCreation = (
44+
datetime.datetime.now().timestamp()
45+
- datetime.datetime.strptime(
46+
repo["created_at"], "%Y-%m-%dT%H:%M:%SZ"
47+
).timestamp()
48+
) / 86400
3549
iBoost *= (365 - min(iDaysSinceCreation, 365)) / 365
3650
# add boost to score
3751
iScore += iBoost
3852
# give projects with a meaningful description a static boost of 50
39-
if len(repo["description"]) > 30 and repo["_InnerSourceMetadata"] or ("motivation" in repo["_InnerSourceMetadata"] and repo["_InnerSourceMetadata"]["motivation"].length > 30):
53+
if (
54+
len(repo["description"]) > 30
55+
and repo["_InnerSourceMetadata"]
56+
or (
57+
"motivation" in repo["_InnerSourceMetadata"]
58+
and repo["_InnerSourceMetadata"]["motivation"].length > 30
59+
)
60+
):
4061
iScore += 50
4162
# give projects with contribution guidelines (CONTRIBUTING.md) file a static boost of 100
4263
if repo["_InnerSourceMetadata"] and "guidelines" in repo["_InnerSourceMetadata"]:
@@ -46,8 +67,8 @@ def calculate_score(repo):
4667
iScore = 3000 + math.log(iScore) * 100
4768
# final score is a rounded value starting from 0 (subtract the initial value)
4869
iScore = round(iScore - 50)
49-
70+
5071
# add score to metadata on the fly
51-
repo['_InnerSourceMetadata']['score'] = iScore
72+
repo["_InnerSourceMetadata"]["score"] = iScore
5273

5374
return iScore

0 commit comments

Comments
 (0)