Skip to content
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
21 changes: 10 additions & 11 deletions data/templates/check_dependencies-with_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
import sys

# Change PYTHONPATH to include dependencies.
sys.path.insert(0, '.')
sys.path.insert(0, ".")

import utils.dependencies # pylint: disable=wrong-import-position

if __name__ == "__main__":
dependency_helper = utils.dependencies.DependencyHelper()

if __name__ == '__main__':
dependency_helper = utils.dependencies.DependencyHelper()
if not dependency_helper.CheckDependencies():
build_instructions_url = (
"https://${project_name}.readthedocs.io/en/latest/sources/user/Users-Guide.html"
)
print(f"See: {build_instructions_url:s} on how to set up ${project_name}.")
print("")

if not dependency_helper.CheckDependencies():
build_instructions_url = (
'https://${project_name}.readthedocs.io/en/latest/sources/user/Users-Guide.html')

print(f'See: {build_instructions_url:s} on how to set up ${project_name}.')
print('')

sys.exit(1)
sys.exit(1)
295 changes: 155 additions & 140 deletions data/templates/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Functionality to check for the availability and version of dependencies.

This file is generated by l2tdevtools update-dependencies.py, any dependency
related changes should be made in dependencies.ini.
This file is generated by l2tdevtools update-dependencies.py, any dependency related
changes should be made in dependencies.ini.
"""

import re


# Dictionary that contains version tuples per module name.
#
# A version tuple consists of:
Expand All @@ -15,158 +14,174 @@
# Where version_attribute_name is either a name of an attribute,
# property or method.
PYTHON_DEPENDENCIES = {
${python_dependencies}}
${python_dependencies}
}

_VERSION_SPLIT_REGEX = re.compile(r'\.|\-')
_VERSION_SPLIT_REGEX = re.compile(r"\.|\-")


def _CheckPythonModule(
module_name, version_attribute_name, minimum_version,
is_required=True, maximum_version=None, verbose_output=True):
"""Checks the availability of a Python module.

Args:
module_name (str): name of the module.
version_attribute_name (str): name of the attribute that contains
the module version or method to retrieve the module version.
minimum_version (str): minimum required version.
is_required (Optional[bool]): True if the Python module is a required
dependency.
maximum_version (Optional[str]): maximum required version. Should only be
used if there is a later version that is not supported.
verbose_output (Optional[bool]): True if output should be verbose.

Returns:
bool: True if the Python module is available and conforms to
the minimum required version, False otherwise.
"""
module_object = _ImportPythonModule(module_name)
if not module_object:
if not is_required:
print(f'[OPTIONAL]\tmissing: {module_name:s}.')
return True

print(f'[FAILURE]\tmissing: {module_name:s}.')
return False

if not version_attribute_name or not minimum_version:
if verbose_output:
print(f'[OK]\t\t{module_name:s}')
return True

module_version = None
if not version_attribute_name.endswith('()'):
module_version = getattr(module_object, version_attribute_name, None)
else:
version_method = getattr(module_object, version_attribute_name[:-2], None)
if version_method:
module_version = version_method()

if not module_version:
if not is_required:
print((
f'[OPTIONAL]\tunable to determine version information '
f'for: {module_name:s}'))
return True

print((
f'[FAILURE]\tunable to determine version information '
f'for: {module_name:s}'))
return False

# Make sure the module version is a string.
module_version = f'{module_version!s}'

# Remove a version suffix, such as: 0.7.0~rc1
module_version_list = _VERSION_SPLIT_REGEX.split(module_version)

try:
int(module_version_list[-1], 10)
except (TypeError, ValueError):
module_version_list.pop()

# Split the version string and convert every digit into an integer.
# A string compare of both version strings will yield an incorrect result.
module_version_map = list(map(int, module_version_list))
minimum_version_map = list(
map(int, _VERSION_SPLIT_REGEX.split(minimum_version)))

if module_version_map < minimum_version_map:
if not is_required:
print((
f'[OPTIONAL]\t{module_name:s} version: {module_version!s} is too '
f'old, {minimum_version!s} or later required.'))
return True

print((
f'[FAILURE]\t{module_name:s} version: {module_version!s} is too old, '
f'{minimum_version!s} or later required.'))
return False

if maximum_version:
maximum_version_map = list(
map(int, _VERSION_SPLIT_REGEX.split(maximum_version)))
if module_version_map > maximum_version_map:
if not is_required:
print((
f'[OPTIONAL]\t{module_name:s} version: {module_version!s} is too '
f'recent, {minimum_version!s} or earlier required.'))
module_name,
version_attribute_name,
minimum_version,
is_required=True,
maximum_version=None,
verbose_output=True,
):
"""Checks the availability of a Python module.

Args:
module_name (str): name of the module.
version_attribute_name (str): name of the attribute that contains
the module version or method to retrieve the module version.
minimum_version (str): minimum required version.
is_required (Optional[bool]): True if the Python module is a required
dependency.
maximum_version (Optional[str]): maximum required version. Should only be
used if there is a later version that is not supported.
verbose_output (Optional[bool]): True if output should be verbose.

Returns:
bool: True if the Python module is available and conforms to
the minimum required version, False otherwise.
"""
module_object = _ImportPythonModule(module_name)
if not module_object:
if not is_required:
print(f"[OPTIONAL]\tmissing: {module_name:s}.")
return True

print(f"[FAILURE]\tmissing: {module_name:s}.")
return False

if not version_attribute_name or not minimum_version:
if verbose_output:
print(f"[OK]\t\t{module_name:s}")
return True

print((
f'[FAILURE]\t{module_name:s} version: {module_version!s} is too '
f'recent, {maximum_version!s} or earlier required.'))
return False
module_version = None
if not version_attribute_name.endswith("()"):
module_version = getattr(module_object, version_attribute_name, None)
else:
version_method = getattr(module_object, version_attribute_name[:-2], None)
if version_method:
module_version = version_method()

if not module_version:
if not is_required:
print(
f"[OPTIONAL]\tunable to determine version information "
f"for: {module_name:s}"
)
return True

print(
f"[FAILURE]\tunable to determine version information "
f"for: {module_name:s}"
)
return False

# Make sure the module version is a string.
module_version = f"{module_version!s}"

# Remove a version suffix, such as: 0.7.0~rc1
module_version_list = _VERSION_SPLIT_REGEX.split(module_version)

try:
int(module_version_list[-1], 10)
except (TypeError, ValueError):
module_version_list.pop()

# Split the version string and convert every digit into an integer.
# A string compare of both version strings will yield an incorrect result.
module_version_map = list(map(int, module_version_list))
minimum_version_map = list(map(int, _VERSION_SPLIT_REGEX.split(minimum_version)))

if module_version_map < minimum_version_map:
if not is_required:
print(
f"[OPTIONAL]\t{module_name:s} version: {module_version!s} is too "
f"old, {minimum_version!s} or later required."
)
return True

print(
f"[FAILURE]\t{module_name:s} version: {module_version!s} is too old, "
f"{minimum_version!s} or later required."
)
return False

if maximum_version:
maximum_version_map = list(
map(int, _VERSION_SPLIT_REGEX.split(maximum_version))
)
if module_version_map > maximum_version_map:
if not is_required:
print(
f"[OPTIONAL]\t{module_name:s} version: {module_version!s} is too "
f"recent, {minimum_version!s} or earlier required."
)
return True

print(
f"[FAILURE]\t{module_name:s} version: {module_version!s} is too "
f"recent, {maximum_version!s} or earlier required."
)
return False

if verbose_output:
print(f'[OK]\t\t{module_name:s} version: {module_version!s}')
if verbose_output:
print(f"[OK]\t\t{module_name:s} version: {module_version!s}")

return True
return True


def _ImportPythonModule(module_name):
"""Imports a Python module.
"""Imports a Python module.

Args:
module_name (str): name of the module.
Args:
module_name (str): name of the module.

Returns:
module: Python module or None if the module cannot be imported.
"""
try:
module_object = list(map(__import__, [module_name]))[0]
except ImportError:
return None
Returns:
module: Python module or None if the module cannot be imported.
"""
try:
module_object = list(map(__import__, [module_name]))[0]
except ImportError:
return None

# If the module name contains dots get the upper most module object.
if '.' in module_name:
for submodule_name in module_name.split('.')[1:]:
module_object = getattr(module_object, submodule_name, None)
# If the module name contains dots get the upper most module object.
if "." in module_name:
for submodule_name in module_name.split(".")[1:]:
module_object = getattr(module_object, submodule_name, None)

return module_object
return module_object


def CheckDependencies(verbose_output=True):
"""Checks the availability of the dependencies.

Args:
verbose_output (Optional[bool]): True if output should be verbose.

Returns:
bool: True if the dependencies are available, False otherwise.
"""
print('Checking availability and versions of dependencies.')
check_result = True

for module_name, version_tuple in sorted(PYTHON_DEPENDENCIES.items()):
if not _CheckPythonModule(
module_name, version_tuple[0], version_tuple[1],
is_required=version_tuple[3], maximum_version=version_tuple[2],
verbose_output=verbose_output):
check_result = False

if check_result and not verbose_output:
print('[OK]')

print('')
return check_result
"""Checks the availability of the dependencies.

Args:
verbose_output (Optional[bool]): True if output should be verbose.

Returns:
bool: True if the dependencies are available, False otherwise.
"""
print("Checking availability and versions of dependencies.")
check_result = True

for module_name, version_tuple in sorted(PYTHON_DEPENDENCIES.items()):
if not _CheckPythonModule(
module_name,
version_tuple[0],
version_tuple[1],
is_required=version_tuple[3],
maximum_version=version_tuple[2],
verbose_output=verbose_output,
):
check_result = False

if check_result and not verbose_output:
print("[OK]")

print("")
return check_result
5 changes: 5 additions & 0 deletions data/templates/pyproject.toml/docformatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

[tool.docformatter]
black = true
non-cap = ${docformatter_non_cap}
non-strict = true
2 changes: 1 addition & 1 deletion data/templates/tox.ini/testenv_black
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ deps =
setuptools >= 65
commands =
black --version
black --check .
black .
16 changes: 16 additions & 0 deletions data/templates/tox.ini/testenv_docformatter
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

[testenv:docformatter]
skipsdist = True
pip_pre = True
passenv =
CFLAGS
CPPFLAGS
LDFLAGS
setenv =
PYTHONPATH = {toxinidir}
deps =
docformatter
setuptools >= 65
commands =
docformatter --version
docformatter --in-place --recursive ${paths_to_lint_python}
Loading
Loading