diff --git a/requirements-swh.txt b/requirements-swh.txt index 08665ea..850ffb6 100644 --- a/requirements-swh.txt +++ b/requirements-swh.txt @@ -1,3 +1,3 @@ # Add here internal Software Heritage dependencies, one per line. -swh.core +swh.core >= 0.3 swh.model >= 0.3.8 diff --git a/setup.py b/setup.py index f623637..cf7965c 100755 --- a/setup.py +++ b/setup.py @@ -1,74 +1,74 @@ #!/usr/bin/env python3 # Copyright (C) 2019-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information from io import open from os import path from setuptools import find_packages, setup here = path.abspath(path.dirname(__file__)) # Get the long description from the README file with open(path.join(here, "README.md"), encoding="utf-8") as f: long_description = f.read() def parse_requirements(name=None): if name: reqf = "requirements-%s.txt" % name else: reqf = "requirements.txt" requirements = [] if not path.exists(reqf): return requirements with open(reqf) as f: for line in f.readlines(): line = line.strip() if not line or line.startswith("#"): continue requirements.append(line) return requirements # Edit this part to match your module. # Full sample: # https://forge.softwareheritage.org/diffusion/DCORE/browse/master/setup.py setup( name="swh.scanner", description="Software Heritage code scanner", long_description=long_description, long_description_content_type="text/markdown", python_requires=">=3.7", author="Software Heritage developers", author_email="swh-devel@inria.fr", url="https://forge.softwareheritage.org/diffusion/DTSCN/", packages=find_packages(), # packages's modules install_requires=parse_requirements() + parse_requirements("swh"), tests_require=parse_requirements("test"), setup_requires=["setuptools-scm"], use_scm_version=True, extras_require={"testing": parse_requirements("test")}, include_package_data=True, entry_points=""" [swh.cli.subcommands] - scanner=swh.scanner.cli:scanner + scanner=swh.scanner.cli """, classifiers=[ "Programming Language :: Python :: 3", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", "Development Status :: 3 - Alpha", ], project_urls={ "Bug Reports": "https://forge.softwareheritage.org/maniphest", "Funding": "https://www.softwareheritage.org/donate", "Source": "https://forge.softwareheritage.org/source/swh-scanner", "Documentation": "https://docs.softwareheritage.org/devel/swh-scanner/", }, ) diff --git a/swh/scanner/cli.py b/swh/scanner/cli.py index 0f53cd7..1ff3e80 100644 --- a/swh/scanner/cli.py +++ b/swh/scanner/cli.py @@ -1,108 +1,108 @@ # Copyright (C) 2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information # WARNING: do not import unnecessary things here to keep cli startup time under # control import os from typing import Any, Dict import click from swh.core import config -from swh.core.cli import CONTEXT_SETTINGS +from swh.core.cli import CONTEXT_SETTINGS, swh as swh_cli_group # All generic config code should reside in swh.core.config DEFAULT_CONFIG_PATH = os.environ.get( "SWH_CONFIG_FILE", os.path.join(click.get_app_dir("swh"), "global.yml") ) DEFAULT_CONFIG: Dict[str, Any] = { "web-api": { "url": "https://archive.softwareheritage.org/api/1/", "auth-token": None, } } def parse_url(url): """CLI-specific helper to 'autocomplete' the provided url.""" if not url.startswith("https://"): url = "https://" + url if not url.endswith("/"): url += "/" return url -@click.group(name="scanner", context_settings=CONTEXT_SETTINGS) +@swh_cli_group.group(name="scanner", context_settings=CONTEXT_SETTINGS) @click.option( "-C", "--config-file", default=DEFAULT_CONFIG_PATH, type=click.Path(exists=True, dir_okay=False, path_type=str), help="YAML configuration file", ) @click.pass_context def scanner(ctx, config_file: str): """Software Heritage Scanner tools.""" # recursive merge not done by config.read conf = config.read_raw_config(config.config_basepath(config_file)) conf = config.merge_configs(DEFAULT_CONFIG, conf) ctx.ensure_object(dict) ctx.obj["config"] = conf @scanner.command(name="scan") @click.argument("root_path", required=True, type=click.Path(exists=True)) @click.option( "-u", "--api-url", default=None, metavar="API_URL", show_default=True, help="URL for the api request", ) @click.option( "--exclude", "-x", "patterns", metavar="PATTERN", multiple=True, help="Exclude directories using glob patterns \ (e.g., '*.git' to exclude all .git directories)", ) @click.option( "-f", "--output-format", "out_fmt", default="text", show_default=True, type=click.Choice(["text", "json", "ndjson", "sunburst"], case_sensitive=False), help="The output format", ) @click.option( "-i", "--interactive", is_flag=True, help="Show the result in a dashboard" ) @click.pass_context def scan(ctx, root_path, api_url, patterns, out_fmt, interactive): """Scan a source code project to discover files and directories already present in the archive""" from .scanner import scan config = ctx.obj["config"] if api_url: config["web-api"]["url"] = parse_url(api_url) scan(config, root_path, patterns, out_fmt, interactive) def main(): return scanner(auto_envvar_prefix="SWH_SCANNER") if __name__ == "__main__": main()