Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ModifiedFile.content and deprecating ModifiedFile.source_code #220

Merged
merged 4 commits into from
Jun 17, 2022
Merged

Adding ModifiedFile.content and deprecating ModifiedFile.source_code #220

merged 4 commits into from
Jun 17, 2022

Conversation

stefanodallapalma
Copy link
Contributor

@stefanodallapalma stefanodallapalma commented Jun 14, 2022

This pull request should address #216, open to discuss modifications and refactoring operations.

I believe source_code is a core property used by many and therefore should not be refactored to content any time soon. Instead, it should be deprecated and then removed in a future version of PyDriller. Therefore, this pull request addresses issue #216 by adding the class variables content and content_before that behave exactly like source_code and source_code_before; the latter have been also translated to properties to warn the user about their deprecation.

Test cases using property source_code and source_code_before. Checked ☑️ if modified for DeprecationWarning and testing the new property content:

  • tests/test_commit/test_source_code_before()
  • tests/test_commit/test_source_code_before_complete()
  • tests/test_commit/test_filename()
  • tests/test_commit/test_metrics_python()
  • tests/test_commit/test_metrics_cpp()
  • tests/test_commit/test_metrics_java()
  • tests/test_commit/test_metrics_not_supported_file()
  • tests/test_git_repository/test_should_detail_a_commit()

Methods in ModifiedFile that use source_code or source_code_before. Checked ☑️ if modified to warn deprecation and to include the new property content:

  • init()
  • self.source_code has been renamed to self.__source_code to handle DeprecationWarning in a new method/property source_code().
  • self.source_code_before has been renamed to self.__source_code_before to handle DeprecationWarning in a new method/property source_code_before().
  • Added self.content and self.content_before.
  • hash()
  • self.source_code replaced by self.content to generate hashable string.
  • _calculate_metrics()
  • Refactor source_code and source_code_before to content and content_before.

Methods in Commit that use source_code or source_code_before.

  • _parse_diff()
  • Added key:value pairs content_before and content to the diff_and_sc dictionary that is passed to ModifiedFile.

Future refactoring:

  • Rename diff_and_sc -> diff_and_content in commit.py.

stefanodallapalma added 4 commits June 14, 2022 11:32
…e.source_code with modified_file.content and catch DeprecationWarning on modified_file.source_code
… and added test case for ModifiedFile.content
@codecov
Copy link

codecov bot commented Jun 14, 2022

Codecov Report

Merging #220 (fd76387) into master (58ae15e) will decrease coverage by 0.16%.
The diff coverage is 90.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #220      +/-   ##
==========================================
- Coverage   98.34%   98.18%   -0.17%     
==========================================
  Files          15       15              
  Lines        1028     1045      +17     
==========================================
+ Hits         1011     1026      +15     
- Misses         17       19       +2     
Impacted Files Coverage Δ
pydriller/domain/commit.py 98.18% <90.00%> (-0.46%) ⬇️

@ishepard ishepard merged commit a0f8fc3 into ishepard:master Jun 17, 2022
@ishepard
Copy link
Owner

LGTM! Thanks for making the change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants