Skip to content

Commit

Permalink
Linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Jan 6, 2021
1 parent 2d12b51 commit c1d65c1
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 66 deletions.
2 changes: 1 addition & 1 deletion __pkginfo__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
]

__copyright__ = """
2020 Dominic Davis-Foster <dominic@davis-foster.co.uk>
2020-2021 Dominic Davis-Foster <dominic@davis-foster.co.uk>
"""

__version__ = "0.2.0"
Expand Down
2 changes: 1 addition & 1 deletion doc-source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
project = "notebook2script"
slug = re.sub(r'\W+', '-', project.lower())
release = version = __version__
copyright = "2020 Dominic Davis-Foster" # pylint: disable=redefined-builtin
copyright = "2020-2021 Dominic Davis-Foster" # pylint: disable=redefined-builtin
language = "en"
package_root = "notebook2script"

Expand Down
4 changes: 2 additions & 2 deletions notebook2script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Convert Jupyter Notebooks to Python Scripts.
"""
#
# Copyright © 2020 Dominic Davis-Foster <dominic@davis-foster.co.uk>
# Copyright © 2020-2021 Dominic Davis-Foster <dominic@davis-foster.co.uk>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
Expand Down Expand Up @@ -40,7 +40,7 @@
from notebook2script.pointless import Pointless

__author__: str = "Dominic Davis-Foster"
__copyright__: str = "2020 Dominic Davis-Foster"
__copyright__: str = "2020-2021 Dominic Davis-Foster"
__license__: str = "GPLv2"
__version__: str = "0.2.0"
__email__: str = "dominic@davis-foster.co.uk"
Expand Down
3 changes: 3 additions & 0 deletions notebook2script/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python3
#
# __main__.py
"""
CLI entry point.
"""
#
# Copyright © 2020 Dominic Davis-Foster <dominic@davis-foster.co.uk>
#
Expand Down
17 changes: 11 additions & 6 deletions notebook2script/pointless.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/env python3
#
# pointless.py
"""
Ensure pointless statements in scripts are converted
into print function calls
"""

""" # noqa: D400
#
# Copyright (C) 2020 Dominic Davis-Foster

#
# Based on pylint
# Copyright (c) 2006-2016 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
# Copyright (c) 2008 Fabrice Douchant <Fabrice.Douchant@logilab.fr>
Expand All @@ -19,7 +22,6 @@
# Copyright (c) 2012 Kevin Jing Qiu <kevin.jing.qiu@gmail.com>
# Copyright (c) 2012-2014 Google, Inc.
# Copyright (c) 2013 buck@yelp.com <buck@yelp.com>
# Copyright (c) 2013-2014 Google, Inc.
# Copyright (c) 2013-2020 Claudiu Popa <pcmanticore@gmail.com>
# Copyright (c) 2014 Alexandru Coman <fcoman@bitdefender.com>
# Copyright (c) 2014 Arun Persaud <arun@nubati.net>
Expand Down Expand Up @@ -154,6 +156,9 @@


class Pointless(PyLinter):
"""
Checker for pointless statements.
"""

def __init__(self):
super().__init__()
Expand All @@ -162,15 +167,15 @@ def __init__(self):
self.initialize()
self.statements = []

def load_default_plugins(self):
def load_default_plugins(self): # noqa: D102
pointless_checker.initialize(self)
reporters.initialize(self)
# Make sure to load the default reporter, because
# the option has been set before the plugins had been loaded.
if not self.reporter:
self._load_reporter()

def process_file(self, filename):
def process_file(self, filename): # noqa: D102
self.statements = []

with fix_import_path([filename]):
Expand Down
47 changes: 26 additions & 21 deletions notebook2script/pointless_checker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
################################################################################
# #
# Copyright (C) 2020 Dominic Davis-Foster #
# Based on pylint #
# See notebook2script/pointless.py for full copyright information #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2 as #
# published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
# #
################################################################################
#!/usr/bin/env python3
#
# __init__.py
"""
Checker for pointless statements.
"""
#
# Copyright © 2020-2021 Dominic Davis-Foster <dominic@davis-foster.co.uk>
# Based on pylint
# See notebook2script/pointless.py for full copyright information
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#

# 3rd party
from pylint.checkers.base_checker import BaseChecker, BaseTokenChecker # type: ignore
Expand All @@ -26,7 +31,7 @@

def initialize(linter):
"""
Initialize linter with checkers in this package
Initialize linter with checkers in this package.
"""

register_plugins(linter, __path__[0]) # type: ignore
Expand Down
58 changes: 27 additions & 31 deletions notebook2script/pointless_checker/base.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
################################################################################
# #
# Copyright (C) 2020 Dominic Davis-Foster #
# Based on pylint #
# See notebook2script/pointless.py for full copyright information #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2 as #
# published by the Free Software Foundation. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
# #
################################################################################
#!/usr/bin/env python3
#
# base.py
"""
Checker for pointless statements.
"""
#
# Copyright © 2020-2021 Dominic Davis-Foster <dominic@davis-foster.co.uk>
# Based on pylint
# See notebook2script/pointless.py for full copyright information
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#

# stdlib
from typing import Dict, Tuple
Expand All @@ -33,16 +38,7 @@
__all__ = ["BasicChecker", "register"]


class BasicChecker(BaseChecker):
"""checks for :
* doc strings
* number of arguments, local variables, branches, returns and statements in
functions, methods
* required module attributes
* dangerous default values as arguments
* redefinition of function / method / class
* uses of the global statement
"""
class BasicChecker(BaseChecker): # noqa: D101

__implements__ = interfaces.IAstroidChecker

Expand Down Expand Up @@ -118,7 +114,7 @@ def visit_expr(self, node) -> None:

def register(linter) -> None:
"""
required method to auto register this checker
Required function to auto register this checker.
"""

linter.register_checker(BasicChecker(linter))
5 changes: 1 addition & 4 deletions repo_helper.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
modname: notebook2script
copyright_years: "2020"
copyright_years: "2020-2021"
author: "Dominic Davis-Foster"
email: "dominic@davis-foster.co.uk"
version: "0.2.0"
Expand All @@ -12,11 +12,9 @@ enable_conda: False

conda_channels:
- conda-forge
- domdfcoding

python_deploy_version: 3.6


# Versions to run tests for
python_versions:
- '3.6'
Expand All @@ -27,7 +25,6 @@ python_versions:
additional_ignore:
- "tests/output/"


console_scripts:
- "notebook2script = notebook2script.__main__:main"

Expand Down

0 comments on commit c1d65c1

Please sign in to comment.