enabling pylint_django plugin in vscode, pylint stop working - django

That's my user settings in vscode
{
"python.pythonPath": "/Users/cristiano/miniconda3/envs/django-rest-2/bin/python",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_django"
],
}
I installed the plugin via conda, same as the pylint
pylint 2.1.1 py36_0
pylint-django 0.11.1 py_1 conda-forge
pylint-plugin-utils 0.4 py_0 conda-forge
If i commented out the "python.linting.pylintArgs" section, pylint works with no problem. I ned to enable the plugin to avoid django-specific errros such as "Entity.objects.all()", but if I enable it, the lint stop working: it does not highlight standard errors o warning the previously was doing it.
I have same exact behaviour using vscode for win and mac. I tried also to use the .pylintrc file as described here but I have the same result: lint stop working.
Same behaviour using base conda env or a custom one.

This config for pylint is working for me:
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
"--disable=C0111", // missing docstring
"--load-plugins=pylint_django,pylint_celery",
],

I just got the same issue. Like #J0hnG4lt said, I had a problem with the python path. I didn't point to the path of the environment, which I have installed pylint_django. This config is work for me. Thanks #Manu.
"python.pythonPath": "/Users/mc976/Documents/Programming/Python/Practice/music_service/venv/bin/python3",
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
"--disable=C0111",
"--load-plugins",
"pylint_django"
]
Besides, I think you should check your environment to make sure that you have correctly installed pylint_django by using pip list.

My issue was more prosaic (but perhaps it will help other forehead slappers like myself). Run the PIP install in the correct virtualenv directory!
pip install pylint-django --upgrade
Also note that plugin errors cause Pylint to completely fail to load silently. Start with blank pylintArgs and slowly add them back one at a time to see where things go awry.

found a working answer for myself here: https://donjayamanne.github.io/pythonVSCodeDocs/docs/linting/
my settings.json file now reads:
{
"python.pythonPath": "C:\\ProgramData\\Anaconda3\\envs\\djangoSite2\\python.exe",
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": ["--disable=C0111","--load-plugins", "pylint_django"],
}
this then adds linting, but doesn't throw an error on fields that it can't find (like the Entity.objects.all() one), but has the disadvantage that if you then try and reference something that really doesn't exist it doesn't throw an error.

It now works on my Mac. This is my workspace's settings.json:
{
"python.linting.pylintEnabled": true,
"python.linting.pycodestyleEnabled": false,
"files.autoSave": "afterDelay",
"editor.fontSize": 14,
"editor.wordWrapColumn": 90,
"editor.autoClosingQuotes": "beforeWhitespace",
"python.pythonPath": "/Users/myname/anaconda3/envs/myproject/bin/python",
"python.linting.pylintArgs": [
"--disable=C0111", // missing docstring
"--load-plugins=pylint_django",
],
}
I had to be careful to have installed pylint-django into the correct python environment. For me, this meant running this command in the terminal:
$ /Users/myname/anaconda3/envs/myproject/bin/python -m install pip pylint pylint-django

python.pythonPath is deprecated. You should use python.defaultInterpreterPath instead

I ran into an error related to pylint not being able to parse JSON correctly. All I had to do was add an 's' to my config to make it plugins (plural) instead of plugin. Then everything started working.
"python.linting.pylintArgs": [
"--load-plugins=pylint_django",
],

Related

Using "m1-medium" not recognized as valid by EAS

When I follow these instructions on an M2 MBA using Expo SDK 47.0.13 and EAS CLI 3.5.2 (darwin-arm64) I get
InvalidEasJsonError: eas.json is not valid.
- "build.dev-hardware.resourceClass" must be one of [default, medium]
which seems like a direct contradiction of those instructions. Why isn't the specified value (m1-medium) recognized as valid?
I had the same issue and I solved it by updating my eas-cli on global level. In my situation I tried updating it with
npm install -g eas-cli
If you've used a different package manager like I did to install eas-cli earlier, you may need to run the command accordingly. In my case it was
yarn global add eas-cli
Also, it's maybe worth checking if in your eas.json file you have any setting related to the cli version like this:
{
"cli": {
"version": ">= 3.3.0"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal",
"ios": {
"resourceClass": "m1-medium"
}
},
"production": {
"ios": {
"resourceClass": "m1-medium"
}
}
}
}
EDIT
I remembered that when this was happening, whenever I ran eas build the console printed a message like this:
I ran the suggested npm install command, but message was still prompted, which led me to believe that yarn was in control of the version of the eas-cli that executes eas build.
This is why I ran yarn global add, which fixed the issue.

Autocomplete django in visual studio code

hello everyone I am having a problem the visual studio code autocomplete for django does not work for me, because for python it does it without problems but when working with django the framework options do not work, that is when I work with views based on classes does not generate the autocomplete, such as template_name, form_class, etc ..., likewise with the models it does not generate the help of max_length, and those other things of the framework, I have selected the interpreter but it does not work for me and also python: build workspace symbols and nothing. in advance I appreciate the help.
You can install and activate python & Microsoft AI extension in visual studio code.
install some of the plugins for local and global
Global in vscode extensions:
Python (Microsoft)
Djaneiro
code spell checker
local:
pip install —dev autopep8 pep8 pylint pylint_django
Press CTRL+SHIFT+P(CMD+SHIFT+P for MacOS) -> ">select interpreter" -> select your virtual envirnoment
https://i.ibb.co/TTfkHRF/select-vir.gif
open vscode/setting.json file and past the beneath config code:
{
....
"editor.formatOnSave": true,
"python.formatting.provider": "autopep8",
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
"--load-plugin=pylint_django"
]
}

Angular 2 Unit Tests: Cannot find name 'describe'

I'm following this tutorial from angular.io
As they said, I've created hero.spec.ts file to create unit tests:
import { Hero } from './hero';
describe('Hero', () => {
it('has name', () => {
let hero: Hero = {id: 1, name: 'Super Cat'};
expect(hero.name).toEqual('Super Cat');
});
it('has id', () => {
let hero: Hero = {id: 1, name: 'Super Cat'};
expect(hero.id).toEqual(1);
});
});
Unit Tests work like a charm. The problem is: I see some errors, which are mentioned in tutorial:
Our editor and the compiler may complain that they don’t know what it
and expect are because they lack the typing files that describe
Jasmine. We can ignore those annoying complaints for now as they are
harmless.
And they indeed ignored it. Even though those errors are harmless, it doesn't look good in my output console when I receive bunch of them.
Example of what I get:
Cannot find name 'describe'.
Cannot find name 'it'.
Cannot find name 'expect'.
What can I do to fix it?
I hope you've installed -
npm install --save-dev #types/jasmine
Then put following import at the top of the hero.spec.ts file -
import 'jasmine';
It should solve the problem.
With Typescript#2.0 or later you can install types with:
npm install -D #types/jasmine
Then import the types automatically using the types option in tsconfig.json:
"types": ["jasmine"],
This solution does not require import {} from 'jasmine'; in each spec file.
npm install #types/jasmine
As mentioned in some comments the "types": ["jasmine"] is not needed anymore, all #types packages are automatically included in compilation (since v2.1 I think).
In my opinion the easiest solution is to exclude the test files in your tsconfig.json like:
"exclude": [
"node_modules",
"**/*.spec.ts"
]
This works for me.
Further information in the official tsconfig docs.
You need to install typings for jasmine. Assuming you are on a relatively recent version of typescript 2 you should be able to do:
npm install --save-dev #types/jasmine
With Typescript#2.0 or later you can install types with npm install
npm install --save-dev #types/jasmine
then import the types automatically using the typeRoots option in tsconfig.json.
"typeRoots": [
"node_modules/#types"
],
This solution does not require import {} from 'jasmine'; in each spec file.
In order for TypeScript Compiler to use all visible Type Definitions during compilation, types option should be removed completely from compilerOptions field in tsconfig.json file.
This problem arises when there exists some types entries in compilerOptions field, where at the same time jest entry is missing.
So in order to fix the problem, compilerOptions field in your tscongfig.json should either include jest in types area or get rid of types comnpletely:
{
"compilerOptions": {
"esModuleInterop": true,
"target": "es6",
"module": "commonjs",
"outDir": "dist",
"types": ["reflect-metadata", "jest"], //<-- add jest or remove completely
"moduleResolution": "node",
"sourceMap": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
Solution to this problem is connected with what #Pace has written in his answer. However, it doesn't explain everything so, if you don't mind, I'll write it by myself.
SOLUTION:
Adding this line:
///<reference path="./../../../typings/globals/jasmine/index.d.ts"/>
at the beginning of hero.spec.ts file fixes problem. Path leads to typings folder (where all typings are stored).
To install typings you need to create typings.json file in root of your project with following content:
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160602141332",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160807145350"
}
}
And run typings install (where typings is NPM package).
In my case, the solution was to remove the typeRoots in my tsconfig.json.
As you can read in the TypeScript doc
If typeRoots is specified, only packages under typeRoots will be included.
I'm up to the latest as of today and found the best way to resolve this is to do nothing...no typeRoots no types no exclude no include all the defaults seem to be working just fine. Actually it didn't work right for me until I removed them all. I had:
"exclude": [
"node_modules"
]
but that's in the defaults so I removed that.
I had:
"types": [
"node"
]
to get past some compiler warning. But now I removed that too.
The warning that shouldn't be is:
error TS2304: Cannot find name 'AsyncIterable'.
from node_modules\#types\graphql\subscription\subscribe.d.ts
which is very obnoxious so I did this in tsconfig so that it loads it:
"compilerOptions": {
"target": "esnext",
}
since it's in the esnext set. I'm not using it directly so no worries here about compatibility just yet. Hope that doesn't burn me later.
I'll just add Answer for what works for me in "typescript": "3.2.4" I realized that jasmine in node_modules/#types there is a folder for ts3.1 under the jasmine type so here are the steps:-
Install type jasmine npm install -D #types/jasmine
Add to tsconfig.json jasmine/ts3.1
"typeRoots": [
...
"./node_modules/jasmine/ts3.1"
],
Add Jasmine to the types
"types": [
"jasmine",
"node"
],
Note: No need for this import 'jasmine'; anymore.
Only had to do the following to pick up #types in a Lerna Mono-repo
where several node_modules exist.
npm install -D #types/jasmine
Then in each tsconfig.file of each module or app
"typeRoots": [
"node_modules/#types",
"../../node_modules/#types" <-- I added this line
],
In my case, I was getting this error when I serve the app, not when testing. I didn't realise I had a different configuration setting in my tsconfig.app.json file.
I previously had this:
{
...
"include": [
"src/**/*.ts"
]
}
It was including all my .spec.ts files when serving the app. I changed the include property toexclude` and added a regex to exclude all test files like this:
{
...
"exclude": [
"**/*.spec.ts",
"**/__mocks__"
]
}
Now it works as expected.
I had this error in an angular library. Turns out I accidentally included my .spec file in the exports in my public-api.ts. Removing the export fixed my issue.
Look at the import maybe you have a cycle dependency, this was in my case the error, using import {} from 'jasmine'; will fix the errors in the console and make the code compilable but not removes the root of devil (in my case the cycle dependency).
I'm on Angular 6, Typescript 2.7, and I'm using Jest framework to unit test.
I had #types/jest installed and added on typeRoots inside tsconfig.json
But still have the display error below (i.e: on terminal there is no errors)
cannot find name describe
And adding the import :
import {} from 'jest'; // in my case or jasmine if you're using jasmine
doesn't technically do anything, so I thought, that there is an import somewhere causing this problem, then I found, that if delete the file
tsconfig.spec.json
in the src/ folder, solved the problem for me. As #types is imported before inside the rootTypes.
I recommend you to do same and delete this file, no needed config is inside. (ps: if you're in the same case as I am)
If the error is in the .specs file
app/app.component.spec.ts(7,3): error TS2304: Cannot find name 'beforeEach'.
add this to the top of your file and npm install rxjs
import { range } from 'rxjs';
import { map, filter } from 'rxjs/operators';
Just add to your tsconfig.json, and be sure that you don't have "**/*.spec.ts"
in exclude
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
My working tsconfig.json

SublimeLinter(ST3/ST2) for C++ (cppcheck/cppint.py)

Equip: Ubuntu 13.04, Sublime 3 + SublimeLinter(was installed from git).
Also, was installed package cppcheck. (aptitude install cppcheck).
cpplint.py was downloaded from google.
Trouble: Sublime doesn`t emphasize errors C++. (python is OK).
What have done, my setting - user:
{
"sublimelinter_syntax_map":
{
"Python Django": "python",
"C++": "c_cpplint" //*doesn`t work.
// "C++": "/usr/bin/cppheck" *doesn`t work.
},
"sublimelinter_executable_map":
{
"c_cpplint": "/home/name/scripts/cpplint.py", // *doesn`t work
// "c_cpplint":"/usr/bin/cppheck" * doesn`t work
"python": "usr/bin/python"
}
}
What`s the deal?
ST2:
cppcheck do nothing.
via cpplint.py
picture
Many thanks.
Here's the solution I've read for cpplint, works perfectly for me. I did the
sudo pip install cpplint
instead of downloading the .py and put it somewhere. This seems to do the trick.
Some people say it's the permission issue on cpplint.py. Try chmod 755 might be another solution(I've not tried it though)

Django coloring output in runserver.py

I want to highlight the output in the console "manage.py runserver"
In Linux, all OK, but in Windows does not work.
The documentation
says: SET export DJANGO_COLORS = "light"
Does not work.
There is a ticket
Nodule is installed: pip install pyreadline
Not work.
Did you apply the patch from the ticket? Otherwise it's not going to work.