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

BREAK: Drop Support for python2 #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ You can help by picking an issue, or choosing to add a new test/feature (create
2. Install pre-commit & unit tests dependencies.
```bash
python3 -m pip install pre-commit python3-venv
python2 -m pip install virtualenv
```

3. Install pre-commit hooks.
Expand Down
2 changes: 0 additions & 2 deletions django_check_seo/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding:utf-8 -*-

# Third party
from django.apps import AppConfig

Expand Down
2 changes: 1 addition & 1 deletion django_check_seo/checks/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, soup, full_url):
if settings.DJANGO_CHECK_SEO_EXCLUDE_CONTENT != "":
# iterate through each body (should be only 1)
for body in self.content:
# and remove selecte blocks
# and remove selected blocks
for node in body.select(settings.DJANGO_CHECK_SEO_EXCLUDE_CONTENT):
node.extract()

Expand Down
2 changes: 0 additions & 2 deletions django_check_seo/checks_list/check_description.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Standard Library
import re

Expand Down
3 changes: 0 additions & 3 deletions django_check_seo/checks_list/check_h1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

# Standard Library
import re

Expand Down
3 changes: 0 additions & 3 deletions django_check_seo/checks_list/check_h2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

# Standard Library
import re

Expand Down
11 changes: 1 addition & 10 deletions django_check_seo/checks_list/check_keyword_url.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

# Standard Library
import re
import sys
from urllib.parse import urlparse # pragma: no cover

import unidecode
from django.conf import settings
Expand All @@ -14,12 +11,6 @@
# Local application / specific library imports
from ..checks import custom_list

# hacky trick to add python2 compatibility to a python3 project after python2 eol
if sys.version_info.major == 2:
from urlparse import urlparse # pragma: no cover
else:
from urllib.parse import urlparse # pragma: no cover


def importance():
"""Scripts with higher importance will be executed first.
Expand Down
26 changes: 2 additions & 24 deletions django_check_seo/checks_list/launch_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

from . import * # noqa: F403,F401

# hacky thing aiming to add python2 compatibility after eol of python2
try:
ModuleNotFoundError
except NameError:
ModuleNotFoundError = ImportError

try:
from checks_list import * # noqa: F403,F401

Expand All @@ -28,27 +22,11 @@ def launch_checks(site):

modules_order = []

# hacky trick to add python2 compatibility to a python3 project after python2 eol
python_2_compatibility_array = [
"django_check_seo.checks_list.launch_checks",
"django_check_seo.checks_list.glob",
"django_check_seo.checks_list.re",
"django_check_seo.checks_list.bs4",
"django_check_seo.checks_list.sys",
"django_check_seo.checks_list.os",
"django_check_seo.checks_list.importlib",
"django_check_seo.checks_list.urlparse",
"django_check_seo.checks_list.django",
"django_check_seo.checks_list.unidecode",
"django_check_seo.checks_list.__future__",
]
# TODO: CHECK AND VERIFY THAT ALL MODULES ARE STILL BEING IMPORTED

# only get modules in ...checks.*
for module_name in sys.modules:
if (
"django_check_seo.checks_list." in module_name
and module_name not in python_2_compatibility_array
) or (module_name.startswith("checks_list.")):
if module_name.startswith("checks_list."):
module = importlib.import_module(module_name)
get_module_order = getattr(module, "importance")

Expand Down
76 changes: 10 additions & 66 deletions launch_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

# django-check-seo super test-launching script
#
# requires python3-venv & python2 virtualenv
# requires python3-venv
#
# Usage:
# ./launch_tests.sh activate venv2 & venv3 (or create them & activate them),
# launch tests, deactivate venv2 & venv3
# ./launch_tests.sh 2 activate venv2 (or create it & activate it),
# ./launch_tests.sh activate venv2 (or create it & activate it),
# launch tests, deactivate venv2
# ./launch_tests.sh 3 activate venv3 (or create it & activate it),
# launch tests, deactivate venv3
# ./launch_tests.sh remove remove folders "venv2" & "venv3"
# ./launch_tests.sh remove remove folders for "venv2"
# ./launch_tests.sh help display this text

function remove {
Expand All @@ -27,28 +23,15 @@ function remove {
echo -e "\e[1;32m✅ nothing to remove\e[0m"
fi

if [[ -d "venv3" ]]; then

echo -e "\e[1;32m✅ test venv3 found\e[0m"
echo -e "\e[2m➡ removing venv3...\e[0m"
rm -r venv3
echo -e "\e[1;32m✅ test venv3 removed successfully\e[0m"
else
echo -e "\e[1;31m❌ test venv3 not found\e[0m"
echo -e "\e[1;32m✅ nothing to remove\e[0m"
fi

}

function display_help {

echo -e "django-check-seo super test-launching script"
echo
echo -e "Usage:"
echo -e " ./launch_tests.sh \e[2mactivate venv2 & venv3 (or create them & activate them), launch tests, deactivate venv2 & venv3\e[0m"
echo -e " ./launch_tests.sh 2 \e[2mactivate venv2 (or create it & activate it), launch tests, deactivate venv2\e[0m"
echo -e " ./launch_tests.sh 3 \e[2mactivate venv3 (or create it & activate it), launch tests, deactivate venv3\e[0m"
echo -e " ./launch_tests.sh remove \e[2mremove folders \"venv2\" & \"venv3\"\e[0m"
echo -e " ./launch_tests.sh \e[2mactivate venv2 & (or create it & activate it), launch tests, deactivate venv2\e[0m"
echo -e " ./launch_tests.sh remove \e[2mremove folders \"venv2\"\e[0m"
echo -e " ./launch_tests.sh help \e[2mdisplay this text\e[0m"

}
Expand All @@ -63,51 +46,22 @@ function create_and_launch_venv2 {

}

function create_and_launch_venv3 {

if [[ -d "venv3" ]]; then
launch_venv3_tests
else
create_venv3
fi

}

function launch_venv2_tests {

echo -e "\e[1;32m✅ test venv2 found\e[0m"
echo -e "\e[2m➡ launching tests...\e[0m"
. venv2/bin/activate && python2 -m pytest -s --cov-config=.coveragerc --cov=django_check_seo --cov-report term-missing && deactivate

}

function launch_venv3_tests {

echo -e "\e[1;32m✅ test venv3 found\e[0m"
echo -e "\e[2m➡ launching tests...\e[0m"
. venv3/bin/activate && python3 -m pytest -s --cov-config=.coveragerc --cov=django_check_seo --cov-report term-missing && deactivate
. venv2/bin/activate && python3 -m pytest -s --cov-config=.coveragerc --cov=django_check_seo --cov-report term-missing && deactivate

}

function create_venv2 {

echo -e "\e[1;31m❌ test venv2 not found\e[0m"
echo -e "\e[2m➡ creating venv2...\e[0m"
python2 -m virtualenv -p python2.7 venv2 1>/dev/null && . venv2/bin/activate && python2 -m pip install "django<3" bs4 lxml "easy-thumbnails==2.3" "djangocms-page-meta==0.8.5" requests pytest pytest-django pytest-cov 1>/dev/null && deactivate
python3 -m venv venv2 1>/dev/null && . venv2/bin/activate && python3 -m pip install django bs4 lxml djangocms-page-meta requests Unidecode pytest pytest-django pytest-cov 1>/dev/null && deactivate
echo -e "\e[1;32m✅ venv2 created successfully\e[0m"
echo -e "\e[2m➡ launching tests...\e[0m"
. venv2/bin/activate && python2 -m pytest -s --cov-config=.coveragerc --cov=django_check_seo --cov-report term-missing && deactivate

}

function create_venv3 {

echo -e "\e[1;31m❌ test venv3 not found\e[0m"
echo -e "\e[2m➡ creating venv3...\e[0m"
python3 -m venv venv3 1>/dev/null && . venv3/bin/activate && python3 -m pip install django bs4 lxml djangocms-page-meta requests pytest pytest-django pytest-cov 1>/dev/null && deactivate
echo -e "\e[1;32m✅ venv3 created successfully\e[0m"
echo -e "\e[2m➡ launching tests...\e[0m"
. venv3/bin/activate && python3 -m pytest -s --cov-config=.coveragerc --cov=django_check_seo --cov-report term-missing && deactivate
. venv2/bin/activate && python3 -m pytest -s --cov-config=.coveragerc --cov=django_check_seo --cov-report term-missing && deactivate

}

Expand All @@ -124,15 +78,9 @@ elif [[ $1 == "help" ]]; then

exit 1

elif [[ $1 == "2" ]]; then

create_and_launch_venv2

exit $?

elif [[ $1 == "3" ]]; then

create_and_launch_venv3
create_and_launch_venv2

exit $?

Expand All @@ -153,11 +101,7 @@ create_and_launch_venv2

exit1=$?

create_and_launch_venv3

exit2=$?

if [ "$exit1" -eq "0" ] && [ "$exit2" -eq "0" ]
if [ "$exit1" -eq "0" ]
then
exit 0
else
Expand Down
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ classifiers =
Intended Audience :: Developers
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Topic :: Internet :: WWW/HTTP
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Third party
from setuptools import setup

setup()
setup(python_requires=">=3.7")
3 changes: 1 addition & 2 deletions tests/test_content_words_number.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-

# Use ./launch_tests.sh to launch these tests.

import re

from bs4 import BeautifulSoup

from django_check_seo.checks import site

html_content = """
Expand Down
10 changes: 4 additions & 6 deletions tests/test_description.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# coding: utf-8

# Use ./launch_tests.sh to launch these tests.

from bs4 import BeautifulSoup

from django_check_seo.checks import site

html_content = """
Expand Down Expand Up @@ -145,8 +144,7 @@ def test_description_1_nokw_too_long_161():


def test_description_1_kw():
from django_check_seo.checks_list import check_keywords
from django_check_seo.checks_list import check_description
from django_check_seo.checks_list import check_description, check_keywords

site = init()

Expand All @@ -167,8 +165,7 @@ def test_description_1_kw():


def test_description_1_kws():
from django_check_seo.checks_list import check_keywords
from django_check_seo.checks_list import check_description
from django_check_seo.checks_list import check_description, check_keywords

site = init()

Expand Down Expand Up @@ -214,6 +211,7 @@ def test_description_1_length():

def test_description_2():
import copy

from django_check_seo.checks_list import check_description

site = init()
Expand Down
12 changes: 4 additions & 8 deletions tests/test_h1.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-

# Use ./launch_tests.sh to launch these tests.

from bs4 import BeautifulSoup

from django_check_seo.checks import site

html_content = """
Expand Down Expand Up @@ -122,8 +121,7 @@ def test_h1_1_nokw_image():


def test_h1_1_kw():
from django_check_seo.checks_list import check_h1
from django_check_seo.checks_list import check_keywords
from django_check_seo.checks_list import check_h1, check_keywords

site = init()

Expand All @@ -144,8 +142,7 @@ def test_h1_1_kw():


def test_h1_1_kws():
from django_check_seo.checks_list import check_h1
from django_check_seo.checks_list import check_keywords
from django_check_seo.checks_list import check_h1, check_keywords

site = init()
site.soup.find("h1").string = "Title of the page description"
Expand All @@ -169,8 +166,7 @@ def test_h1_1_kws():


def test_h1_1_kw_strange1():
from django_check_seo.checks_list import check_h1
from django_check_seo.checks_list import check_keywords
from django_check_seo.checks_list import check_h1, check_keywords

site = init()
site.soup.select('meta[name="keywords"]')[0]["content"] = "@letics"
Expand Down
Loading