Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
name: CodeQL

on:
push:
branches: [ main ]
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
branches: [main]
schedule:
- cron: '22 18 * * 5'
- cron: 22 18 * * 5

jobs:
analyze:
Expand All @@ -32,7 +32,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'python' ]
language: [python]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: [3.13]

steps:
- uses: actions/checkout@v2
Expand All @@ -23,17 +23,14 @@ jobs:
- name: Generate coverage report
run: |
coverage erase
pytest --cov=codemetrics --cov-branch --cov-report=xml --cov-config=setup.cfg
pytest --cov=codemetrics --cov-branch --cov-report=xml --cov-config=pyproject.toml
coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
# Codacy does not seem to support coverage.xml out of the box
# - name: Codacy Coverage Reporter
# uses: codacy/codacy-coverage-reporter-action@master
# with:
# project-token: ${{secrets.CODACY_PROJECT_TOKEN}}
files: ./coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}



2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.13'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ wheels/

# Local files that should stay so
local/
.vscode/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
39 changes: 17 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
default_stages:
- commit
- pre-commit
repos:
- hooks:
- id: commitizen
stages:
- commit-msg
repo: https://github.com/commitizen-tools/commitizen
rev: v2.24.0
rev: master
- hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-toml
- id: debug-statements
- id: detect-private-key
- id: requirements-txt-fixer
repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v6.0.0
- hooks:
- args:
- --autofix
- --indent
- '2'
id: pretty-format-yaml
repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.3.0
- hooks:
- id: black
language_version: python3.8
repo: https://github.com/python/black
rev: 22.3.0
- hooks:
- additional_dependencies:
- flake8-comprehensions>=3.1.0
id: flake8
language: python_venv
repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
rev: v2.15.0
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.24.1
hooks:
- id: validate-pyproject
files: pyproject\.toml$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.13.0
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format
- hooks:
- args:
- --install-types
Expand All @@ -43,11 +42,7 @@ repos:
files: codemetrics/
id: mypy
repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.942
- hooks:
- id: isort
repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
rev: v1.18.1
- hooks:
- always_run: false
entry: python -m unittest
Expand Down
8 changes: 3 additions & 5 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Ready to contribute? Here's how to set up `codemetrics` for local development.

$ mkvirtualenv codemetrics
$ cd codemetrics/
$ python setup.py develop
$ python -m pip install -e .[develop]

4. Create a branch for local development::

Expand All @@ -78,11 +78,9 @@ Ready to contribute? Here's how to set up `codemetrics` for local development.
tests, including testing other Python versions with tox::

$ flake8 codemetrics tests
$ python setup.py test or py.test
$ python -m unittest discover tests
$ tox

To get flake8 and tox, just pip install them into your virtualenv.

6. Commit your changes and push your branch to GitHub::

$ git add .
Expand Down Expand Up @@ -122,7 +120,7 @@ Then run::
$ tox -p # there should be no errors.
$ vim HISTORY.rst
$ bump2version patch # possible: major / minor / patch.
$ vim setup.cfg # bump2version does not update all references.
$ vim pyproject.toml # bump2version does not update all references.
$ git push
$ git tag vx.y.z
$ git push --tags
Expand Down
8 changes: 4 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include AUTHORS.md
include CONTRIBUTING.md
include HISTORY.md
include AUTHORS.rst
include CONTRIBUTING.rst
include HISTORY.rst
include LICENSE.txt
include README.md
include README.rst

recursive-include tests *
recursive-exclude * __pycache__
Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ lint: ## check style with flake8
flake8 codemetrics tests

test: ## run tests quickly with the default Python
python setup.py test
python -m unittest discover tests

test-all: ## run tests on every Python version with tox
tox

coverage: ## check code coverage quickly with the default Python
coverage run --source codemetrics setup.py test
coverage run --source codemetrics -m pytest tests
coverage report -m
coverage html
$(BROWSER) htmlcov/index.html
Expand All @@ -80,9 +80,8 @@ release: dist ## package and upload a release
twine upload dist/*

dist: clean ## builds source and wheel package
python setup.py sdist
python setup.py bdist_wheel
python -m build
ls -l dist

install: clean ## install the package to the active Python's site-packages
python setup.py install
python -m pip install .
7 changes: 5 additions & 2 deletions codemetrics/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sklearn.feature_extraction.text

from . import internals, scm
from typing import Optional

__all__ = [
"get_mass_changes",
Expand All @@ -23,7 +24,9 @@


def get_mass_changes(
log: pd.DataFrame, min_path: int = None, max_changes_per_path: float = None
log: pd.DataFrame,
min_path: Optional[int] = None,
max_changes_per_path: Optional[float] = None,
) -> pd.DataFrame:
"""Extract mass changesets from the SCM log data frame.

Expand Down Expand Up @@ -61,7 +64,7 @@ def get_mass_changes(

def get_ages(
data: pd.DataFrame,
by: typing.Sequence[str] = None,
by: Optional[typing.Sequence[str]] = None,
) -> pd.DataFrame:
"""Generate age of each file based on last change.

Expand Down
25 changes: 14 additions & 11 deletions codemetrics/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from . import internals, scm
from .internals import log
from typing import Optional

default_client = "git"

Expand Down Expand Up @@ -60,7 +61,10 @@ class _GitLogCollector(scm.ScmLogCollector):
]

def __init__(
self, git_client: str = default_client, cwd: pl.Path = None, _pdb: bool = False
self,
git_client: str = default_client,
cwd: Optional[pl.Path] = None,
_pdb: bool = False,
):
"""Initialize.

Expand Down Expand Up @@ -190,9 +194,9 @@ def process_log_entries(
def get_log(
self,
path: str = ".",
after: dt.datetime = None,
before: dt.datetime = None,
progress_bar: tqdm.tqdm = None,
after: Optional[dt.datetime] = None,
before: Optional[dt.datetime] = None,
progress_bar: Optional[tqdm.tqdm] = None,
) -> pd.DataFrame:
"""Retrieve log from git.

Expand Down Expand Up @@ -230,7 +234,7 @@ def get_log(
class _GitFileDownloader(scm.ScmDownloader):
"""Download files from Subversion."""

def __init__(self, git_client: str = None, cwd: pl.Path = None):
def __init__(self, git_client: Optional[str] = None, cwd: Optional[pl.Path] = None):
"""Initialize downloader.

Args:
Expand All @@ -251,7 +255,6 @@ def _download(


class GitProject(scm.Project):

"""Project for git SCM."""

def __init__(self, cwd: pl.Path = pl.Path("."), client: str = "git"):
Expand Down Expand Up @@ -285,11 +288,11 @@ def download(self, data: pd.DataFrame) -> scm.DownloadResult:
def get_log(
self,
path: str = ".",
after: dt.datetime = None,
before: dt.datetime = None,
progress_bar: tqdm.tqdm = None,
after: Optional[dt.datetime] = None,
before: Optional[dt.datetime] = None,
progress_bar: Optional[tqdm.tqdm] = None,
# FIXME: Needed for Subversion though may be a better way.
relative_url: str = None,
relative_url: Optional[str] = None,
_pdb: bool = False,
) -> pd.DataFrame:
"""Entry point to retrieve git log.
Expand Down Expand Up @@ -318,7 +321,7 @@ def get_log(


def download(
data: pd.DataFrame, client: str = None, cwd: pl.Path = None
data: pd.DataFrame, client: Optional[str] = None, cwd: Optional[pl.Path] = None
) -> scm.DownloadResult:
"""Downloads files from Subversion.

Expand Down
3 changes: 2 additions & 1 deletion codemetrics/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import typing

import pandas as pd
from typing import Optional

log = logging.getLogger("codemetrics")
log.addHandler(logging.NullHandler())
Expand All @@ -27,7 +28,7 @@ def get_now():
return dt.datetime.now(dt.timezone.utc)


def get_year_ago(from_date: dt.datetime = None):
def get_year_ago(from_date: Optional[dt.datetime] = None):
"""Get current time stamp minus 1 year.

Decrements by one the year of the date returned by `get_now()`.
Expand Down
6 changes: 5 additions & 1 deletion codemetrics/pbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import tqdm

import codemetrics as cm
from typing import Optional


class ProgressBarAdapter:
Expand All @@ -17,7 +18,10 @@ class ProgressBarAdapter:
"""

def __init__(
self, progress_bar: tqdm.tqdm, after: dt.datetime, ascending: bool = None
self,
progress_bar: tqdm.tqdm,
after: dt.datetime,
ascending: Optional[bool] = None,
):
"""Creates adapter to update the progress bar based on days retrieved.

Expand Down
Loading