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

fix: initial checks added for python and django #452

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2a4e862
fix: initial checks added for python and django
zubairshakoorarbisoft Nov 27, 2023
d385a59
fix: ETE testing samples added
zubairshakoorarbisoft Nov 30, 2023
25467bf
fix: github checks has been reused
zubairshakoorarbisoft Nov 30, 2023
7c87819
fix: setup_py all check reused and refactored
zubairshakoorarbisoft Nov 30, 2023
cfa86e3
fix: django packages code refactored for both dashboards
zubairshakoorarbisoft Dec 1, 2023
b1f26dc
fix: all reuseable checks added
zubairshakoorarbisoft Dec 1, 2023
1380e06
fix: requirements upgraded after adding toml
zubairshakoorarbisoft Dec 1, 2023
1314651
Merge branch 'master' into zshkoor/dependencies-dashboard
zubairshakoorarbisoft Dec 1, 2023
f41f210
fix: reuseable fixtures removed from repo_tool utils
zubairshakoorarbisoft Dec 4, 2023
fcbceb4
fix: sample dashboard csv removed
zubairshakoorarbisoft Dec 4, 2023
f8b8857
fix: dependency urls file removed
zubairshakoorarbisoft Dec 4, 2023
6bf80be
fix: removed python django tests temporarily
zubairshakoorarbisoft Dec 4, 2023
af125fc
fix: pylintrc rules fixed
zubairshakoorarbisoft Dec 4, 2023
eaf85e3
fix: isort applied
zubairshakoorarbisoft Dec 4, 2023
a1939a7
fix: dependencies_health folder added in quality command
zubairshakoorarbisoft Dec 4, 2023
4cb0ec7
fix: pylint issues fixed
zubairshakoorarbisoft Dec 4, 2023
9fd071f
fix: fixed quality checks
zubairshakoorarbisoft Dec 5, 2023
405d574
fix: fixed nested quality issues
zubairshakoorarbisoft Dec 5, 2023
f3d8a92
fix: separated fixture to fix quality issues
zubairshakoorarbisoft Dec 5, 2023
bd2dbd6
fix: fixed all quality issues
zubairshakoorarbisoft Dec 5, 2023
0b1eca2
fix: removed extra fixtures folder
zubairshakoorarbisoft Dec 5, 2023
087b5a1
fix: toml added in requirements
zubairshakoorarbisoft Dec 5, 2023
b643d03
Merge branch 'master' into zshkoor/dependencies-dashboard
zubairshakoorarbisoft Dec 5, 2023
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
5 changes: 5 additions & 0 deletions dependencies_health/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
A module that contains all the checks for dependencies dashboard
"""

__version__ = "1.0.0"
15 changes: 15 additions & 0 deletions dependencies_health/check_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
contains check that reads/parses dependencies of a repo
"""

from repo_health.check_dependencies import set_repo_dependencies


def check_dependencies(repo_path, all_results):
"""
Test to find the dependencies of the repo
"""
all_results = set_repo_dependencies(
all_results,
repo_path
)
48 changes: 48 additions & 0 deletions dependencies_health/check_django.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
Contains the check to check the Django versions releases
"""
import pytest

from dependencies_health.utils import (find_django_version_in_setup_py_classifier, get_default_branch, get_release_tags,
is_django_package)

module_dict_key = "django"


@pytest.fixture(name='repo_release_tags')
def fixture_repo_release_tags(repo_path):
"""Fixture containing the repo release tags"""
return get_release_tags(repo_path)


def check_django_support_releases(repo_release_tags, all_results, repo_path):
"""
Check to check the django versions in the releases
"""
if not repo_release_tags:
all_results[module_dict_key] = {}
print("There is not tag found")
return
django_versions = ['4.0', '4.1', '4.2']
all_results[module_dict_key] = {}
desc_tags_list = list(reversed(repo_release_tags))
if not is_django_package(repo_path):
all_results[module_dict_key]['has_django'] = False
return
# otherwise look for django version releases
all_results[module_dict_key]['has_django'] = True
for version in django_versions:
latest_tag_having_django_support = None
for tag in desc_tags_list:
if not find_django_version_in_setup_py_classifier(repo_path, tag, version):
if tag == desc_tags_list[0]: # try with default branch if the latest tag
default_branch = get_default_branch(repo_path)
if find_django_version_in_setup_py_classifier(repo_path, default_branch, version):
all_results[module_dict_key][version] = default_branch
else:
all_results[module_dict_key][version] = None
else:
all_results[module_dict_key][version] = latest_tag_having_django_support
break
# if django version found in config files then set it as lastest tag having django support
latest_tag_having_django_support = tag
22 changes: 22 additions & 0 deletions dependencies_health/check_django_dependencies_compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Contains check that reads/parses dependencies of a repo
"""

import logging

from repo_health.check_django_dependencies_compatibility import django_dependency_sheet_fixture, set_django_packages # pylint: disable=unused-import

logger = logging.getLogger(__name__)

MODULE_DICT_KEY = "django_packages"


def check_django_dependencies_status(repo_path, all_results, django_dependency_sheet):
"""
Test to find the django dependencies compatibility
"""
all_results = set_django_packages(
repo_path,
all_results,
django_dependency_sheet
)
27 changes: 27 additions & 0 deletions dependencies_health/check_github.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Checks repository is on github actions workflow and tests are enabled.
"""

from repo_health.check_github import set_branch_and_pr_count
from repo_health.utils import github_org_repo

module_dict_key = "github"


def check_github_actions_integration(all_results, git_origin_url):
"""
Checks repository's org name
"""
org_name = github_org_repo(git_origin_url)[0]
all_results[module_dict_key]['org_name'] = org_name


def check_branch_and_pr_count(all_results, git_origin_url):
"""
Checks repository branch and pr count
"""
all_results = set_branch_and_pr_count(
all_results,
git_origin_url,
module_dict_key
)
44 changes: 44 additions & 0 deletions dependencies_health/check_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Contains the checks to check the python versions releases
"""
import pytest

from dependencies_health.utils import find_python_version_in_config_files, get_default_branch, get_release_tags

module_dict_key = "python"


@pytest.fixture(name='repo_release_tags')
def fixture_repo_release_tags(repo_path):
"""Fixture containing the repo release tags"""
return get_release_tags(repo_path)


def check_python_support_releases(repo_release_tags, all_results, repo_path):
"""
Check to see the python version releases for 3.8, 3.9, 3.10, 3.11
"""
if not repo_release_tags:
all_results[module_dict_key] = {}
print("There is not tag found")
return
python_versions = ['3.8', '3.9', '3.10', '3.11']
all_results[module_dict_key] = {}
desc_tags_list = list(reversed(repo_release_tags))
for version in python_versions:
latest_tag_having_python_support = None
for tag in desc_tags_list:
if not find_python_version_in_config_files(repo_path, tag, version):
# try with the default latest/default branch if it is latest tag
# because support sometimes added in master or default branch and not released
if tag == desc_tags_list[0]:
default_branch = get_default_branch(repo_path)
if find_python_version_in_config_files(repo_path, default_branch, version):
all_results[module_dict_key][version] = default_branch
else:
all_results[module_dict_key][version] = None
else:
all_results[module_dict_key][version] = latest_tag_having_python_support
break
# if python version found in config files then set it as lastest tag having python support
latest_tag_having_python_support = tag
55 changes: 55 additions & 0 deletions dependencies_health/check_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Checks whether repo requires some libraries
"""
import glob
import os
import re

import pytest
from pytest_repo_health import health_metadata

from repo_health import get_file_lines

module_dict_key = "requires"


@pytest.fixture(name='req_lines')
def fixture_req_lines(repo_path):
"""
Fixture containing the text content of req_files
"""
files = glob.glob(os.path.join(repo_path, "requirements/**/*.in"), recursive=True)
req_lines = []
for file_path in files:
lines = get_file_lines(file_path)
req_lines.extend(lines)

return req_lines


@health_metadata(
[module_dict_key],
{
"django": "repo requires django",
"pytest": "repo requires pytest",
"nose": "repo requires nose",
"boto": "repo requires boto",
},
)
def check_requires(req_lines, all_results):
"""
Test to find whether repo requires some key requirements
"""
important_requirments = ["django", "pytest", "nose"]
for req in important_requirments:
all_results[module_dict_key][req] = False
for line in req_lines:
if re.search(req, line):
all_results[module_dict_key][req] = True

should_exact_match_requirements = ['boto']
for req in should_exact_match_requirements:
all_results[module_dict_key][req] = False
for line in req_lines:
if line.split('=')[0] == req:
all_results[module_dict_key][req] = True
61 changes: 61 additions & 0 deletions dependencies_health/check_setup_py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
Checks to see if setup.py follows minimum standards
And gathers info
"""

import re

from repo_health.check_setup_py import set_repo_url # pylint: disable=useless-suppression
from repo_health.check_setup_py import (fixture_python_version, fixture_setup_cfg, # pylint: disable=unused-import
fixture_setup_py, set_pypi_name)

module_dict_key = "setup_py"


def check_pypi_name(setup_py, setup_cfg, all_results):
"""
Get the name of the PyPI package for this repo.
"""
all_results = set_pypi_name(
all_results,
setup_py,
setup_cfg
)


def check_has_python_38_classifiers(python_version, all_results):
"""
Are there classifiers with python 3.8?
"""
all_results[module_dict_key]["py38_classifiers"] = "3.8" in python_version


def check_travis_python_versions(python_version, all_results):
"""
Add list of python versions to the results
"""
all_results[module_dict_key]["python_versions"] = python_version


def check_repo_url(setup_py, setup_cfg, all_results):
"""
Get the repo URL.
"""
all_results = set_repo_url(
all_results,
setup_py,
setup_cfg
)


def check_project_urls(setup_py, setup_cfg, all_results):
"""
Get the additional project URLs.
TODO: This captures the multi-line junk without parsing them out individually.
"""
py_urls = re.findall(r"""(?ms)^\s*project_urls\s*=\s*({[^}]+})""", setup_py)
cfg_urls = re.findall(r"""(?ms)^project_urls\s*=\s*(.*?)(?:^\S|^$)""", setup_cfg)
urls = py_urls + cfg_urls
if urls:
assert len(urls) == 1
all_results[module_dict_key]["project_urls"] = urls[0]
Loading