Skip to content

Commit

Permalink
Package wide linting fixes (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jprestwo authored Jul 2, 2024
1 parent ce415e6 commit f250d45
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
18 changes: 14 additions & 4 deletions ament_cmake_virtualenv/cmake/ament_generate_virtualenv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,13 @@ function(ament_generate_virtualenv)
_ament_cmake_python_install_module(${ARGN})
get_filename_component(module_path ${ARGN} NAME)
set(module_path "${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_DIR}/${module_path}")
# message(WARNING "[ament_cmake_virtualenv]: ament_python_install_module override for ${module_path} to ${${PROJECT_NAME}_VENV_INSTALL_DIR}")
install(CODE "execute_process(COMMAND ${wrap_module_BIN} --module-path ${module_path} --venv-install-dir ${${PROJECT_NAME}_VENV_INSTALL_DIR})")
# message(
# WARNING "[ament_cmake_virtualenv]: ament_python_install_module override for ${module_path} to ${${PROJECT_NAME}_VENV_INSTALL_DIR}"
# )
install(
CODE "execute_process(\
COMMAND ${wrap_module_BIN} --module-path ${module_path} --venv-install-dir ${${PROJECT_NAME}_VENV_INSTALL_DIR})"
)
endmacro()

# Override the ament_python_install_package macro to wrap packages
Expand All @@ -153,7 +158,12 @@ function(ament_generate_virtualenv)
_ament_cmake_python_register_environment_hook()
_ament_cmake_python_install_package(${ARGN})
set(package_dir "${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_DIR}/${ARGN}")
# message(WARNING "[ament_cmake_virtualenv]: ament_python_install_package override for ${package_dir} to ${${PROJECT_NAME}_VENV_INSTALL_DIR}")
install(CODE "execute_process(COMMAND ${wrap_package_BIN} --package-dir ${package_dir} --venv-install-dir ${${PROJECT_NAME}_VENV_INSTALL_DIR})")
# message(
# WARNING "[ament_cmake_virtualenv]: ament_python_install_package override for ${package_dir} to ${${PROJECT_NAME}_VENV_INSTALL_DIR}"
# )
install(
CODE "execute_process(\
COMMAND ${wrap_package_BIN} --package-dir ${package_dir} --venv-install-dir ${${PROJECT_NAME}_VENV_INSTALL_DIR})"
)
endmacro()
endfunction()
9 changes: 6 additions & 3 deletions ament_virtualenv/ament_virtualenv/combine_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import re
import sys

from typing import List, Dict
from io import TextIOWrapper
from collections import namedtuple
from packaging.requirements import Requirement, InvalidRequirement

Expand All @@ -43,9 +45,10 @@
SuppressedRequirement = namedtuple("SuppressedRequirement", "requirement source")


def combine_requirements(requirements_list, output_file):
# type: (List[IO], IO) -> int
combined_requirements = {} # type: Dict[str, requirements.Requirement]
def combine_requirements(
requirements_list: List[TextIOWrapper], output_file: TextIOWrapper
) -> int:
combined_requirements: Dict[str, Requirement] = {}
for requirements_file in requirements_list:
contents = requirements_file.read()

Expand Down
6 changes: 4 additions & 2 deletions ament_virtualenv/ament_virtualenv/glob_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import sys
import os

from typing import List
from catkin_pkg.package import Package

try:
from ament_virtualenv.package import parse_package
except ImportError:
Expand Down Expand Up @@ -112,8 +115,7 @@ def find_in_workspaces(project, file, workspaces=[]):
AMENT_VIRTUALENV_TAGNAME = "pip_requirements"


def parse_exported_requirements(package):
# type: (catkin_pkg.package.Package) -> List[str]
def parse_exported_requirements(package: Package) -> List[str]:
requirements_list = []
for export in package.exports:
if export.tagname == AMENT_VIRTUALENV_TAGNAME:
Expand Down
18 changes: 12 additions & 6 deletions ament_virtualenv/ament_virtualenv/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def __init__(self, filename=None, **kwargs):
slot.append(deepcopy(d))
del kwargs['run_depends']
self.filename = filename
self.licenses = [l if isinstance(l, License) else License(l) for l in self.licenses]
self.licenses = [
licence if isinstance(licence, License) else
License(licence) for licence in self.licenses
]
# verify that no unknown keywords are passed
unknown = set(kwargs.keys()).difference(self.__slots__)
if unknown:
Expand Down Expand Up @@ -217,15 +220,18 @@ def validate(self, warnings=None):
'with a lower case letter and only contain lower case letters, digits, '
'underscores, and dashes.' % self.name)

version_regexp = '^[0-9]+\.[0-9]+\.[0-9]+$'
version_regexp = '^[0-9]+\.[0-9]+\.[0-9]+$' # noqa: W605
if not self.version:
errors.append('Package version must not be empty')
elif not re.match(version_regexp, self.version):
errors.append(
'Package version "%s" does not follow version conventions'
% self.version
)
elif not re.match('^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$', self.version):
elif not re.match(
'^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$', # noqa: W605
self.version
):
new_warnings.append(
'Package "%s" does not follow the version conventions. '
'It should not contain leading zeros (unless the number is 0).' % self.name
Expand All @@ -251,7 +257,7 @@ def validate(self, warnings=None):

if not self.licenses:
errors.append('The package node must contain at least one "license" tag')
if [l for l in self.licenses if not l.strip()]:
if [license for license in self.licenses if not license.strip()]:
errors.append('The license tag must neither be empty nor only contain whitespaces')

if self.authors is not None:
Expand Down Expand Up @@ -389,8 +395,8 @@ def validate(self):
if self.email is None:
return
_pattern = (
'^[-a-zA-Z0-9_%+]+(\.[-a-zA-Z0-9_%+]+)*'
'@[-a-zA-Z0-9%]+(\.[-a-zA-Z0-9%]+)*\.[a-zA-Z]{2,}$'
'^[-a-zA-Z0-9_%+]+(\.[-a-zA-Z0-9_%+]+)*' # noqa: W605
'@[-a-zA-Z0-9%]+(\.[-a-zA-Z0-9%]+)*\.[a-zA-Z]{2,}$' # noqa: W605
)
if not re.match(_pattern, self.email):
raise InvalidPackage('Invalid email "%s" for person "%s"' % (self.email, self.name))
Expand Down

0 comments on commit f250d45

Please sign in to comment.