-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from fabianhe/dev
Release 0.7.0
- Loading branch information
Showing
46 changed files
with
950 additions
and
598 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,3 +133,8 @@ dmypy.json | |
|
||
# macOS | ||
.DS_Store | ||
|
||
# Other | ||
measurements | ||
experimental | ||
executables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
FROM python:latest | ||
|
||
RUN pip install pyrepositoryminer | ||
WORKDIR /app | ||
|
||
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \ | ||
cd /usr/local/bin && \ | ||
ln -s /opt/poetry/bin/poetry && \ | ||
poetry config virtualenvs.create false | ||
|
||
COPY ./pyproject.toml ./poetry.lock README.md /app/ | ||
RUN poetry install --no-root --no-dev --no-interaction --no-ansi | ||
COPY ./pyrepositoryminer /app/pyrepositoryminer | ||
COPY ./executables /app/executables | ||
ENV EXECUTABLES=/app/executables | ||
ENV PYTHONPATH=/app | ||
RUN pip install . |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "pyrepositoryminer" | ||
version = "0.6.0" | ||
version = "0.7.0" | ||
description = "Efficient Repository Mining in Python" | ||
license = "GPL-3.0-or-later" | ||
authors = ["Fabian Heseding <[email protected]>"] | ||
|
@@ -10,7 +10,7 @@ repository = "https://github.com/fabianhe/pyrepositoryminer" | |
documentation = "https://github.com/fabianhe/pyrepositoryminer/blob/master/DOCS.md" | ||
|
||
[tool.poetry.scripts] | ||
pyrepositoryminer = "pyrepositoryminer.main:app" | ||
pyrepositoryminer = "pyrepositoryminer:app" | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.8" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
__version__ = "0.6.0" | ||
__version__ = "0.7.0" | ||
|
||
from typer import Typer | ||
|
||
from pyrepositoryminer.commands import analyze, branch, clone, commits | ||
|
||
app = Typer(help="Efficient Repository Mining in Python.") | ||
app.command()(analyze) | ||
app.command()(branch) | ||
app.command()(clone) | ||
app.command()(commits) | ||
|
||
__all__ = ("app",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from pyrepositoryminer.main import app | ||
from pyrepositoryminer import app | ||
|
||
app(prog_name="pyrepositoryminer") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from pyrepositoryminer.commands.analyze import analyze | ||
from pyrepositoryminer.commands.branch import branch | ||
from pyrepositoryminer.commands.clone import clone | ||
from pyrepositoryminer.commands.commits import commits | ||
|
||
__all__ = ("analyze", "branch", "clone", "commits") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from enum import Enum | ||
from functools import reduce | ||
from importlib import import_module | ||
from inspect import isclass | ||
from multiprocessing import Pool | ||
from pathlib import Path | ||
from sys import stdin | ||
from typing import List, Optional | ||
|
||
from typer import Abort, Argument, Option, echo | ||
from typer.models import FileText | ||
|
||
from pyrepositoryminer.analyze import InitArgs, initialize, worker | ||
from pyrepositoryminer.metrics import all_metrics | ||
from pyrepositoryminer.metrics.dir.main import DirMetric | ||
from pyrepositoryminer.metrics.nativeblob.main import NativeBlobMetric | ||
from pyrepositoryminer.metrics.nativetree.main import NativeTreeMetric | ||
|
||
AvailableMetrics = Enum( # type: ignore | ||
# https://github.com/python/mypy/issues/5317 | ||
"AvailableMetrics", | ||
[(k, k) for k in sorted(all_metrics.keys())], | ||
) | ||
|
||
|
||
def import_metric(import_str: str): # type: ignore # TODO make this a metric abc | ||
module_str, _, attrs_str = import_str.partition(":") | ||
if not module_str or not attrs_str: | ||
echo(f'Import string "{import_str}" must be in format "<module>:<attribute>"') | ||
raise Abort() | ||
try: | ||
module = import_module(module_str) | ||
except ImportError as e: | ||
if e.name != module_str: | ||
raise e from None | ||
echo(f'Could not import module "{module_str}"') | ||
raise Abort() | ||
try: | ||
instance = reduce(getattr, (module, *attrs_str.split("."))) # type: ignore | ||
except AttributeError: | ||
print(f'Attribute "{attrs_str}" not found in module "{module_str}"') | ||
raise Abort() | ||
if not isclass(instance): | ||
print(f'Instance "{instance}" must be a class') | ||
raise Abort() | ||
parents = (NativeBlobMetric, NativeTreeMetric, DirMetric) | ||
if not any(issubclass(instance, parent) for parent in parents): # type: ignore | ||
print(f'Instance "{instance}" must subclass a pyrepositoryminer metric class') | ||
raise Abort() | ||
return instance | ||
|
||
|
||
def analyze( | ||
repository: Path = Argument(..., help="The path to the bare repository."), | ||
metrics: Optional[List[AvailableMetrics]] = Argument(None, case_sensitive=False), | ||
commits: Optional[FileText] = Option( | ||
None, | ||
help="The newline-separated input file of commit ids. Commit ids are read from stdin if this is not passed.", # noqa: E501 | ||
), | ||
custom_metrics: List[str] = Option([]), | ||
workers: int = 1, | ||
) -> None: | ||
"""Analyze commits of a repository. | ||
Either provide the commit ids to analyze on stdin or as a file argument.""" | ||
metrics = metrics if metrics else [] | ||
ids = (id.strip() for id in (commits if commits else stdin)) | ||
with Pool( | ||
max(workers, 1), | ||
initialize, | ||
( | ||
InitArgs( | ||
repository, | ||
tuple({metric.value for metric in metrics} & all_metrics.keys()), | ||
tuple(map(import_metric, set(custom_metrics))), | ||
), | ||
), | ||
) as pool: | ||
results = (res for res in pool.imap(worker, ids) if res is not None) | ||
for result in results: | ||
echo(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from pathlib import Path | ||
from typing import Iterable | ||
|
||
from pygit2 import Repository | ||
from typer import Argument, echo | ||
|
||
|
||
def branch( | ||
repository: Path = Argument(..., help="The path to the bare repository."), | ||
local: bool = True, | ||
remote: bool = False, | ||
) -> None: | ||
"""Get the branches of a repository.""" | ||
repo = Repository(repository) | ||
branches: Iterable[str] | ||
if local and remote: | ||
branches = repo.branches | ||
elif local: | ||
branches = repo.branches.local | ||
elif remote: | ||
branches = repo.branches.remote | ||
for branch_name in branches: | ||
echo(branch_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from pathlib import Path | ||
|
||
from pygit2 import clone_repository | ||
|
||
|
||
def clone(url: str, path: Path, bare: bool = True) -> None: | ||
"Clone a repository to a path." | ||
clone_repository(url, path, bare=bare) |
Oops, something went wrong.