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

chore: add check for python-pinned-dependency count #532

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-20.04]
python-version: ['3.12']
toxenv: [python, quality]

Expand Down
8 changes: 5 additions & 3 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
# SERIOUSLY.
#
# ------------------------------
# Generated by edx-lint version: 5.3.6
# Generated by edx-lint version: 5.4.0
# ------------------------------
[MASTER]
ignore = ,.git,.tox
Expand Down Expand Up @@ -289,7 +289,9 @@ disable =
logging-fstring-interpolation,
django-not-available,
c-extension-no-member,
missing-timeout
missing-timeout,
possibly-used-before-assignment,
broad-exception-caught

[REPORTS]
output-format = text
Expand Down Expand Up @@ -386,4 +388,4 @@ int-import-graph =
[EXCEPTIONS]
overgeneral-exceptions = builtins.Exception

# 6ba39b4accf3da730ae894307bd8cd4a4e122ab3
# 0a144c96a050dac3a5cbf676c19bf5e8fa63eac2
6 changes: 4 additions & 2 deletions pylintrc_tweaks
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
ignore+ = ,.git,.tox

[MESSAGES CONTROL]
disable+ =
disable+ =
django-not-available,
c-extension-no-member,
missing-timeout
missing-timeout,
possibly-used-before-assignment,
broad-exception-caught

42 changes: 42 additions & 0 deletions repo_health/check_pinned_python_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Counts the python dependencies which are pinned
"""
import os

Check warning on line 4 in repo_health/check_pinned_python_dependencies.py

View check run for this annotation

Codecov / codecov/patch

repo_health/check_pinned_python_dependencies.py#L4

Added line #L4 was not covered by tests

import pytest

Check warning on line 6 in repo_health/check_pinned_python_dependencies.py

View check run for this annotation

Codecov / codecov/patch

repo_health/check_pinned_python_dependencies.py#L6

Added line #L6 was not covered by tests

from repo_health import get_file_content

Check warning on line 8 in repo_health/check_pinned_python_dependencies.py

View check run for this annotation

Codecov / codecov/patch

repo_health/check_pinned_python_dependencies.py#L8

Added line #L8 was not covered by tests

module_dict_key = "pinned_python_dependencies"

Check warning on line 10 in repo_health/check_pinned_python_dependencies.py

View check run for this annotation

Codecov / codecov/patch

repo_health/check_pinned_python_dependencies.py#L10

Added line #L10 was not covered by tests


def get_dependencies_count(repo_path, file_name):

Check warning on line 13 in repo_health/check_pinned_python_dependencies.py

View check run for this annotation

Codecov / codecov/patch

repo_health/check_pinned_python_dependencies.py#L13

Added line #L13 was not covered by tests
"""
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

Check warning on line 29 in repo_health/check_pinned_python_dependencies.py

View check run for this annotation

Codecov / codecov/patch

repo_health/check_pinned_python_dependencies.py#L20-L29

Added lines #L20 - L29 were not covered by tests
else:
continue
return dependency_count

Check warning on line 32 in repo_health/check_pinned_python_dependencies.py

View check run for this annotation

Codecov / codecov/patch

repo_health/check_pinned_python_dependencies.py#L31-L32

Added lines #L31 - L32 were not covered by tests


@pytest.mark.edx_health
def check_pinned_python_dependencies(repo_path, all_results):

Check warning on line 36 in repo_health/check_pinned_python_dependencies.py

View check run for this annotation

Codecov / codecov/patch

repo_health/check_pinned_python_dependencies.py#L35-L36

Added lines #L35 - L36 were not covered by tests
"""
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

Check warning on line 42 in repo_health/check_pinned_python_dependencies.py

View check run for this annotation

Codecov / codecov/patch

repo_health/check_pinned_python_dependencies.py#L40-L42

Added lines #L40 - L42 were not covered by tests
2 changes: 1 addition & 1 deletion repo_health/check_ubuntufiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
packages = self._prepare_data(list(packages))
return packages

except Exception as exc: # pylint: disable=broad-exception-caught
except Exception as exc:

Check warning on line 235 in repo_health/check_ubuntufiles.py

View check run for this annotation

Codecov / codecov/patch

repo_health/check_ubuntufiles.py#L235

Added line #L235 was not covered by tests
logger.exception("Following error occurred while parsing yml playbook (%s) in configuration repo: %s",
playbook_path, exc)
return []
Expand Down
4 changes: 2 additions & 2 deletions scripts/repo-health-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export LANG=C.UTF-8

WORKSPACE=$PWD
# If the REPORT_DATE variable is set and not an empty string parse the date to standardize it.
if [[ -n $REPORT_DATE ]]; then
if [[ -n $REPORT_DATE ]]; then
REPORT_DATE=$(date '+%Y-%m-%d' -d "$REPORT_DATE")
fi

Expand Down Expand Up @@ -104,7 +104,7 @@ while IFS= read -r line; do
--output-path "${ORG_DATA_DIR}/${OUTPUT_FILE_NAME}" \
-o log_cli=true --exitfirst --noconftest -v -c /dev/null
}

if REPO_HEALTH_COMMAND; then
true
elif REPO_HEALTH_COMMAND; then
Expand Down
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
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

Loading