diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..44ebdabd --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include requirements.txt +include test-requirements.txt diff --git a/docs/modifiedfile.rst b/docs/modifiedfile.rst index 52e6cedc..5785f92f 100644 --- a/docs/modifiedfile.rst +++ b/docs/modifiedfile.rst @@ -6,19 +6,19 @@ ModifiedFile You can get a list of modified files as well as their diffs and current source code from each commit. All *Modifications* can be obtained by iterating over the ModifiedFile object. Each modification object references a modified file and has the following fields: -* **old_path**: old path of the file (can be _None_ if the file is added) -* **new_path**: new path of the file (can be _None_ if the file is deleted) +* **old_path**: old path of the file (can be ``None`` if the file is added) +* **new_path**: new path of the file (can be ``None`` if the file is deleted) * **filename**: return only the filename (e.g., given a path-like-string such as "/Users/dspadini/pydriller/myfile.py" returns “myfile.py”) * **change_type**: type of the change: can be Added, Deleted, Modified, or Renamed. If you use `change_type.name` you get `ADD`, `DELETE`, `MODIFY`, `RENAME`. * **diff**: diff of the file as Git presents it (e.g., starting with @@ xx,xx @@). * **diff_parsed**: diff parsed in a dictionary containing the added and deleted lines. The dictionary has 2 keys: “added” and “deleted”, each containing a list of Tuple (int, str) corresponding to (number of line in the file, actual line). * **added_lines**: number of lines added * **deleted_lines**: number of lines removed -* **source_code**: source code of the file (can be _None_ if the file is deleted or only renamed) -* **source_code_before**: source code of the file before the change (can be _None_ if the file is added or only renamed) +* **source_code**: source code of the file (can be ``None`` if the file is deleted or only renamed) +* **source_code_before**: source code of the file before the change (can be ``None`` if the file is added or only renamed) * **methods**: list of methods of the file. The list might be empty if the programming language is not supported or if the file is not a source code file. These are the methods **after** the change. * **methods_before**: list of methods of the file **before** the change (e.g., before the commit.) -* **changed_methods**: subset of _methods_ containing **only** the changed methods. +* **changed_methods**: subset of *methods* containing **only** the changed methods. * **nloc**: Lines Of Code (LOC) of the file * **complexity**: Cyclomatic Complexity of the file * **token_count**: Number of Tokens of the file diff --git a/docs/requirements.txt b/docs/requirements.txt index 52b04f2e..e58f5b5c 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1 +1,3 @@ -sphinx_rtd_theme \ No newline at end of file +sphinx_rtd_theme + +-r ../requirements.txt \ No newline at end of file diff --git a/pydriller/__init__.py b/pydriller/__init__.py index 3a12d64e..fe718e07 100644 --- a/pydriller/__init__.py +++ b/pydriller/__init__.py @@ -2,4 +2,4 @@ from .domain.commit import Commit, ModifiedFile, ModificationType # noqa from .repository import Repository, Git # noqa -__version__ = "2.7" +__version__ = "2.8" diff --git a/pydriller/domain/__init__.py b/pydriller/domain/__init__.py index bd19aad0..6ce45cc8 100644 --- a/pydriller/domain/__init__.py +++ b/pydriller/domain/__init__.py @@ -1,4 +1,4 @@ -from pydriller.utils.check_git_version import CheckGitVersion - - -CheckGitVersion().check_git_version() +# from pydriller.utils.check_git_version import CheckGitVersion +# +# +# CheckGitVersion().check_git_version() diff --git a/pydriller/domain/commit.py b/pydriller/domain/commit.py index 529a4aa0..48f93649 100644 --- a/pydriller/domain/commit.py +++ b/pydriller/domain/commit.py @@ -542,6 +542,7 @@ def __init__(self, commit: GitCommit, conf) -> None: """ self._c_object = commit self._conf = conf + self._stats_cache = None def __hash__(self) -> int: """ @@ -688,6 +689,9 @@ def merge(self) -> bool: return len(self._c_object.parents) > 1 def _stats(self): + if self._stats_cache is not None: + return self._stats_cache + if len(self.parents) == 0: text = self._conf.get('git').repo.git.diff_tree(self.hash, "--", numstat=True, root=True) text2 = "" @@ -698,7 +702,8 @@ def _stats(self): else: text = self._conf.get('git').repo.git.diff(self._c_object.parents[0].hexsha, self._c_object.hexsha, "--", numstat=True, root=True) - return self._list_from_string(text) + self._stats_cache = self._list_from_string(text) + return self._stats_cache def _list_from_string(self, text: str): total = {"insertions": 0, "deletions": 0, "lines": 0, "files": 0} diff --git a/pydriller/utils/check_git_version.py b/pydriller/utils/check_git_version.py index 43bb7cbb..90c5ffc2 100644 --- a/pydriller/utils/check_git_version.py +++ b/pydriller/utils/check_git_version.py @@ -1,19 +1,19 @@ -import subprocess -import re - - -class GitVersion(Exception): - def __init__(self, message): - super().__init__(message) - - -class CheckGitVersion: - def check_git_version(self): - git_version = ( - subprocess.check_output(["git", "--version"]).decode("ascii").strip() - ) - version_number = re.findall(r"[0-9]+\.[0-9]+", git_version)[0] - if float(version_number) < 2.38: - raise GitVersion( - f"Current git version is {version_number}. Minimum supported version is 2.38." - ) +# import subprocess +# import re +# +# +# class GitVersion(Exception): +# def __init__(self, message): +# super().__init__(message) +# +# +# class CheckGitVersion: +# def check_git_version(self): +# git_version = ( +# subprocess.check_output(["git", "--version"]).decode("ascii").strip() +# ) +# version_number = re.findall(r"[0-9]+\.[0-9]+", git_version)[0] +# if float(version_number) < 2.38: +# raise GitVersion( +# f"Current git version is {version_number}. Minimum supported version is 2.38." +# ) diff --git a/requirements.txt b/requirements.txt index ca2d13aa..4582c096 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ gitpython pytz types-pytz -lizard \ No newline at end of file +lizard==1.17.10 \ No newline at end of file diff --git a/setup.py b/setup.py index 02c30af2..bc5eace8 100644 --- a/setup.py +++ b/setup.py @@ -33,6 +33,8 @@ def get_version(): author_email='spadini.davide@gmail.com', version=get_version(), packages=find_packages('.', exclude=['tests*']), + include_package_data=True, + data_files=[('', ['requirements.txt', 'test-requirements.txt'])], url='https://github.com/ishepard/pydriller', license='Apache License', package_dir={'pydriller': 'pydriller'}, diff --git a/tests/test_check_git_version.py b/tests/test_check_git_version.py index 51c57b14..76a064d4 100644 --- a/tests/test_check_git_version.py +++ b/tests/test_check_git_version.py @@ -1,24 +1,24 @@ -from unittest.mock import patch -from pydriller.utils.check_git_version import CheckGitVersion, GitVersion -from contextlib import nullcontext as does_not_raise - -import pytest - - -@pytest.mark.parametrize( - "version_number,expectation", - [ - ("3.2.0", does_not_raise()), - ("2.38.1", does_not_raise()), - ("2.0.0", pytest.raises(GitVersion)), - ], -) -def test_extracts_correct_version(version_number, expectation): - with patch( - "pydriller.utils.check_git_version.subprocess.check_output" - ) as mock_git_version: - mock_git_version().decode.return_value.strip.return_value = ( - f"git version {version_number}" - ) - with expectation: - CheckGitVersion().check_git_version() +# from unittest.mock import patch +# from pydriller.utils.check_git_version import CheckGitVersion, GitVersion +# from contextlib import nullcontext as does_not_raise +# +# import pytest +# +# +# @pytest.mark.parametrize( +# "version_number,expectation", +# [ +# ("3.2.0", does_not_raise()), +# ("2.38.1", does_not_raise()), +# ("2.0.0", pytest.raises(GitVersion)), +# ], +# ) +# def test_extracts_correct_version(version_number, expectation): +# with patch( +# "pydriller.utils.check_git_version.subprocess.check_output" +# ) as mock_git_version: +# mock_git_version().decode.return_value.strip.return_value = ( +# f"git version {version_number}" +# ) +# with expectation: +# CheckGitVersion().check_git_version()