Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] pylint-odoo: Adding support for parameters --ignore and --ignore-patterns #103

Conversation

JesusZapata
Copy link

@JesusZapata JesusZapata commented Jan 5, 2017

pylint supports the following parameters:

  • --ignore=<file>[,<file>...]
  • --ignore-patterns=<pattern>[,<pattern>...]

But pylint-odoo is not using for ignore them from custom search files methods.
We are searching files: js, md, rst...
And we need skip them too if this parameters is defined.

Doubts you have:

  • How do I run the tests with the console and append more parameters --ignore and / or --ignore-patterns.
  • When running with "python setup.py test" the setup.py file can not pass more arguments.
  • Running it with "tox" to the tox command can not pass more arguments.

Related to issue #102

"""
self.ext_files = {}
base_path = os.path.dirname(os.path.realpath(__file__))
ignores = []
ignore_argvs = getopt.getopt([argv for argv in sys.argv[1:]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters are received with sys.argv but when run with setup.py or tox that variable is empty.
Could you help me with this @moylop260 ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameters are received from config like as other custom parameters.
Because a configfile could be used too.

Search where is used the config variable to read by example the js configuration file for js-lint check

@JesusZapata JesusZapata force-pushed the master-add-supports-for-ignore-files-jesuszapata branch from 84f871a to 25cc9d0 Compare January 6, 2017 14:52
@@ -237,6 +237,20 @@ class ModuleChecker(misc.WrapperModuleChecker):
'javascript lint. You can use the environment variable '
'"PYLINT_ODOO_JSLINTRC" too. Default: %s' % DFTL_JSLINTRC)
}),
('po-ignore', {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to use --ignore but enter in conflict with ignore of pylint
It is a good solucion?

@moylop260
Copy link

moylop260 commented Jan 6, 2017 via email

@JesusZapata
Copy link
Author

Now used the correct parameters --ignore and --ignore-patterns !

@JesusZapata JesusZapata force-pushed the master-add-supports-for-ignore-files-jesuszapata branch from 86df315 to a442815 Compare January 6, 2017 20:58
ignores_patterns = [glob.glob(os.path.join(base_path, ignore.pattern))
for ignore
in self.linter.option_value('ignore-patterns')]
for ignore in ignores_patterns:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about use utils._basename_in_blacklist_re method?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay! Thanks for the information of this method ! I started using it!

for ignore in self.linter.option_value('ignore')]
ignores_patterns = [glob.glob(os.path.join(base_path, ignore.pattern))
for ignore
in self.linter.option_value('ignore-patterns')]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not tested this code but I don't understand how works if the arg.dest for this parameter is black_list_re
Check if It have the same content, please

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well, I did not know that parameter! I'm using it now

"""
self.ext_files = {}
base_path = os.path.dirname(os.path.realpath(__file__))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need the path of pylint_odoo/misc.py file here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used another variable what store same value!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to use another variable and do not pass the tests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a commenr in the code of why is required this value

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: "because do not pass the test" is not a good justify

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you run manually the command pylint with ignore with other path won't work.
I mean, copy test_repo to /tmp/ and check if ignore parameters are working yet.

if ignore in root:
find = False
continue
if find:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cyclomatic complexity of this method is too high.
Could you refactoring it to reduce it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this array should be traversed!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But with the continue breaks the cycle

@JesusZapata JesusZapata force-pushed the master-add-supports-for-ignore-files-jesuszapata branch 2 times, most recently from 1ddde14 to 1c88591 Compare January 8, 2017 22:29
@JesusZapata JesusZapata force-pushed the master-add-supports-for-ignore-files-jesuszapata branch from 910e124 to 5a5375f Compare January 8, 2017 23:02
self.linter.config.
black_list_re):
find = False
continue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A continue as last sentence of a for is useless.
Maybe you want use break

'--enable=javascript-lint']
pylint_res = self.run_pylint(self.paths_modules, extra_params)
real_errors = pylint_res.linter.stats['by_msg']
self.assertEqual(real_errors.items(), [])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should force a output in order to validate that was skipped files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed test cases!

@JesusZapata
Copy link
Author

I made test into the folder /tmp attached screenshot

Firts all deprecated-openerp-xml-node
deprecated-openerp-xml-node

Second parameter --ignore
deprecated-openerp-xml-node-ignore

Third parameter --ignore-patterns
enable deprecated-openerp-xml-node-ignore-patterns

Is good idea used deprecated-openerp-xml-node for test this functionality ?

@moylop260
Copy link

Maybe is working the original parameter, because you are skipping a full folder.
You should try with a particular file.

And remove the following line: base_path = os.path.dirname(os.path.realpath(__file__))

@JesusZapata
Copy link
Author

@moylop260 Thanks for you observation! The previous code did not find the files

fext = os.path.splitext(filename)[1].lower()
fname_rel = os.path.relpath(
os.path.join(root, filename), self.module_path)
self.ext_files.setdefault(fext, []).append(fname_rel)
name = os.path.join(self.module_path, fname_rel)
Copy link

@moylop260 moylop260 Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you deleting a value to add it again?
I mean, you have os.path.join(root, filename):

  • e.g. /mypath1/mypath2/myfile.ext

Then you get relative path based on self.module_path

  • e.g. If self.module_path is /mypath1 then the relative path is mypath2/myfile.ext after that you are joining again the self.module_path to get /mypath1/mypath2/myfile.ext again.

Do you want drive me crazy or Am I missing something?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand.

When run pylint -r n --disable=all --enable=deprecated-openerp-xml-node --ignore=test_module/res_users.xml --load-plugins=pylint_odoo /tmp/test_repo/

The variable self.linter.config.black_list has ['test_module/res_users.xml']
I only ask if ignore in name: the name variable has '/tmp/test_repo/test_module/res_users.xml'

Does this help you?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a pdb and print the value os.path.join(root, filename) and name and tell me what is the difference

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output of pdb

(Pdb++) os.path.join(root, filename)
'/tmp/test_repo/test_module/res_users.xml'
(Pdb++) name
'/tmp/test_repo/test_module/res_users.xml'

They are the same values!
I can remove the variable name and use os.path.join (root, filename) directly

Is that what you mean?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I told you
You are using a=10; a+=1; a-=1 😞

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks to you, i have fixed it!

# If the file is within ignores is ignored
for ignore in self.linter.config.black_list:
if ignore in name:
find = False
Copy link

@moylop260 moylop260 Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What means find variable?
(Because I don't understand why we have a find = False when is really find it)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed this, I give a better use to the variable

@JesusZapata
Copy link
Author

@moylop260
What else does it take to close this PR?

fext = os.path.splitext(filename)[1].lower()
fname_rel = os.path.relpath(
os.path.join(root, filename), self.module_path)
self.ext_files.setdefault(fext, []).append(fname_rel)
# If the file is within black_list_re is ignored

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fname = os.path.join(root, filename)
And reuse this variable 2 times

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used the variable when needed!

find = True
break
if not find:
self.ext_files.setdefault(fext, []).append(fname_rel)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assign fname_rel variable here where is really used.

"""
self.ext_files = {}
ignores = list(self.linter.config.black_list)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this variable instead of use it directly?
NOTE: I requested a explanation, don't confuse with a request of change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable is not necessary since it is used only once!
This change had been made by the 188d405 commit excluding the test folder
Can I return this change?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarify.
Yes, please

Copy link

@moylop260 moylop260 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM just waiting justification of variable ignores

@JesusZapata JesusZapata force-pushed the master-add-supports-for-ignore-files-jesuszapata branch from 97fbd70 to ec722f6 Compare January 11, 2017 18:51
@moylop260 moylop260 merged commit 9762664 into Vauxoo:master Jan 11, 2017
@moylop260 moylop260 deleted the master-add-supports-for-ignore-files-jesuszapata branch January 11, 2017 19:06
@moylop260
Copy link

Please create PR to oca from merged sha

JesusZapata pushed a commit to vauxoo-dev/pylint-odoo that referenced this pull request Jan 11, 2017
@JesusZapata
Copy link
Author

JesusZapata commented Jan 11, 2017

Done the PR OCA#103

JesusZapata pushed a commit to vauxoo-dev/pylint-odoo that referenced this pull request Jan 14, 2017
…-for-ignore-files-jesuszapata

[IMP] pylint-odoo: Adding support for parameters --ignore and --ignore-patterns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants