Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCat467 authored Jan 28, 2022
1 parent 8de4956 commit e3add39
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 35 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

here = pathlib.Path(__file__).parent.resolve()

version = '0.0.0'
version = '0.1.0'
# Get the long description from the README file
long_description = (here / 'README.md').read_text(encoding='utf-8')
install_requires = ['pylint']
Expand Down
49 changes: 49 additions & 0 deletions src/lintcheck.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Metadata-Version: 2.1
Name: lintcheck
Version: 0.1.0
Summary: Pylint extension for IDLE
Home-page: https://github.com/CoolCat467/lintcheck
Author: CoolCat467
License: UNKNOWN
Project-URL: Bug Reports, https://github.com/CoolCat467/lintcheck/issues
Project-URL: Source, https://github.com/CoolCat467/lintcheck
Keywords: pylint,idle,extension,development
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Build Tools
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.6, <4
Description-Content-Type: text/markdown
License-File: LICENSE

# LintCheck
Python IDLE extension to preform pylint analysis on an open file

## Installation
1) Go to terminal and install with `pip install lintcheck`.
2) Run command `lintcheck`. You will likely see a message saying
`lintcheck not in system registered extensions!`. Run the command
given to add lintcheck to your system's IDLE extension config file.
3) Again run command `lintcheck`. This time, you should see the following
output: `Config should be good!`.
4) Open IDLE, go to `Options` -> `Configure IDLE` -> `Extensions`.
If everything went well, alongside `ZzDummy` there should be and
option called `lintcheck`. This is where you can configure how
lintcheck works.

### Information on options
Option `ignore` is a list of pylint messages,
seperated by semicolons (;) that should be disabled using `--disable`.
See `pylint --help` for more information.

Option `jobs` is the number of processes pylint should use when
checking your code, using `--jobs`. See `pylint --help` for more information.


11 changes: 11 additions & 0 deletions src/lintcheck.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
LICENSE
README.md
setup.cfg
setup.py
src/lintcheck/__init__.py
src/lintcheck.egg-info/PKG-INFO
src/lintcheck.egg-info/SOURCES.txt
src/lintcheck.egg-info/dependency_links.txt
src/lintcheck.egg-info/entry_points.txt
src/lintcheck.egg-info/requires.txt
src/lintcheck.egg-info/top_level.txt
1 change: 1 addition & 0 deletions src/lintcheck.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions src/lintcheck.egg-info/entry_points.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[console_scripts]
lintcheck = lintcheck:check_installed

1 change: 1 addition & 0 deletions src/lintcheck.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lintcheck
82 changes: 48 additions & 34 deletions src/lintcheck/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# -*- coding: utf-8 -*-
# Lint Check - Use pylint to check open file, then add comments to file.

"""Lint Check Extension"""
"Lint Check Extension"

# Programmed by CoolCat467

__title__ = 'lintcheck'
__author__ = 'CoolCat467'
__version__ = '0.0.0'
__version__ = '0.1.0'
__ver_major__ = 0
__ver_minor__ = 0
__ver_minor__ = 1
__ver_patch__ = 0

import os
Expand Down Expand Up @@ -59,7 +59,7 @@ def check_installed() -> bool:
# Make sure linebreaks will go properly in terminal
add_data = add_data.replace('\n', '\\n')
# Tell them command
print(f"sudo echo -e '{add_data}' | sudo tee -a {ex_defaults}")
print(f"echo -e '{add_data}' | sudo tee -a {ex_defaults}")
print()
else:
print('Config should be good!')
Expand Down Expand Up @@ -104,8 +104,8 @@ def ensure_values_exist_in_section(section:str, values:dict) -> bool:
need_save = True
return need_save

class lintcheck:
"""Prepend or remove initial text from selected lines."""
class lintcheck:# pylint: disable=C0103
"Add comments from pylint to an open program."
# Extend the file and format menus.
menudefs = [
('file', [
Expand All @@ -119,12 +119,12 @@ class lintcheck:
values = {'enable': 'True',
'enable_editor': 'True',
'enable_shell': 'False',
'ignore': 'C0303',
'ignore': 'None',
'jobs': '0'}
# Default keybinds for config file
bind_defaults = {'lint-check': '<Control-Shift-Key-C>',
'lint-remove-comments': '<Control-Alt-Key-c>'}
comment = '# pylint: '
comment = '# lintcheck: '

ignore = ''
jobs = '0'
Expand All @@ -138,31 +138,31 @@ def __init__(self, editwin):
self.files = editwin.io#idlelib.iomenu.IOBinding

self.pylint_file = os.path.expanduser(
os.path.join('~', '.idlerc', 'pylint-out.json'))
os.path.join(idleConf.userdir, 'pylint-out.json'))

self.text.bind('<<lint-check>>', self.lint_check_event)
self.text.bind('<<lint-remove-comments>>', self.remove_lint_comments_event)

## @classmethod
## def ensure_bindings_exist(cls) -> bool:
## "Ensure key bindings exist in user extensions config. Return True if need to save."
## need_save = False
## section = cls.__name__+'_cfgBindings'
## if ensure_section_exists(section):
## need_save = True
## if ensure_values_exist_in_section(section, cls.bind_defaults):
## need_save = True
## return need_save
##
## @classmethod
## def ensure_config_exists(cls):
## "Ensure required configuration exists for this extention. Return True if need to save."
## need_save = False
## if ensure_section_exists(cls.__name__):
## need_save = True
## if ensure_values_exist_in_section(cls.__name__, cls.values):
## need_save = True
## return need_save
@classmethod
def ensure_bindings_exist(cls) -> bool:
"Ensure key bindings exist in user extensions config. Return True if need to save."
need_save = False
section = cls.__name__+'_cfgBindings'
if ensure_section_exists(section):
need_save = True
if ensure_values_exist_in_section(section, cls.bind_defaults):
need_save = True
return need_save

@classmethod
def ensure_config_exists(cls):
"Ensure required configuration exists for this extention. Return True if need to save."
need_save = False
if ensure_section_exists(cls.__name__):
need_save = True
if ensure_values_exist_in_section(cls.__name__, cls.values):
need_save = True
return need_save

@classmethod
def reload(cls):
Expand All @@ -183,6 +183,7 @@ def add_comment(self, message):
# Get line, message id, and message from pylint output
line = message['line']
msg_id = message['message-id']
symbol = message['symbol']
msg = message['message']

# Go to line pylint is talking about
Expand All @@ -197,7 +198,7 @@ def add_comment(self, message):
indent_match_idx = len(lines)-2 if len(lines) > 1 else 0
indent = get_line_indent(lines[indent_match_idx])
# Set last line of section (empty) to pylint message in a comment
lines[-1] = ' '*indent+self.comment+msg_id+': '+msg
lines[-1] = ' '*indent+self.comment+symbol+' ('+msg_id+'): '+msg
# Re-add empty line so we don't break text around comment
lines.append('')
# Save changes
Expand Down Expand Up @@ -241,11 +242,14 @@ def lint_check_event(self, _) -> None:
'Please install pylint to use this extension.')
lines.append('')
self.formatter.set_region(head, tail, chars, lines)
# Make bell sound so user knows they need to pay attension
self.text.bell()
return
# Make sure file is saved.
self.files.maybesave()
# If not saved, do not run. Would break file.
if not self.files.get_saved():
self.text.bell()
return
# Get arguments
file = os.path.abspath(self.files.filename)
Expand All @@ -256,7 +260,7 @@ def lint_check_event(self, _) -> None:
jobs = max(0, jobs)
args = [file, f'--output={self.pylint_file}',
'--output-format=json', f'--jobs={jobs}']
if self.ignore:
if self.ignore and self.ignore != 'None':
if ';' not in self.ignore:
ignore = [self.ignore]
else:
Expand All @@ -265,21 +269,31 @@ def lint_check_event(self, _) -> None:

# Run pylint on open file
pylint.lint.run.Run(args, exit=False)

# Read data from temporary file as json
data = []
with open(self.pylint_file, 'r', encoding='utf-8') as results:
data = json.load(results)

results.close()
# Remove file and add code comments
os.remove(self.pylint_file)
# Add code comments
self.add_comments(file, data)

## # Remove file
## os.remove(self.pylint_file)

# Make bell sound so user knows we are done,
# as it freezes a bit while pylint looks at the file
self.text.bell()

def remove_lint_comments_event(self, _) -> None:
"Remove all pylint comments."
# Get selected region lines
head, tail, chars, lines = self.formatter.get_region()
if not self.comment in chars:
# Make bell sound so user knows this ran even though
# nothing happened.
self.text.bell()
return
# Using dict so we can reverse and enumerate
ldict = dict(enumerate(lines))
Expand Down

0 comments on commit e3add39

Please sign in to comment.