Page MenuHomePhabricator

pycodestyles does not work inside scripts/userscripts
Closed, ResolvedPublic

Description

If you save a PEP8-uncompliant bot script in ./scripts/userscripts and run pycodestyles on it, you will not get any warnings back. But if you copy that file elsewhere and run pycodestyle there, you will get warnings.

Reproduction steps

Save this file both in /tmp and in ./scripts/userscripts:

1#!/usr/bin/python3
2# -*- coding: utf-8 -*-
3

Note that last line in the file contains white-spaces, which is a violation of PEP8.

Here is the output of pycodestyles, first in the ./scripts/userscripts/ directory and next in /tmp:

➜  userscripts git:(master) pycodestyle T.py 
➜  userscripts git:(master)
➜  userscripts git:(master) cd /tmp
➜  /tmp pycodestyle T.py 
T.py:3:1: W293 blank line contains whitespace
T.py:3:1: W391 blank line at end of file
➜  /tmp

Event Timeline

Huji created this task.May 28 2020, 2:28 PM
Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald TranscriptMay 28 2020, 2:28 PM
Huji updated the task description. (Show Details)May 28 2020, 2:28 PM
Huji updated the task description. (Show Details)
Huji updated the task description. (Show Details)May 28 2020, 2:30 PM

I think it is disabled in tox.ini for purpose. I would not like to have my userscripts analyzed and if I would do, I would update tox.ini for my fork.

Huji added a comment.May 28 2020, 2:33 PM

Two questions:

  1. How is it that tox.in (which is define in the root of the bot) is being observed when I run pycodestyles in a subdirectory?
  2. While we can decide which parts of bywikibot code should or should not be excluded from pycodestyles, we cannot choose that for user scripts. Why don't we leave it to the user to decide?
Huji added a comment.May 28 2020, 2:36 PM

In other words, I can add a blank tox.ini file in ./scripts/userscripts and that fixes the issue above. However, I think the default should be the other way around: those users who *don't* want this directory to be considered by pycodestyles should add a tox.ini in their userscripts directory that reads: exclude = *

Change 599345 had a related patch set uploaded (by Huji; owner: Huji):
[pywikibot/core@master] Do not exclude userscripts directory from pycodestyles

https://gerrit.wikimedia.org/r/599345

Huji added a comment.May 28 2020, 2:49 PM

@Dvorapa I think you added this back in c1eb7709af0b mainly to make it easier for pywikibot developers (like you and me) to run tests. If so, then the correct way was for you to add a tox.ini in your installations with an exclusion rule. I, for one, want my userscripts to also be checked by the linter :)

Dvorapa added a comment.EditedMay 28 2020, 5:03 PM

I don't remember why I added those, I have got separate bot and development repositories, so this patch was not for me. Someone must had requested this somewhere, it's a shame I didn't mentioned in the commit message, who came up with that and where. Maybe somewhere in Phab or mw.org

Dvorapa added a comment.EditedMay 28 2020, 5:06 PM

Anyway I guess you are right, we should not block users flake8, autopep and pycodestyle linters where it is possible they would want to check. user-config.py should be removed too I guess.

Huji claimed this task.May 28 2020, 5:33 PM
Huji triaged this task as Medium priority.

Change 599345 merged by jenkins-bot:
[pywikibot/core@master] Do not exclude userscripts directory from pycodestyles

https://gerrit.wikimedia.org/r/599345

Xqt closed this task as Resolved.Jun 1 2020, 8:27 AM