Browse Source

Pass project to main func

root-dir
carmenbianca 3 weeks ago
parent
commit
0ce6c8d3c0
Signed by: Carmen Bianca Bakker <carmenbianca@fsfe.org> GPG Key ID: 76EBA6F6B6EA2EC9
6 changed files with 17 additions and 18 deletions
  1. 6
    1
      src/reuse/_main.py
  2. 2
    3
      src/reuse/download.py
  3. 2
    4
      src/reuse/header.py
  4. 3
    2
      src/reuse/init.py
  5. 2
    4
      src/reuse/lint.py
  6. 2
    4
      src/reuse/spdx.py

+ 6
- 1
src/reuse/_main.py View File

@@ -21,6 +21,7 @@ from . import (
)
from ._format import INDENT, fill_all, fill_paragraph
from ._util import setup_logging
from .project import create_project

_LOGGER = logging.getLogger(__name__)

@@ -227,7 +228,11 @@ def main(args: List[str] = None, out=sys.stdout) -> int:
if parsed_args.version:
out.write("reuse {}\n".format(__version__))
return 0
return parsed_args.func(parsed_args, out)

project = create_project()
project.include_submodules = parsed_args.include_submodules

return parsed_args.func(parsed_args, project, out)


if __name__ == "__main__":

+ 2
- 3
src/reuse/download.py View File

@@ -16,7 +16,7 @@ import requests

from ._licenses import EXCEPTION_MAP, LICENSE_MAP
from ._util import PathType, find_licenses_directory
from .project import create_project
from .project import Project
from .report import ProjectReport

# All raw text files are available as files underneath this path.
@@ -89,7 +89,7 @@ def add_arguments(parser) -> None:
)


def run(args, out=sys.stdout) -> int:
def run(args, project: Project, out=sys.stdout) -> int:
"""Download license and place it in the LICENSES/ directory."""

def _already_exists(path: PathLike):
@@ -133,7 +133,6 @@ def run(args, out=sys.stdout) -> int:
out.write("\n")

if args.all:
project = create_project()
# TODO: This is fairly inefficient, but gets the job done.
report = ProjectReport.generate(project)
licenses = report.missing_licenses

+ 2
- 4
src/reuse/header.py View File

@@ -38,7 +38,7 @@ from ._util import (
make_copyright_line,
spdx_identifier,
)
from .project import Project, create_project
from .project import Project

_LOGGER = logging.getLogger(__name__)

@@ -411,7 +411,7 @@ def add_arguments(parser) -> None:
parser.add_argument("path", action="store", nargs="+", type=PathType("w"))


def run(args, out=sys.stdout) -> int:
def run(args, project: Project, out=sys.stdout) -> int:
"""Add headers to files."""
if not any((args.copyright, args.license)):
args.parser.error(_("option --copyright or --license is required"))
@@ -427,8 +427,6 @@ def run(args, out=sys.stdout) -> int:
if args.style is None and not args.explicit_license:
_verify_paths_supported(paths, args.parser)

project = create_project()
project.include_submodules = args.include_submodules
template = None
commented = False
if args.template:

+ 3
- 2
src/reuse/init.py View File

@@ -16,6 +16,7 @@ import requests
from ._licenses import EXCEPTION_MAP, LICENSE_MAP
from ._util import PathType, find_root
from .download import _path_to_license_file, put_license_in_file
from .project import Project


def prompt_licenses(out=sys.stdout) -> List[str]:
@@ -70,9 +71,9 @@ def add_arguments(parser):
)


def run(args, out=sys.stdout):
def run(args, project: Project, out=sys.stdout):
"""List all non-compliant files."""
# pylint: disable=too-many-statements
# pylint: disable=too-many-statements,unused-argument
if args.path:
root = args.path
else:

+ 2
- 4
src/reuse/lint.py View File

@@ -12,7 +12,7 @@ from typing import Iterable

from . import __REUSE_version__
from ._util import PathType
from .project import create_project
from .project import Project
from .report import ProjectReport


@@ -250,10 +250,8 @@ def add_arguments(parser):
parser.add_argument("path", action="store", nargs="*", type=PathType("r"))


def run(args, out=sys.stdout):
def run(args, project: Project, out=sys.stdout):
"""List all non-compliant files."""
project = create_project()
project.include_submodules = args.include_submodules
paths = args.path
if not paths:
paths = [project.root]

+ 2
- 4
src/reuse/spdx.py View File

@@ -10,7 +10,7 @@ import sys
from gettext import gettext as _

from ._util import PathType
from .project import create_project
from .project import Project
from .report import ProjectReport

_LOGGER = logging.getLogger(__name__)
@@ -23,7 +23,7 @@ def add_arguments(parser) -> None:
)


def run(args, out=sys.stdout) -> int:
def run(args, project: Project, out=sys.stdout) -> int:
"""Print the project's bill of materials."""
if args.file:
out = args.file.open("w", encoding="UTF-8")
@@ -31,8 +31,6 @@ def run(args, out=sys.stdout) -> int:
# Translators: %s is a file name.
_LOGGER.warning(_("'%s' does not end with .spdx"), out.name)

project = create_project()
project.include_submodules = args.include_submodules
report = ProjectReport.generate(project)

out.write(report.bill_of_materials())

Loading…
Cancel
Save