diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a762b624a..c742c06d4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,33 +1,19 @@ -name: rosdistro-ci +--- +name: Run tests -on: +on: # yamllint disable-line rule:truthy push: - branches: [master] + branches: ['master'] pull_request: jobs: - build: - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - python: ['3.7', '3.8', '3.9', '3.10'] - include: - - os: ubuntu-18.04 - python: '2.7' - - os: ubuntu-18.04 - python: '3.6' - name: rosdistro tests - runs-on: ${{matrix.os}} - + pytest: + uses: ros-infrastructure/ci/.github/workflows/pytest.yaml@main + yamllint: + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{matrix.python}} - uses: actions/setup-python@v2 - with: - python-version: ${{matrix.python}} - - name: Install dependencies - run: | - python -m pip install -U -e .[test] pytest-cov -c constraints.txt - - name: Run tests - run: | - python -m pytest test --cov + - uses: actions/checkout@v4 + - run: >- + yamllint . + -f github + -d '{extends: default, ignore: [test/files/foo/*.yaml]}' diff --git a/constraints.txt b/constraints.txt deleted file mode 100644 index 628b53fb4..000000000 --- a/constraints.txt +++ /dev/null @@ -1,2 +0,0 @@ -pyparsing==2.4.7; python_version < '3' -PyYAML<6.0; python_version < '3' diff --git a/src/rosdistro/distribution_cache_generator.py b/src/rosdistro/distribution_cache_generator.py index a8f8e4d46..3e4e94ea6 100644 --- a/src/rosdistro/distribution_cache_generator.py +++ b/src/rosdistro/distribution_cache_generator.py @@ -107,7 +107,7 @@ def generate_distribution_cache(index, dist_name, preclean=False, ignore_local=F errors.append('%s: invalid package.xml file for package "%s": %s' % (dist_name, pkg_name, e)) continue # check that version numbers match (at least without deb inc) - if not re.match('^%s(-[\dA-z~\+\.]+)?$' % re.escape(pkg.version), repo.version): + if not re.match(r'^%s(-[\dA-z~\+\.]+)?$' % re.escape(pkg.version), repo.version): errors.append('%s: different version in package.xml (%s) for package "%s" than for the repository (%s) (after removing the debian increment)' % (dist_name, pkg.version, pkg_name, repo.version)) if package_xml != old_package_xml: diff --git a/src/rosdistro/external/appdirs.py b/src/rosdistro/external/appdirs.py index 13f5176db..fd29611f0 100644 --- a/src/rosdistro/external/appdirs.py +++ b/src/rosdistro/external/appdirs.py @@ -99,7 +99,7 @@ def user_data_dir(appname=None, appauthor=None, version=None, roaming=False): def site_data_dir(appname=None, appauthor=None, version=None, multipath=False): - """Return full path to the user-shared data dir for this application. + r"""Return full path to the user-shared data dir for this application. "appname" is the name of application. If None, just the system directory is returned. @@ -200,7 +200,7 @@ def user_config_dir(appname=None, appauthor=None, version=None, roaming=False): def site_config_dir(appname=None, appauthor=None, version=None, multipath=False): - """Return full path to the user-shared data dir for this application. + r"""Return full path to the user-shared data dir for this application. "appname" is the name of application. If None, just the system directory is returned. diff --git a/src/rosdistro/manifest_provider/tar.py b/src/rosdistro/manifest_provider/tar.py index 3338c6cbe..dc9af9b03 100644 --- a/src/rosdistro/manifest_provider/tar.py +++ b/src/rosdistro/manifest_provider/tar.py @@ -69,7 +69,7 @@ def tar_manifest_provider(_dist_name, repo, pkg_name): response = urlopen(request) with tarfile.open(fileobj=io.BytesIO(response.read())) as tar: - package_xml = tar.extractfile(os.path.join(subdir, 'package.xml')).read() + package_xml = tar.extractfile(subdir + '/package.xml').read() # Python2 returns strings, Python3 returns bytes-- support both try: diff --git a/src/rosdistro/release_cache_generator.py b/src/rosdistro/release_cache_generator.py index 0c0d14c57..b02aa1b31 100644 --- a/src/rosdistro/release_cache_generator.py +++ b/src/rosdistro/release_cache_generator.py @@ -96,7 +96,7 @@ def generate_release_cache(index, dist_name, preclean=False, debug=False): errors.append('%s: invalid package.xml file for package "%s"' % (dist_name, pkg_name)) continue # check that version numbers match (at least without deb inc) - if not re.match('^%s(-[\dA-z~\+\.]+)?$' % re.escape(pkg.version), repo.version): + if not re.match(r'^%s(-[\dA-z~\+\.]+)?$' % re.escape(pkg.version), repo.version): errors.append('%s: different version in package.xml (%s) for package "%s" than for the repository (%s) (after removing the debian increment)' % (dist_name, pkg.version, pkg_name, repo.version)) if not debug: diff --git a/src/rosdistro/repository_specification.py b/src/rosdistro/repository_specification.py index 7852b2b72..7a35aeead 100644 --- a/src/rosdistro/repository_specification.py +++ b/src/rosdistro/repository_specification.py @@ -38,7 +38,7 @@ class RepositorySpecification(object): # Match groups are server and path on server. - VCS_REGEX = re.compile('(?:https?:\/\/|ssh:\/\/|git:\/\/|git@)((?:[a-fA-F0-9]{40}@)?[\w.-]+)[:/]([\w/-]*)(?:\.git)?$') + VCS_REGEX = re.compile(r'(?:https?:\/\/|ssh:\/\/|git:\/\/|git@)((?:[a-fA-F0-9]{40}@)?[\w.-]+)[:/]([\w/-]*)(?:\.git)?$') def __init__(self, name, data): self.name = name diff --git a/src/rosdistro/vcs.py b/src/rosdistro/vcs.py index c959409b6..76448a1e4 100644 --- a/src/rosdistro/vcs.py +++ b/src/rosdistro/vcs.py @@ -67,7 +67,7 @@ def ref_is_hash(ref): def _run_command(cmd, cwd=None, env=None): result = {'cmd': ' '.join(cmd), 'cwd': cwd} try: - proc = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env) + proc = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, env=env) output, _ = proc.communicate() result['output'] = output.rstrip() result['returncode'] = proc.returncode diff --git a/stdeb.cfg b/stdeb.cfg index 76ca3f35d..866b0d4d3 100644 --- a/stdeb.cfg +++ b/stdeb.cfg @@ -12,7 +12,7 @@ Conflicts: python3-rosdistro Conflicts3: python-rosdistro Copyright-File: LICENSE.txt Suite: bionic cosmic disco eoan buster -Suite3: bionic cosmic disco eoan focal jammy buster bullseye +Suite3: focal jammy noble bookworm trixie Python2-Depends-Name: python X-Python3-Version: >= 3.4 Setup-Env-Vars: SKIP_PYTHON_MODULES=1 @@ -26,7 +26,7 @@ Replaces: python-rosdistro (<< 0.6.0) Replaces3: python3-rosdistro (<< 0.6.0) Copyright-File: LICENSE.txt Suite: bionic cosmic disco eoan buster -Suite3: bionic cosmic disco eoan focal jammy buster bullseye +Suite3: focal jammy noble bookworm trixie Python2-Depends-Name: python X-Python3-Version: >= 3.4 Setup-Env-Vars: SKIP_PYTHON_SCRIPTS=1 diff --git a/test/__init__.py b/test/__init__.py index 3cc149302..1b24935c2 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,6 +1,15 @@ import os import sys +try: + from urllib.parse import urljoin + from urllib.request import pathname2url +except ImportError: + from urlparse import urljoin + from urllib import pathname2url sys.path.insert(0, os.path.join( os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'src')) + +def path_to_url(path): + return urljoin('file:', pathname2url(path)) diff --git a/test/test_cache.py b/test/test_cache.py index 497af2216..0b3b53722 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -2,10 +2,12 @@ from rosdistro import get_distribution_cache, get_index +from . import path_to_url + FILES_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')) def test_get_release_cache(): - url = 'file://' + FILES_DIR + '/index_v2.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) i = get_index(url) get_distribution_cache(i, 'foo') diff --git a/test/test_distribution.py b/test/test_distribution.py index 1ea37aa4b..b84208b1c 100644 --- a/test/test_distribution.py +++ b/test/test_distribution.py @@ -6,11 +6,13 @@ import yaml +from . import path_to_url + FILES_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')) def test_distribution_file(): - url = 'file://' + FILES_DIR + '/foo/distribution.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'foo', 'distribution.yaml')) yaml_str = load_url(url) data = yaml.safe_load(yaml_str) dist_file = DistributionFile('foo', data) @@ -18,7 +20,7 @@ def test_distribution_file(): def test_get_distribution_file(): - url = 'file://' + FILES_DIR + '/index_v2.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) i = get_index(url) dist_file = get_distribution_file(i, 'foo') _validate_dist_file(dist_file) diff --git a/test/test_doc.py b/test/test_doc.py index 5dd04cc67..2d033353a 100644 --- a/test/test_doc.py +++ b/test/test_doc.py @@ -6,11 +6,13 @@ import yaml +from . import path_to_url + FILES_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')) def test_doc_file(): - url = 'file://' + FILES_DIR + '/foo/distribution.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'foo', 'distribution.yaml')) yaml_str = load_url(url) data = yaml.safe_load(yaml_str) doc_file = DocFile('foo', data) @@ -18,7 +20,7 @@ def test_doc_file(): def test_get_doc_file(): - url = 'file://' + FILES_DIR + '/index_v2.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) i = get_index(url) doc_file = get_doc_file(i, 'foo') _validate_doc_file(doc_file) diff --git a/test/test_doc_build.py b/test/test_doc_build.py index 4265975d6..86d4a8b52 100644 --- a/test/test_doc_build.py +++ b/test/test_doc_build.py @@ -6,18 +6,20 @@ import yaml +from . import path_to_url + FILES_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')) def test_doc_build_file(): - url = 'file://' + FILES_DIR + '/foo/doc-build.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'foo', 'doc-build.yaml')) yaml_str = load_url(url) data = yaml.safe_load(yaml_str) DocBuildFile('foo', data) def test_get_doc_build_files(): - url = 'file://' + FILES_DIR + '/index_v2.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) i = get_index(url) files = get_doc_build_files(i, 'foo') assert len(files) == 1 diff --git a/test/test_index.py b/test/test_index.py index 1208f8aa6..7a20292cc 100644 --- a/test/test_index.py +++ b/test/test_index.py @@ -5,6 +5,8 @@ from rosdistro import get_index from rosdistro import get_index_url +from . import path_to_url + FILES_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')) @@ -13,7 +15,7 @@ def test_get_index_url(): def test_get_index_v2(): - url = 'file://' + FILES_DIR + '/index_v2.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) i = get_index(url) assert len(i.distributions.keys()) == 1 assert 'foo' in i.distributions.keys() @@ -23,7 +25,7 @@ def test_get_index_v2(): def test_get_index_v3(): - url = 'file://' + FILES_DIR + '/index_v3.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v3.yaml')) i = get_index(url) assert len(i.distributions.keys()) == 1 assert 'foo' in i.distributions.keys() @@ -37,7 +39,7 @@ def test_get_index_v3(): def test_get_index_v3_invalid(): - url = 'file://' + FILES_DIR + '/index_v3_invalid.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v3_invalid.yaml')) i = get_index(url) dist_files = get_distribution_files(i, 'foo') @@ -50,7 +52,7 @@ def test_get_index_v3_invalid(): def test_get_index_v4(): - url = 'file://' + FILES_DIR + '/index_v4.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v4.yaml')) i = get_index(url) assert len(i.distributions.keys()) == 1 assert 'foo' in i.distributions.keys() diff --git a/test/test_manifest_providers.py b/test/test_manifest_providers.py index a9a4eb041..b4e5d953b 100644 --- a/test/test_manifest_providers.py +++ b/test/test_manifest_providers.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +import os + try: from unittest.mock import patch except ImportError: @@ -109,7 +111,7 @@ def test_git_source_multi(): repo_cache = git_source_manifest_provider(_ros_source_repo()) assert repo_cache.ref() package_path, package_xml = repo_cache['roslib'] - assert package_path == 'core/roslib' + assert package_path == os.path.join('core', 'roslib') def test_tar_source(): diff --git a/test/test_release.py b/test/test_release.py index 11421758d..9260d9620 100644 --- a/test/test_release.py +++ b/test/test_release.py @@ -6,11 +6,13 @@ import yaml +from . import path_to_url + FILES_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')) def test_release_file(): - url = 'file://' + FILES_DIR + '/foo/distribution.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'foo', 'distribution.yaml')) yaml_str = load_url(url) data = yaml.safe_load(yaml_str) rel_file = ReleaseFile('foo', data) @@ -18,7 +20,7 @@ def test_release_file(): def test_get_release_file(): - url = 'file://' + FILES_DIR + '/index_v2.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) i = get_index(url) rel_file = get_release_file(i, 'foo') _validate_rel_file(rel_file) diff --git a/test/test_release_build.py b/test/test_release_build.py index b53676c6b..30fe473df 100644 --- a/test/test_release_build.py +++ b/test/test_release_build.py @@ -6,24 +6,26 @@ import yaml +from . import path_to_url + FILES_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')) def test_release_build_file(): - url = 'file://' + FILES_DIR + '/foo/release-build.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'foo', 'release-build.yaml')) yaml_str = load_url(url) data = yaml.safe_load(yaml_str) ReleaseBuildFile('foo', data) def test_get_release_build_files(): - url = 'file://' + FILES_DIR + '/index_v2.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) i = get_index(url) get_release_build_files(i, 'foo') def test_get_release_builds(): - url = 'file://' + FILES_DIR + '/index_v2.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) i = get_index(url) d = get_release(i, 'foo') builds = get_release_builds(i, d) diff --git a/test/test_source.py b/test/test_source.py index 6c15757e0..8d0ba4571 100644 --- a/test/test_source.py +++ b/test/test_source.py @@ -6,11 +6,13 @@ import yaml +from . import path_to_url + FILES_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')) def test_source_file(): - url = 'file://' + FILES_DIR + '/foo/distribution.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'foo', 'distribution.yaml')) yaml_str = load_url(url) data = yaml.safe_load(yaml_str) src_file = SourceFile('foo', data) @@ -18,7 +20,7 @@ def test_source_file(): def test_get_source_file(): - url = 'file://' + FILES_DIR + '/index_v2.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) i = get_index(url) src_file = get_source_file(i, 'foo') _validate_src_file(src_file) diff --git a/test/test_source_build.py b/test/test_source_build.py index ac2ed7209..304f8653f 100644 --- a/test/test_source_build.py +++ b/test/test_source_build.py @@ -6,18 +6,20 @@ import yaml +from . import path_to_url + FILES_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')) def test_source_build_file(): - url = 'file://' + FILES_DIR + '/foo/source-build.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'foo', 'source-build.yaml')) yaml_str = load_url(url) data = yaml.safe_load(yaml_str) SourceBuildFile('foo', data) def test_get_source_build_files(): - url = 'file://' + FILES_DIR + '/index_v2.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) i = get_index(url) files = get_source_build_files(i, 'foo') assert len(files) == 1 diff --git a/test/test_verify.py b/test/test_verify.py index 5afe57c9e..5ceac5947 100644 --- a/test/test_verify.py +++ b/test/test_verify.py @@ -2,14 +2,16 @@ from rosdistro.verify import verify_files_identical, verify_files_parsable +from . import path_to_url + FILES_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')) def test_verify_files_parsable(): - index_url = 'file://' + FILES_DIR + '/index_v2.yaml' + index_url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) assert verify_files_parsable(index_url) def test_verify_files_identical(): - index_url = 'file://' + FILES_DIR + '/index_v2.yaml' + index_url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) assert verify_files_identical(index_url) diff --git a/test/test_writer.py b/test/test_writer.py index bc8ef7f03..9d5a32ea8 100644 --- a/test/test_writer.py +++ b/test/test_writer.py @@ -5,6 +5,8 @@ from rosdistro.writer import yaml_from_distribution_file +from . import path_to_url + FILES_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'files')) @@ -30,7 +32,7 @@ def get_diff(expected, actual): def test_verify_files_parsable(): - url = 'file://' + FILES_DIR + '/index_v2.yaml' + url = path_to_url(os.path.join(FILES_DIR, 'index_v2.yaml')) index = get_index(url) distribution_file = get_distribution_file(index, 'foo') data = yaml_from_distribution_file(distribution_file)