pylint not generating messages for C0326 whitepace violations - whitespace

pylint is not producing the expected convention warning messages for whitespace non-conformances.
python 3.6.8
pylint 2.13.5
using this test script :
from __future__ import print_function
import os, sys
import logging
from .. import views
class DoSomething(SomeCommand) : # space before colon !
def __init__(self):
for i in range(1,11): # no space after comma !!
if self.number == i:
print("matched")
else:
print ('not matched') # space before paren !!!
def check_user(self):
if self.user: return True
else : return False # spaces before colon !
results from pylint check :
PS C:\Users\PycharmProjects\coding_standard\src> pylint test_script.py
************* Module test_script
test_script.py:18:0: C0304: Final newline missing (missing-final-newline)
test_script.py:1:0: C0114: Missing module docstring (missing-module-docstring)
test_script.py:3:0: C0410: Multiple imports on one line (os, sys) (multiple-imports)
test_script.py:5:0: E0402: Attempted relative import beyond top-level package (relative-beyond-top-level)
test_script.py:7:0: C0115: Missing class docstring (missing-class-docstring)
test_script.py:7:18: E0602: Undefined variable 'SomeCommand' (undefined-variable)
test_script.py:16:4: C0116: Missing function or method docstring (missing-function-docstring)
test_script.py:17:8: R1703: The if statement can be replaced with 'return bool(test)' (simplifiable-if-statement)
test_script.py:17:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
test_script.py:17:22: C0321: More than one statement on a single line (multiple-statements)
test_script.py:7:0: R0903: Too few public methods (1/2) (too-few-public-methods)
test_script.py:3:0: W0611: Unused import os (unused-import)
test_script.py:3:0: W0611: Unused import sys (unused-import)
test_script.py:4:0: W0611: Unused import logging (unused-import)
test_script.py:5:0: W0611: Unused import views (unused-import)
Based on the docs I would expect to see C0326 messages for the commented lines.
I am using this as the reference for the conditions to be identified by C0326:
http://pylint-messages.wikidot.com/messages:c0326
Any suggestions to T/S this ?
Based on comment from #DylanLee ...
If I did it is truly by accident. I am not (knowingly) using any kind of config file to disable messages. Based on your comment, I ued the command line option:
$pylint --list-msgs-enabled
, which produces a list ...
Enabled messages:
...
multiple-statements (C0321)
superfluous-parens (C0325)
mixed-line-endings (C0327)
unexpected-line-ending-format (C0328)
wrong-spelling-in-comment (C0401)
...
Disabled messages:
raw-checker-failed (I0001)
bad-inline-option (I0010)
locally-disabled (I0011)
file-ignored (I0013)
suppressed-message (I0020)
useless-suppression (I0021)
deprecated-pragma (I0022)
use-symbolic-message-instead (I0023)
So, it is not obviously being disable, but is not included in the enabled list !
Maybe some updates to pylint that is suppressing that specific message ?

bad-whitespace has been removed from pylint in 2.6. You should use an autoformatter like black and pre-commit to handle this automatically.
See : https://pylint.pycqa.org/en/latest/whatsnew/2.6.html?highlight=bad-whitespace#other-changes
bad-continuation and bad-whitespace have been removed. black or another formatter can help you with this better than Pylint

Related

Streamlit Unhashable TypeError when i use st.cache

when i use the st.cache decorator to cash hugging-face transformer model i get
Unhashable TypeError
this is the code
from transformers import pipeline
import streamlit as st
from io import StringIO
#st.cache(hash_funcs={StringIO: StringIO.getvalue})
def model() :
return pipeline("sentiment-analysis", model='akhooli/xlm-r-large-arabic-sent')
after searching in issues section in streamlit repo
i found that hashing argument is not required , just need to pass this argument
allow_output_mutation = True
This worked for me:
from transformers import pipeline
import tokenizers
import streamlit as st
import copy
#st.cache(hash_funcs={tokenizers.Tokenizer: lambda _: None, tokenizers.AddedToken: lambda _: None})
def get_model() :
return pipeline("sentiment-analysis", model='akhooli/xlm-r-large-arabic-sent')
input = st.text_input('Text')
bt = st.button("Get Sentiment Analysis")
if bt and input:
model = copy.deepcopy(get_model())
st.write(model(input))
Note 1:
calling the pipeline with input model(input) changes the model and we shouldn't change a cached value so we need to copy the model and run it on the copy.
Note 2:
First run will load the model using the get_model function next run will use the chace.
Note 3:
You can read more about Advanced caching in stremlit in thier documentation.
Output examples:

Why is the output file from Biopython not found?

I work with a Mac. I have been trying to make a multiple sequence alignment in Python using Muscle. This is the code I have been running:
from Bio.Align.Applications import MuscleCommandline
cline = MuscleCommandline(input="testunaligned.fasta", out="testunaligned.aln", clwstrict=True)
print(cline)
from Bio import AlignIO
align = AlignIO.read(open("testunaligned.aln"), "clustal")
print(align)
I keep getting the following error:
FileNotFoundError: [Errno 2] No such file or directory: 'testunaligned.aln'
Does anyone know how I could fix this? I am very new to Python and computer science in general, and I am totally at a loss. Thanks!
cline in your code is an instance of MuscleCommandline object that you initialized with all the parameters. After the initialization, this instance can run muscle, but it will only do that if you call it. That means you have to invoke cline()
When you simply print the cline object, it will return a string that corresponds to the command you can manually run on the command line to get the same result as when you invoke cline().
And here the working code:
from Bio.Align.Applications import MuscleCommandline
cline = MuscleCommandline(
input="testunaligned.fasta",
out="testunaligned.aln",
clwstrict=True
)
print(cline)
cline() # this is where mucle runs
from Bio import AlignIO
align = AlignIO.read(open("testunaligned.aln"), "clustal")
print(align)

shutil error: "Module 'shutil' has no 'copy' member"

I am still learning python but got stuck here:
from pathlib import Path
import os
import shutil
p = Path.home()
shutil.copy(p / 'G:\souce.txt', p / 'G:\dest.text')
The error is:
shutil: shutil
Anomalous backslash in string: '\s'. String constant might be missing an r prefix.pylint(anomalous-
backslash-in-string)
Anomalous backslash in string: '\d'. String constant might be missing an r prefix.pylint(anomalous-
backslash-in-string)
Module 'shutil' has no 'copy' memberpylint(no-member)
Not able to go for the next step. So any suggestions please.
You can just do:
import shutil
shutil.copy('G:\souce.txt', 'G:\dest.text')

Declare additional dependency to sphinx-build in an extension

TL,DR: From a Sphinx extension, how do I tell sphinx-build to treat an additional file as a dependency? In my immediate use case, this is the extension's source code, but the question could equally apply to some auxiliary file used by the extension.
I'm generating documentation with Sphinx using a custom extension. I'm using sphinx-build to build the documentation. For example, I use this command to generate the HTML (this is the command in the makefile generated by sphinx-quickstart):
sphinx-build -b html -d _build/doctrees . _build/html
Since my custom extension is maintained together with the source of the documentation, I want sphinx-build to treat it as a dependency of the generated HTML (and LaTeX, etc.). So whenever I change my extension's source code, I want sphinx-build to regenerate the output.
How do I tell sphinx-build to treat an additional file as a dependency? That is not mentioned in the toctree, since it isn't part of the source. Logically, this should be something I do from my extension's setup function.
Sample extension (my_extension.py):
from docutils import nodes
from docutils.parsers.rst import Directive
class Foo(Directive):
def run(self):
node = nodes.paragraph(text='Hello world\n')
return [node]
def setup(app):
app.add_directive('foo', Foo)
Sample source (index.rst):
.. toctree::
:maxdepth: 2
.. foo::
Sample conf.py (basically the output of sphinx-quickstart plus my extension):
import sys
import os
sys.path.insert(0, os.path.abspath('.'))
extensions = ['my_extension']
templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index'
project = 'Hello directive'
copyright = '2019, Gilles'
author = 'Gilles'
version = '1'
release = '1'
language = None
exclude_patterns = ['_build']
pygments_style = 'sphinx'
todo_include_todos = False
html_theme = 'alabaster'
html_static_path = ['_static']
htmlhelp_basename = 'Hellodirectivedoc'
latex_elements = {
}
latex_documents = [
(master_doc, 'Hellodirective.tex', 'Hello directive Documentation',
'Gilles', 'manual'),
]
man_pages = [
(master_doc, 'hellodirective', 'Hello directive Documentation',
[author], 1)
]
texinfo_documents = [
(master_doc, 'Hellodirective', 'Hello directive Documentation',
author, 'Hellodirective', 'One line description of project.',
'Miscellaneous'),
]
Validation of a solution:
Run make html (or sphinx-build as above).
Modify my_extension.py to replace Hello world by Hello again.
Run make html again.
The generated HTML (_build/html/index.html) must now contain Hello again instead of Hello world.
It looks like the note_dependency method in the build environment API should do what I want. But when should I call it? I tried various events but none seemed to hit the environment object in the right state. What did work was to call it from a directive.
import os
from docutils import nodes
from docutils.parsers.rst import Directive
import sphinx.application
class Foo(Directive):
def run(self):
self.state.document.settings.env.note_dependency(__file__)
node = nodes.paragraph(text='Hello done\n')
return [node]
def setup(app):
app.add_directive('foo', Foo)
If a document contains at least one foo directive, it'll get marked as stale when the extension that introduces this directive changes. This makes sense, although it could get tedious if an extension adds many directives or makes different changes. I don't know if there's a better way.
Inspired by Luc Van Oostenryck's autodoc-C.
As far as I know app.env.note_dependency can be called within the doctree-read to add any file as a dependency to the document currently being read.
So in your use case, I assume this would work:
from typing import Any, Dict
from sphinx.application import Sphinx
import docutils.nodes as nodes
def doctree-read(app: Sphinx, doctree: nodes.document):
app.env.note_dependency(file)
def setup(app: Sphinx):
app.connect("doctree-read", doctree-read)

Python error: one of the arguments is required

I'm trying to run a code from github that uses Python to classify images but I'm getting an error.
here is the code:
import argparse as ap
import cv2
import imutils
import numpy as np
import os
from sklearn.svm import LinearSVC
from sklearn.externals import joblib
from scipy.cluster.vq import *
# Get the path of the testing set
parser = ap.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-t", "--testingSet", help="Path to testing Set")
group.add_argument("-i", "--image", help="Path to image")
parser.add_argument('-v',"--visualize", action='store_true')
args = vars(parser.parse_args())
# Get the path of the testing image(s) and store them in a list
image_paths = []
if args["testingSet"]:
test_path = args["testingSet"]
try:
testing_names = os.listdir(test_path)
except OSError:
print "No such directory {}\nCheck if the file exists".format(test_path)
exit()
for testing_name in testing_names:
dir = os.path.join(test_path, testing_name)
class_path = imutils.imlist(dir)
image_paths+=class_path
else:
image_paths = [args["image"]]
and this is the error message I'm getting
usage: getClass.py [-h]
(- C:/Users/Lenovo/Downloads/iris/bag-of-words-master/dataset/test TESTINGSET | - C:/Users/Lenovo/Downloads/iris/bag-of-words-master/dataset/test/test_1.jpg IMAGE)
[- C:/Users/Lenovo/Downloads/iris/bag-of-words-master/dataset]
getClass.py: error: one of the arguments - C:/Users/Lenovo/Downloads/iris/bag-of-words-master/dataset/test/--testingSet - C:/Users/Lenovo/Downloads/iris/bag-of-words-master/dataset/test/test_1.jpg/--image is required
can you please help me with this? where and how should I write the file path?
This is an error your own program is issuing. The message is not about the file path but about the number of arguments. This line
group = parser.add_mutually_exclusive_group(required=True)
says that only one of your command-line arguments (-t, -i) is permitted. But it appears from the error message that you are supplying both --testingSet and --image on your command line.
Since you only have 3 arguments, I have to wonder if you really need argument groups at all.
To get your command line to work, drop the mutually-exclusive group and add the arguments to the parser directly.
parser.add_argument("-t", "--testingSet", help="Path to testing Set")
parser.add_argument("-i", "--image", help="Path to image")
parser.add_argument('-v',"--visualize", action='store_true')

Resources