Skip to content

Commit

Permalink
Fix a number of warnings on Ubuntu 24.04. (#289)
Browse files Browse the repository at this point in the history
* Fix a number of warnings on Ubuntu 24.04.

In particular:
1.  Get rid of the fallback path for argcompleter.  It
    isn't necessary anymore since all versions of argcompleter
    support these, and it was confusing mypy.
2.  Add in a proper Optional annotation.
3.  Use the newer importlib_resources.file API when it is
    available.

* Add in appropriate dependency on python3-argcomplete.

Also do a minor refactoring of the dependencies while we
are here.

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette authored Feb 1, 2024
1 parent 0f1bc39 commit 73f1b0d
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 64 deletions.
8 changes: 4 additions & 4 deletions sros2/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
<author email="[email protected]">Morgan Quigley</author>
<author>Mikael Arguedas</author>

<depend>rclpy</depend>
<depend>ros2cli</depend>

<exec_depend>ament_index_python</exec_depend>
<exec_depend>python3-lxml</exec_depend>
<exec_depend>python3-argcomplete</exec_depend>
<exec_depend>python3-cryptography</exec_depend>
<exec_depend>python3-importlib-resources</exec_depend>
<exec_depend>python3-lxml</exec_depend>
<exec_depend>rclpy</exec_depend>
<exec_depend>ros2cli</exec_depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
Expand Down
4 changes: 2 additions & 2 deletions sros2/sros2/api/_artifact_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import pathlib
from typing import List
from typing import List, Optional

from sros2 import _utilities, keystore
from sros2.policy import load_policy
Expand All @@ -22,7 +22,7 @@


def generate_artifacts(
keystore_path: pathlib.Path = None,
keystore_path: Optional[pathlib.Path] = None,
identity_names: List[str] = [],
policy_files: List[pathlib.Path] = []) -> None:
if keystore_path is None:
Expand Down
26 changes: 14 additions & 12 deletions sros2/sros2/policy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,39 @@
POLICY_VERSION = '0.2.0'


def _get_path(template, name):
if hasattr(importlib_resources, 'files'):
return importlib_resources.files(template).joinpath(name)
else:
with importlib_resources.path(template, name) as path:
return path


def get_policy_default(name: str) -> pathlib.Path:
with importlib_resources.path('sros2.policy.defaults', name) as path:
return path
return _get_path('sros2.policy.defaults', name)


def get_policy_schema(name: str) -> pathlib.Path:
with importlib_resources.path('sros2.policy.schemas', name) as path:
return path
return _get_path('sros2.policy.schemas', name)


def get_policy_template(name: str) -> pathlib.Path:
with importlib_resources.path('sros2.policy.templates', name) as path:
return path
return _get_path('sros2.policy.templates', name)


def get_transport_default(transport: str, name: str) -> pathlib.Path:
module = 'sros2.policy.defaults.' + transport
with importlib_resources.path(module, name) as path:
return path
return _get_path(module, name)


def get_transport_schema(transport: str, name: str) -> pathlib.Path:
module = 'sros2.policy.schemas.' + transport
with importlib_resources.path(module, name) as path:
return path
return _get_path(module, name)


def get_transport_template(transport: str, name: str) -> pathlib.Path:
module = 'sros2.policy.templates.' + transport
with importlib_resources.path(module, name) as path:
return path
return _get_path(module, name)


def load_policy(policy_file_path: pathlib.Path) -> etree.ElementTree:
Expand Down
6 changes: 1 addition & 5 deletions sros2/sros2/verb/create_enclave.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
import sys
import warnings

try:
from argcomplete.completers import DirectoriesCompleter
except ImportError:
def DirectoriesCompleter():
return None
from argcomplete.completers import DirectoriesCompleter

import sros2.keystore
from sros2.verb import VerbExtension
Expand Down
6 changes: 1 addition & 5 deletions sros2/sros2/verb/create_keystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
import pathlib
import sys

try:
from argcomplete.completers import DirectoriesCompleter
except ImportError:
def DirectoriesCompleter():
return None
from argcomplete.completers import DirectoriesCompleter

import sros2.errors
import sros2.keystore
Expand Down
12 changes: 2 additions & 10 deletions sros2/sros2/verb/create_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,8 @@
import pathlib
import sys

try:
from argcomplete.completers import DirectoriesCompleter
except ImportError:
def DirectoriesCompleter():
return None
try:
from argcomplete.completers import FilesCompleter
except ImportError:
def FilesCompleter(*, allowednames, directories):
return None
from argcomplete.completers import DirectoriesCompleter
from argcomplete.completers import FilesCompleter

import sros2.keystore
from sros2.verb import VerbExtension
Expand Down
12 changes: 2 additions & 10 deletions sros2/sros2/verb/generate_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,8 @@
import pathlib
import sys

try:
from argcomplete.completers import DirectoriesCompleter
except ImportError:
def DirectoriesCompleter():
return None
try:
from argcomplete.completers import FilesCompleter
except ImportError:
def FilesCompleter(*, allowednames, directories):
return None
from argcomplete.completers import DirectoriesCompleter
from argcomplete.completers import FilesCompleter

from sros2.api import _artifact_generation
import sros2.errors
Expand Down
11 changes: 1 addition & 10 deletions sros2/sros2/verb/generate_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@
import pathlib
import sys

try:
from argcomplete.completers import DirectoriesCompleter
except ImportError:
def DirectoriesCompleter():
return None
try:
from argcomplete.completers import FilesCompleter
except ImportError:
def FilesCompleter(*, allowednames, directories):
return None
from argcomplete.completers import FilesCompleter

from lxml import etree

Expand Down
8 changes: 2 additions & 6 deletions sros2/sros2/verb/list_enclaves.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

try:
from argcomplete.completers import DirectoriesCompleter
except ImportError:
def DirectoriesCompleter():
return None

import pathlib
import sys
import warnings

from argcomplete.completers import DirectoriesCompleter

import sros2.keystore
from sros2.verb import VerbExtension

Expand Down

0 comments on commit 73f1b0d

Please sign in to comment.