From 730fdcccc22fe0e459406e04b6c61de846ef5aad Mon Sep 17 00:00:00 2001 From: Christian Henkel <6976069+ct2034@users.noreply.github.com> Date: Tue, 18 Jul 2023 14:06:04 +0200 Subject: [PATCH] Preparation for PyPI release (#25) * metadata by pyproject.toml * no ref to the bin file any more * proper handling of missing args * updating linter call list * coverage seems to be broken Signed-off-by: Christian Henkel --- .github/workflows/lint.yml | 2 +- .github/workflows/pytest.yml | 12 +++--- bin/ros_license_toolkit | 42 ------------------ pyproject.toml | 43 +++++++++++++++++++ setup.py | 54 ------------------------ src/ros_license_toolkit/main.py | 4 +- test/systemtest/test_all_packages.py | 2 +- test/systemtest/test_documentation.py | 2 +- test/systemtest/test_license_per_repo.py | 2 +- test/systemtest/test_separate_pkgs.py | 4 +- 10 files changed, 57 insertions(+), 110 deletions(-) delete mode 100755 bin/ros_license_toolkit create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 53d5572..aeaffaa 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -45,7 +45,7 @@ jobs: run: pip install . - uses: ricardochaves/python-lint@v1.4.0 with: - python-root-list: "src/ test/ bin/ros_license_toolkit setup.py" + python-root-list: "src/ test/" use-pylint: false use-pycodestyle: true use-flake8: true diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 6aa9f25..020e53c 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -51,15 +51,15 @@ jobs: run: pip install . - uses: pavelzw/pytest-action@v2 with: - custom-arguments: "--cov=src/ros_license_toolkit --cov-report=xml" + custom-arguments: "--cov=src/ros_license_toolkit" emoji: true verbose: true job-summary: true - - uses: orgoro/coverage@v3 - with: - coverageFile: "coverage.xml" - token: ${{ secrets.GITHUB_TOKEN }} - if: github.event_name == 'pull_request' + # - uses: orgoro/coverage@v3 + # with: + # coverageFile: "coverage.xml" + # token: ${{ secrets.GITHUB_TOKEN }} + # if: github.event_name == 'pull_request' # - uses: MishaKav/pytest-coverage-comment@main # with: # pytest-xml-coverage-path: "coverage.xml" diff --git a/bin/ros_license_toolkit b/bin/ros_license_toolkit deleted file mode 100755 index 097c0e8..0000000 --- a/bin/ros_license_toolkit +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (c) 2022 - for information on the respective copyright owner -# see the NOTICE file and/or the repository -# https://github.com/boschresearch/ros_license_toolkit - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Executable entry point for the ros_license_toolkit script""" - -import os -import sys - -# Determine the real location of this script, resolving all symlinks -bindir = os.path.dirname(os.path.realpath(__file__)) - -# If ros_license_toolkit uses private modules, they are in the same folder as -# the script. The script will be symlinked from e.g. /usr/bin -if os.path.isfile(os.path.join(bindir, "ros_license_toolkit", "__init__.py")): - sys.path.insert(0, bindir) - -# If ros_license_toolkit is called from the source tree, we use that module -if os.path.isfile(os.path.join(bindir, os.path.pardir, - "src", "ros_license_toolkit", "__init__.py")): - sys.path.insert(0, os.path.normpath( - os.path.join(bindir, os.path.pardir, "src"))) - -del bindir -del os - -if __name__ == "__main__": - from ros_license_toolkit.main import main - sys.exit(main(args=sys.argv[1:])) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..93f1392 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,43 @@ +[build-system] +requires = ["setuptools>=61.0.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "ros_license_toolkit" +version = "1.0.0" +description = "Checks ROS packages for correct license declaration." +readme = "README.md" +authors = [ + {name = "Christian Henkel", email = "christian.henkel2@de.bosch.com"}, +] +license = {file = "LICENSE"} +classifiers = [ + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Framework :: Robot Framework :: Tool", + "Topic :: Software Development :: Quality Assurance", + "Topic :: Software Development :: Libraries :: Python Modules", +] +keywords = ["ros", "license", "toolkit", "oss", "packages"] +dependencies = [ + "gitpython", + "rospkg", +# TODO v32 changes things, see +# https://github.com/nexB/scancode-toolkit/blob/develop/ +# CHANGELOG.rst#v3200---2023-05-23 + "scancode-toolkit<=31.2.6", + "spdx-tools" +] +requires-python = ">=3.7" + +[project.urls] +homepage = "https://github.com/boschresearch/ros_license_toolkit" +repository = "https://github.com/boschresearch/ros_license_toolkit" + +[project.scripts] +ros_license_toolkit = "ros_license_toolkit.main:main" \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index 20aa382..0000000 --- a/setup.py +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright (c) 2022 - for information on the respective copyright owner -# see the NOTICE file and/or the repository -# https://github.com/boschresearch/ros_license_toolkit - -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Setup script for the ros_license_toolkit package.""" - -import os - -from setuptools import setup - - -def read(fname): - """Read a file (here: README.md) and return its content.""" - return open( - os.path.join(os.path.dirname(__file__), fname), - encoding="utf-8").read() - - -setup( - name="ros_license_toolkit", - description="Checks ROS packages for correct license declaration.", - long_description=read("README.md"), - long_description_content_type="text/markdown", - author="Christian Henkel", - author_email="christian.henkel2@de.bosch.com", - license="Apache License, Version 2.0", - url="tbd", - keywords=["license", "ROS"], - packages=["ros_license_toolkit"], - install_requires=[ - 'gitpython', - 'rospkg', - # TODO v32 changes things, see - # https://github.com/nexB/scancode-toolkit/blob/develop/ - # CHANGELOG.rst#v3200---2023-05-23 - 'scancode-toolkit<=31.2.6', - 'spdx-tools' - ], - package_dir={"": "src"}, - data_files=[], - scripts=["bin/ros_license_toolkit"] -) diff --git a/src/ros_license_toolkit/main.py b/src/ros_license_toolkit/main.py index 7b204de..93cba67 100644 --- a/src/ros_license_toolkit/main.py +++ b/src/ros_license_toolkit/main.py @@ -22,7 +22,7 @@ import os import sys import timeit -from typing import Sequence +from typing import Optional, Sequence from ros_license_toolkit.checks import LicensesInCodeCheck from ros_license_toolkit.checks import LicenseTagExistsCheck @@ -39,7 +39,7 @@ from ros_license_toolkit.ui_elements import Verbosity -def main(args: Sequence[str]) -> int: +def main(args: Optional[Sequence[str]] = None) -> int: """Main entry point for the ros_license_toolkit CLI. :param args: the command line arguments, defaults to sys.argv[1:] diff --git a/test/systemtest/test_all_packages.py b/test/systemtest/test_all_packages.py index 99bbfdc..c869b91 100644 --- a/test/systemtest/test_all_packages.py +++ b/test/systemtest/test_all_packages.py @@ -31,7 +31,7 @@ def test_all(self): Check that the output contains all package names. """ with subprocess.Popen( - ["bin/ros_license_toolkit", "test/_test_data"], + ["ros_license_toolkit", "test/_test_data"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) as process: diff --git a/test/systemtest/test_documentation.py b/test/systemtest/test_documentation.py index 84f739e..f5f5b1e 100644 --- a/test/systemtest/test_documentation.py +++ b/test/systemtest/test_documentation.py @@ -29,7 +29,7 @@ class TestDocumentation(unittest.TestCase): def test_readme(self): """Check if the help text is up to date.""" with subprocess.Popen( - ["bin/ros_license_toolkit", "-h"], + ["ros_license_toolkit", "-h"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) as process: diff --git a/test/systemtest/test_license_per_repo.py b/test/systemtest/test_license_per_repo.py index 1c0e389..c4fcad0 100644 --- a/test/systemtest/test_license_per_repo.py +++ b/test/systemtest/test_license_per_repo.py @@ -45,7 +45,7 @@ def _test_repo(self, repo_name, pkg_names, license_name): make_repo(repo_path) # test with subprocess.Popen( - ["bin/ros_license_toolkit", repo_path], + ["ros_license_toolkit", repo_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE ) as process: diff --git a/test/systemtest/test_separate_pkgs.py b/test/systemtest/test_separate_pkgs.py index d44b292..3579034 100644 --- a/test/systemtest/test_separate_pkgs.py +++ b/test/systemtest/test_separate_pkgs.py @@ -39,7 +39,7 @@ def test_deep_package_folder(self): "test/_test_data/test_deep_package_folder/deeper/test_pkg_deep" ]: with subprocess.Popen( - ["bin/ros_license_toolkit", call_path], + ["ros_license_toolkit", call_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) as process: @@ -105,7 +105,7 @@ def test_pkg_unknown_license(self): package.xml.""" # using subprocess.Popen instead of main() to capture stdout with subprocess.Popen( - ["bin/ros_license_toolkit", + ["ros_license_toolkit", "test/_test_data/test_pkg_unknown_license"], stdout=subprocess.PIPE, stderr=subprocess.PIPE