wemake-services / wemake-python-styleguide

The strictest and most opinionated python linter ever!
https://wemake-python-styleguide.rtfd.io
MIT License
2.5k stars 381 forks source link

Software license (flake8-isort has gpl) #2481

Open hatterton opened 2 years ago

hatterton commented 2 years ago

Hi, there is a list of statements:

  1. wemake-python-styleguide has license MIT
  2. flake8-isort has license GPL
  3. flake8-isort is one of mandatory dependencies of wemake-python-styleguide

These facts force you have GPL software license too, don't? Could you, please, describe the situation cause I may be wrong?

sobolevn commented 2 years ago

I think that in this case we can just drop flake8-isort. GPL is not suitable for QA tools.

hatterton commented 2 years ago

Yeah, it would be great. We are using wemake in project and our scanning tools says that one of your dependencies has GPL and it it strange and is not suitable for us too

skarzi commented 2 years ago

Have you tried to contact the flake8-isort maintainers? Maybe they will change their license ;)

sobolevn commented 2 years ago

This is everything we need:

class Flake8Isort5(Flake8IsortBase):
    """class for isort >=5"""

    def run(self):
        if self.filename is not self.stdin_display_name:
            file_path = Path(self.filename)
            isort_config = isort.settings.Config(
                settings_path=file_path.parent)
        else:
            file_path = None
            isort_config = isort.settings.Config(
                settings_path=Path.cwd())
        input_string = ''.join(self.lines)
        traceback = ''
        isort_changed = False
        input_stream = StringIO(input_string)
        output_stream = StringIO()
        isort_stdout = StringIO()
        try:
            with redirect_stdout(isort_stdout):
                isort_changed = isort.api.sort_stream(
                    input_stream=input_stream,
                    output_stream=output_stream,
                    config=isort_config,
                    file_path=file_path)
        except isort.exceptions.FileSkipped:
            pass
        except isort.exceptions.ISortError as e:
            warnings.warn(e)
        if isort_changed:
            outlines = output_stream.getvalue()
            diff_delta = "".join(unified_diff(
                              input_string.splitlines(keepends=True),
                              outlines.splitlines(keepends=True),
                              fromfile="{}:before".format(self.filename),
                              tofile="{}:after".format(self.filename)))
            traceback = (isort_stdout.getvalue() + "\n" + diff_delta)
            for line_num, message in self.isort_linenum_msg(diff_delta):
                if self.show_traceback:
                    message += traceback
                yield line_num, 0, message, type(self)

    def isort_linenum_msg(self, udiff):
        """Parse unified diff for changes and generate messages
        Args
        ----
        udiff : unified diff delta
        Yields
        ------
        tuple: A tuple of the specific isort line number and message.
        """
        line_num = 0
        additions = []
        moves = []
        for line in udiff.splitlines():
            if line.startswith('@@', 0, 2):
                line_num = int(line[4:].split(' ')[0].split(',')[0])
                continue
            elif not line_num:  # skip lines before first hunk
                continue
            if line.startswith(' ', 0, 1):
                line_num += 1  # Ignore unchanged lines but increment line_num.
            elif line.startswith('-', 0, 1):
                if line.strip() == '-':
                    yield line_num, self.isort_blank_unexp
                    line_num += 1
                else:
                    moves.append(line[1:])
                    yield line_num, self.isort_unsorted
                    line_num += 1
            elif line.startswith('+', 0, 1):
                if line.strip() == '+':
                    # Include newline additions but do not increment line_num.
                    yield line_num, self.isort_blank_req
                else:
                    additions.append((line_num, line))

        # return all additions that did not move
        for line_num, line in additions:
            if not line[1:] in moves:
                yield line_num, self.isort_add_unexp

It is easier for us to just use isort directly, which is MIT.