-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: added pinned python dependency count check (#532)
- Loading branch information
1 parent
0971dee
commit 9107ccb
Showing
8 changed files
with
104 additions
and
9 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
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,42 @@ | ||
""" | ||
Counts the python dependencies which are pinned | ||
""" | ||
import os | ||
|
||
import pytest | ||
|
||
from repo_health import get_file_content | ||
|
||
module_dict_key = "pinned_python_dependencies" | ||
|
||
|
||
def get_dependencies_count(repo_path, file_name): | ||
""" | ||
entry point to read requirements from constraints and common-constraints | ||
@param repo_path: | ||
@param file_name: | ||
@return: number. | ||
""" | ||
full_path = os.path.join(repo_path, "requirements/{0}".format(file_name)) | ||
content = get_file_content(full_path) | ||
lines = content.split('\n') | ||
dependency_count = 0 | ||
pinned_dependencies_marker = ['==', '>', '<'] | ||
for line in lines: | ||
if line.startswith('#'): | ||
continue | ||
if any(marker in line for marker in pinned_dependencies_marker): | ||
dependency_count += 1 | ||
else: | ||
continue | ||
return dependency_count | ||
|
||
|
||
@pytest.mark.edx_health | ||
def check_pinned_python_dependencies(repo_path, all_results): | ||
""" | ||
We shall read constraints file | ||
""" | ||
constraints_count = get_dependencies_count(repo_path, 'common_constraints.txt') | ||
common_constraints_count = get_dependencies_count(repo_path, 'constraints.txt') | ||
all_results[module_dict_key] = constraints_count + common_constraints_count |
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
24 changes: 24 additions & 0 deletions
24
tests/fake_repos/python_pinned_dependencies/requirements/common_constraints.txt
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,24 @@ | ||
|
||
# A central location for most common version constraints | ||
# (across edx repos) for pip-installation. | ||
# | ||
# Similar to other constraint files this file doesn't install any packages. | ||
# It specifies version constraints that will be applied if a package is needed. | ||
# When pinning something here, please provide an explanation of why it is a good | ||
# idea to pin this package across all edx repos, Ideally, link to other information | ||
# that will help people in the future to remove the pin when possible. | ||
# Writing an issue against the offending project and linking to it here is good. | ||
# | ||
# Note: Changes to this file will automatically be used by other repos, referencing | ||
# this file from Github directly. It does not require packaging in edx-lint. | ||
|
||
|
||
# using LTS django version | ||
Django<5.0 | ||
|
||
# elasticsearch>=7.14.0 includes breaking changes in it which caused issues in discovery upgrade process. | ||
# elastic search changelog: https://www.elastic.co/guide/en/enterprise-search/master/release-notes-7.14.0.html | ||
elasticsearch<7.14.0 | ||
|
||
# django-simple-history>3.0.0 adds indexing and causes a lot of migrations to be affected | ||
django-simple-history==3.0.0 |
25 changes: 25 additions & 0 deletions
25
tests/fake_repos/python_pinned_dependencies/requirements/constraints.txt
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,25 @@ | ||
|
||
# A central location for most common version constraints | ||
# (across edx repos) for pip-installation. | ||
# | ||
# Similar to other constraint files this file doesn't install any packages. | ||
# It specifies version constraints that will be applied if a package is needed. | ||
# When pinning something here, please provide an explanation of why it is a good | ||
# idea to pin this package across all edx repos, Ideally, link to other information | ||
# that will help people in the future to remove the pin when possible. | ||
# Writing an issue against the offending project and linking to it here is good. | ||
# | ||
# Note: Changes to this file will automatically be used by other repos, referencing | ||
# this file from Github directly. It does not require packaging in edx-lint. | ||
|
||
|
||
# using LTS django version | ||
Django<5.0 | ||
|
||
# elasticsearch>=7.14.0 includes breaking changes in it which caused issues in discovery upgrade process. | ||
# elastic search changelog: https://www.elastic.co/guide/en/enterprise-search/master/release-notes-7.14.0.html | ||
elasticsearch<7.14.0 | ||
|
||
# django-simple-history>3.0.0 adds indexing and causes a lot of migrations to be affected | ||
django-simple-history==3.0.0 | ||
|