diff --git a/README.md b/README.md index a1c2404..8fd5f8a 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ You can use the scripts in this repository to analyse another git repository for Using python 3.7 or greater: - pip install -r requirements.txt + pip install . There are two scripts for calculating metrics (which may be combined into one soon). To find out how to use them: - python calculate_four_metrics.py --help - python git-metrics.py --help + calculate-four-metrics --help + git-metrics --help ## Throughput metrics: Deployment Lead Time and Deploy Interval @@ -37,17 +37,17 @@ Once you have your repository annotated with tags for each deployment, you can u Use a command like this to produce the raw data for this graph and store it in a csv file: - python git_metrics.py release-lead-time [--tag-pattern=] [--earliest-date=] > repo_data.csv - + git-metrics release-lead-time [--tag-pattern=] [--earliest-date=] > repo_data.csv + You can then plot this data with this command: - python git_metrics.py plot --release-lead-time + git-metrics plot --release-lead-time You can also print out average values for both release lead time and release interval like this: - calculate_four_metrics.py lead-time [--deploy-tag-pattern=] [--start-date=] - calculate_four_metrics.py deploy-interval [--deploy-tag-pattern=] [--start-date=] + calculate-four-metrics lead-time [--deploy-tag-pattern=] [--start-date=] + calculate-four-metrics deploy-interval [--deploy-tag-pattern=] [--start-date=] For more information about how to install these scripts, see below under 'Installation' @@ -66,8 +66,8 @@ If you want to add a patch tag to a commit that has been deployed, and already h You can also print out average values for both mean time to recover and change failure rate like this: - calculate_four_metrics.py recovery-time [--deploy-tag-pattern=] [--patch-tag-pattern=] [--start-date=] - calculate_four_metrics.py change-fail-rate [--deploy-tag-pattern=] [--patch-tag-pattern=] [--start-date=] + calculate-four-metrics recovery-time [--deploy-tag-pattern=] [--patch-tag-pattern=] [--start-date=] + calculate-four-metrics change-fail-rate [--deploy-tag-pattern=] [--patch-tag-pattern=] [--start-date=] ## Open branches @@ -77,8 +77,8 @@ Open branches gathers information about the age of all commits in a branch that Use these script commands to produce this kind of graph: - git_metrics.py open-branches [--master-branch=] > my_repo.csv - git_metrics.py plot --open-branches my_repo.csv + git-metrics open-branches [--master-branch=] > my_repo.csv + git-metrics plot --open-branches my_repo.csv ## Installation @@ -86,56 +86,39 @@ Use these script commands to produce this kind of graph: **Requirement:** Python 3.7 or later To install dependencies: - `pip install -r requirements.txt` + `python pip install .` for more help run: - `python git_metrics.py --help` - -### Python 2 systems - -Those OS with Python 2 as default, e.g. Ubuntu 17/16, you need to use pip and python explicitly if you didn't change the default: - -Call the script with: - - python3 git_metrics.py --help - -Install pip3 if not already installed and configure dependencies with pip3, e.g. Ubuntu 16/17: - - sudo apt-get install python3-pip - pip3 install -r requirements.txt - -On Ubuntu you might also miss the `python3-tk` package if doing plots - - sudo apt install python3-tk + `git-metrics --help` ## Usage Call script with - python3 git_metrics.py --help + git-metrics --help which will show basic usage information like: Calculate age of commits in open remote branches Usage: - git_metrics.py open-branches [--master-branch=] - git_metrics.py open-branches [--master-branch=] --plot - git_metrics.py release-lead-time [--tag-pattern=] [--earliest-date=] - git_metrics.py release-lead-time --plot [--tag-pattern=] - git_metrics.py plot --open-branches - git_metrics.py plot --release-lead-time - git_metrics.py batch --open-branches ... - git_metrics.py batch --release-lead-time [--earliest-date=] ... - git_metrics.py (-h | --help) + git-metrics open-branches [--master-branch=] + git-metrics open-branches [--master-branch=] --plot + git-metrics release-lead-time [--tag-pattern=] [--earliest-date=] + git-metrics release-lead-time --plot [--tag-pattern=] + git-metrics plot --open-branches + git-metrics plot --release-lead-time + git-metrics batch --open-branches ... + git-metrics batch --release-lead-time [--earliest-date=] ... + git-metrics (-h | --help) Options: --master-branch= example: origin/gh-pages * **`--plot`** parameter will open a GnuPlot plot, and will not will not save your data. -* To _save data_ use without plot and pipe to file for csv format: `git_metrics.py release-lead-time > my-csv-file.csv` -* Use plot command to plot existing csv files, e.g. `git_metrics.py plot --release-lead-time my-csv-file.csv` +* To _save data_ use without plot and pipe to file for csv format: `git-metrics release-lead-time > my-csv-file.csv` +* Use plot command to plot existing csv files, e.g. `git-metrics plot --release-lead-time my-csv-file.csv` * `batch` (undocumented) ## Developer information @@ -143,5 +126,3 @@ which will show basic usage information like: Run the self-tests using pytest: pytest -v - - diff --git a/git_metrics/__init__.py b/git_metrics/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/calculate_four_metrics.py b/git_metrics/calculate_four_metrics.py similarity index 87% rename from calculate_four_metrics.py rename to git_metrics/calculate_four_metrics.py index 4f0a6e1..322b702 100644 --- a/calculate_four_metrics.py +++ b/git_metrics/calculate_four_metrics.py @@ -5,12 +5,12 @@ * Mean time to recover Usage: - calculate_four_metrics.py lead-time [--deploy-tag-pattern=] [--start-date=] - calculate_four_metrics.py deploy-interval [--deploy-tag-pattern=] [--start-date=] - calculate_four_metrics.py change-fail-rate [--deploy-tag-pattern=] [--patch-tag-pattern=] [--start-date=] - calculate_four_metrics.py recovery-time [--deploy-tag-pattern=] [--patch-tag-pattern=] [--start-date=] - calculate_four_metrics.py metrics-all [--deploy-tag-pattern=] [--patch-tag-pattern=] [--start-date=] - calculate_four_metrics.py (-h | --help) + calculate-four-metrics lead-time [--deploy-tag-pattern=] [--start-date=] + calculate-four-metrics deploy-interval [--deploy-tag-pattern=] [--start-date=] + calculate-four-metrics change-fail-rate [--deploy-tag-pattern=] [--patch-tag-pattern=] [--start-date=] + calculate-four-metrics recovery-time [--deploy-tag-pattern=] [--patch-tag-pattern=] [--start-date=] + calculate-four-metrics metrics-all [--deploy-tag-pattern=] [--patch-tag-pattern=] [--start-date=] + calculate-four-metrics (-h | --help) """ import csv @@ -24,10 +24,10 @@ import docopt -from git_metrics_release_lead_time import commit_author_time_tag_author_time_and_from_to_tag_name, \ +from .git_metrics_release_lead_time import commit_author_time_tag_author_time_and_from_to_tag_name, \ fetch_tags_and_author_dates, fetch_tags_and_sha -from process import mk_run -from recovery_time import Deployment, find_is_patch, find_outages +from .process import mk_run +from .recovery_time import Deployment, find_is_patch, find_outages def configure_logging(): @@ -143,7 +143,7 @@ def calculate_lead_time(path_to_git_repo, pattern, start_date): log.info("calculating lead time data from deployments %s", deployment_tag_pairs) lead_time_data = [(tat - cat) for cat, tat, old_tag, tag in deployment_data] return statistics.mean(lead_time_data) if lead_time_data else "N/A" - + def write_four_metrics_csv_file(data): writer = csv.writer(sys.stdout, delimiter=',', lineterminator='\n') diff --git a/custom_git.py b/git_metrics/custom_git.py similarity index 100% rename from custom_git.py rename to git_metrics/custom_git.py diff --git a/data.py b/git_metrics/data.py similarity index 100% rename from data.py rename to git_metrics/data.py diff --git a/git_metrics.py b/git_metrics/git_metrics.py similarity index 82% rename from git_metrics.py rename to git_metrics/git_metrics.py index 598cecc..4f39428 100644 --- a/git_metrics.py +++ b/git_metrics/git_metrics.py @@ -1,15 +1,15 @@ """Calculate age of commits in open remote branches Usage: - git_metrics.py open-branches [--master-branch=] - git_metrics.py open-branches [--master-branch=] --plot - git_metrics.py release-lead-time [--tag-pattern=] [--earliest-date=] - git_metrics.py release-lead-time --plot [--tag-pattern=] - git_metrics.py plot --open-branches - git_metrics.py plot --release-lead-time - git_metrics.py batch --open-branches ... - git_metrics.py batch --release-lead-time [--earliest-date=] ... - git_metrics.py (-h | --help) + git-metrics open-branches [--master-branch=] + git-metrics open-branches [--master-branch=] --plot + git-metrics release-lead-time [--tag-pattern=] [--earliest-date=] + git-metrics release-lead-time --plot [--tag-pattern=] + git-metrics plot --open-branches + git-metrics plot --release-lead-time + git-metrics batch --open-branches ... + git-metrics batch --release-lead-time [--earliest-date=] ... + git-metrics (-h | --help) Options: --master-branch= example: origin/gh-pages @@ -23,12 +23,12 @@ import docopt import sys -from git_metrics_open_branches import plot_open_branches_metrics -from git_metrics_open_branches import get_branches -from git_metrics_open_branches import commit_author_time_and_branch_ref -from git_metrics_release_lead_time import commit_author_time_tag_author_time_and_from_to_tag_name -from git_metrics_release_lead_time import plot_release_lead_time_metrics -from process import mk_run +from .git_metrics_open_branches import plot_open_branches_metrics +from .git_metrics_open_branches import get_branches +from .git_metrics_open_branches import commit_author_time_and_branch_ref +from .git_metrics_release_lead_time import commit_author_time_tag_author_time_and_from_to_tag_name +from .git_metrics_release_lead_time import plot_release_lead_time_metrics +from .process import mk_run def read_open_branches_csv_file(filename): @@ -136,4 +136,3 @@ def assert_master_branch(run, master_branch): if __name__ == "__main__": main() - diff --git a/git_metrics_open_branches.py b/git_metrics/git_metrics_open_branches.py similarity index 95% rename from git_metrics_open_branches.py rename to git_metrics/git_metrics_open_branches.py index 4efd06d..3f0b151 100644 --- a/git_metrics_open_branches.py +++ b/git_metrics/git_metrics_open_branches.py @@ -1,5 +1,5 @@ -from data import columns -from custom_git import for_each_ref, log +from .data import columns +from .custom_git import for_each_ref, log def plot_open_branches_metrics(data): diff --git a/git_metrics_release_lead_time.py b/git_metrics/git_metrics_release_lead_time.py similarity index 96% rename from git_metrics_release_lead_time.py rename to git_metrics/git_metrics_release_lead_time.py index 1d23500..85cb8ea 100644 --- a/git_metrics_release_lead_time.py +++ b/git_metrics/git_metrics_release_lead_time.py @@ -3,10 +3,10 @@ import matplotlib -from data import columns, zip_with_tail -from custom_git import for_each_ref, show -from custom_git import cherry -from process import proc_to_stdout +from .data import columns, zip_with_tail +from .custom_git import for_each_ref, show +from .custom_git import cherry +from .process import proc_to_stdout TAGS_WITH_AUTHOR_DATE_CMD = for_each_ref( 'refs/tags/**', diff --git a/process.py b/git_metrics/process.py similarity index 100% rename from process.py rename to git_metrics/process.py diff --git a/recovery_time.py b/git_metrics/recovery_time.py similarity index 100% rename from recovery_time.py rename to git_metrics/recovery_time.py diff --git a/test_data.py b/git_metrics/test_data.py similarity index 82% rename from test_data.py rename to git_metrics/test_data.py index a549863..12694fa 100644 --- a/test_data.py +++ b/git_metrics/test_data.py @@ -1,5 +1,5 @@ -from data import columns -from data import zip_with_tail +from .data import columns +from .data import zip_with_tail def test_single_column(): diff --git a/test_git.py b/git_metrics/test_git.py similarity index 95% rename from test_git.py rename to git_metrics/test_git.py index 9a400bb..f344286 100644 --- a/test_git.py +++ b/git_metrics/test_git.py @@ -1,5 +1,5 @@ -from custom_git import for_each_ref, cherry, show -from custom_git import log +from .custom_git import for_each_ref, cherry, show +from .custom_git import log def test_for_each_ref_normal(): diff --git a/test_integration.py b/git_metrics/test_integration.py similarity index 96% rename from test_integration.py rename to git_metrics/test_integration.py index cf9c95a..7833750 100644 --- a/test_integration.py +++ b/git_metrics/test_integration.py @@ -5,7 +5,7 @@ import pytest from git import Repo -from calculate_four_metrics import calculate_lead_time, calculate_deploy_interval, calculate_change_fail_rate, \ +from .calculate_four_metrics import calculate_lead_time, calculate_deploy_interval, calculate_change_fail_rate, \ calculate_MTTR @@ -52,7 +52,7 @@ def _run_git_cmd(git_repo, command, environment): "GIT_AUTHOR_NAME": "Integration Test", "EMAIL": "test@example.com"} env_variables.update(environment) - subprocess.run(command, cwd=git_repo.working_dir, + subprocess.run(command, cwd=git_repo.working_dir, env=env_variables) @@ -111,4 +111,3 @@ def test_calculate_deploy_interval_no_matching_tags(git_repo_DDDP): def test_lead_time_multiple_deploys(git_repo_DDDP): mean_lead_time = calculate_lead_time(git_repo_DDDP.working_dir, "FOO*", 1548321540) assert mean_lead_time == "N/A" - diff --git a/test_process.py b/git_metrics/test_process.py similarity index 89% rename from test_process.py rename to git_metrics/test_process.py index 7e5dc44..c79c3b9 100644 --- a/test_process.py +++ b/git_metrics/test_process.py @@ -1,7 +1,7 @@ import os from subprocess import Popen, PIPE -from process import proc_to_stdout +from .process import proc_to_stdout def test_proc_to_pocess(): diff --git a/test_recovery_time.py b/git_metrics/test_recovery_time.py similarity index 96% rename from test_recovery_time.py rename to git_metrics/test_recovery_time.py index 69bb394..5f5a933 100644 --- a/test_recovery_time.py +++ b/git_metrics/test_recovery_time.py @@ -1,4 +1,4 @@ -from recovery_time import find_outages, split_sequence, Deployment, find_is_patch +from .recovery_time import find_outages, split_sequence, Deployment, find_is_patch deployment_zero = Deployment(False, 0) deployment_two = Deployment(False, 2) diff --git a/test_release_lead_time.py b/git_metrics/test_release_lead_time.py similarity index 79% rename from test_release_lead_time.py rename to git_metrics/test_release_lead_time.py index a6a2455..3cda2fa 100644 --- a/test_release_lead_time.py +++ b/git_metrics/test_release_lead_time.py @@ -1,10 +1,10 @@ from collections import namedtuple from contextlib import contextmanager -from git_metrics_release_lead_time import parse_tags_with_date -from git_metrics_release_lead_time import tags_with_author_date -from git_metrics_release_lead_time import fetch_tags_and_sha -import git_metrics_release_lead_time +from .git_metrics_release_lead_time import parse_tags_with_date +from .git_metrics_release_lead_time import tags_with_author_date +from .git_metrics_release_lead_time import fetch_tags_and_sha +from . import git_metrics_release_lead_time def test_parse_tags_with_author_date(): diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..638dd9c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index c803c9e..0000000 --- a/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -pytest -docopt -matplotlib -pandas -requests -gitpython \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..1f89258 --- /dev/null +++ b/setup.py @@ -0,0 +1,21 @@ +from setuptools import setup, find_packages + +setup( + name='git_metrics', + version='0.1.0', + packages=find_packages(), + install_requires=[ + "docopt >= 0.6.2", + "GitPython >= 3.1.14", + "matplotlib >= 3.3.4", + "pandas >= 1.2.3", + "pytest >= 6.2.2", + "requests >= 2.25.1", + ], + entry_points={ + 'console_scripts': [ + 'calculate-four-metrics = git_metrics.calculate_four_metrics:main', + 'git-metrics = git_metrics.git_metrics:main', + ], + }, +)