Skip to content

Commit fe3132e

Browse files
committed
Linting.
1 parent bcb6081 commit fe3132e

9 files changed

Lines changed: 72 additions & 71 deletions

File tree

__pkginfo__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file is managed by 'repo_helper'. Don't edit it directly.
2-
# Copyright (C) 2020 Dominic Davis-Foster <dominic@davis-foster.co.uk>
2+
# Copyright © 2020 Dominic Davis-Foster <dominic@davis-foster.co.uk>
33
#
44
# This file is distributed under the same license terms as the program it came with.
55
# There will probably be a file called LICEN[S/C]E in the same directory as this file.

notebook2script/__init__.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
################################################################################
2-
# #
3-
# Copyright (C) 2020 Dominic Davis-Foster #
4-
# #
5-
# This program is free software; you can redistribute it and/or modify #
6-
# it under the terms of the GNU General Public License version 2 as #
7-
# published by the Free Software Foundation. #
8-
# #
9-
# This program is distributed in the hope that it will be useful, #
10-
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
11-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
12-
# GNU General Public License for more details. #
13-
# #
14-
# You should have received a copy of the GNU General Public License #
15-
# along with this program; if not, write to the Free Software #
16-
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
17-
# #
18-
################################################################################
1+
#!/usr/bin/env python3
2+
#
3+
# __init__.py
4+
"""
5+
Convert Jupyter Notebooks to Python Scripts.
6+
"""
7+
#
8+
# Copyright © 2020 Dominic Davis-Foster <dominic@davis-foster.co.uk>
9+
#
10+
# This program is free software; you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License version 2
12+
# as published by the Free Software Foundation.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program; if not, write to the Free Software
21+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22+
# MA 02110-1301, USA.
23+
#
1924

20-
# stdlib
21-
import pathlib
22-
23-
repo_root = pathlib.Path("/home/domdf/Python/01 GitHub Repos/pyms-github")
24-
notebooks_dir = repo_root / "pyms-demo/jupyter"
25-
scripts_dir = repo_root / "pyms-demo/scripts"
25+
__author__: str = "Dominic Davis-Foster"
26+
__copyright__: str = "2020 Dominic Davis-Foster"
27+
__license__: str = "GPLv2"
28+
__version__: str = "0.0.0"
29+
__email__: str = "dominic@davis-foster.co.uk"

notebook2script/__main__.py

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
################################################################################
2-
# #
3-
# Copyright (C) 2020 Dominic Davis-Foster #
4-
# #
5-
# This program is free software; you can redistribute it and/or modify #
6-
# it under the terms of the GNU General Public License version 2 as #
7-
# published by the Free Software Foundation. #
8-
# #
9-
# This program is distributed in the hope that it will be useful, #
10-
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
11-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
12-
# GNU General Public License for more details. #
13-
# #
14-
# You should have received a copy of the GNU General Public License #
15-
# along with this program; if not, write to the Free Software #
16-
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
17-
# #
18-
################################################################################
1+
#!/usr/bin/env python3
2+
#
3+
# __main__.py
4+
#
5+
# Copyright © 2020 Dominic Davis-Foster <dominic@davis-foster.co.uk>
6+
#
7+
# This program is free software; you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License version 2
9+
# as published by the Free Software Foundation.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program; if not, write to the Free Software
18+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19+
# MA 02110-1301, USA.
20+
#
1921

2022
# stdlib
2123
import argparse
@@ -30,20 +32,12 @@
3032
from notebook2script.ipynb2py import convert_notebook
3133
from notebook2script.pointless import Pointless
3234

33-
sys.path.append("..")
34-
sys.path.append("../..")
35+
__all__ = ["main", "process_multiple_notebooks", "process_notebook"]
3536

3637
linter = Pointless()
3738

3839

3940
def main() -> None:
40-
# Strip out the current working directory from sys.path.
41-
# Having the working directory in `sys.path` means that `pylint` might
42-
# inadvertently import user code from modules having the same name as
43-
# stdlib or pylint's own modules.
44-
# CPython issue: https://bugs.python.org/issue33053
45-
if sys.path[0] == '' or sys.path[0] == os.getcwd():
46-
sys.path.pop(0)
4741

4842
parser = argparse.ArgumentParser(description="Convert Jupyter Notebooks to Python scripts")
4943

notebook2script/ipynb2py.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
# 3rd party
3131
from nbconvert import PythonExporter # type: ignore
3232

33+
__all__ = ["convert_notebook"]
34+
3335
py_exporter = PythonExporter()
3436

3537

@@ -38,7 +40,7 @@ def convert_notebook(
3840
outfile: Union[str, pathlib.Path, os.PathLike],
3941
):
4042
"""
41-
Convert a notebook to a python file
43+
Convert a notebook to a python file.
4244
4345
:param nb_file: Filename of the Jupyter Notebook to convert
4446
:param outfile: Filename to save the output script as

notebook2script/pointless.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@
150150
# this package
151151
from notebook2script import pointless_checker
152152

153+
__all__ = ["Pointless", "fix_import_path"]
154+
153155

154156
class Pointless(PyLinter):
155157
"""lint Python modules using external checkers.
@@ -253,6 +255,7 @@ def fix_import_path(args):
253255
We avoid adding duplicate directories to sys.path.
254256
`sys.path` is reset to its original value upon exiting this context.
255257
"""
258+
256259
original = _patch_sys_path(args)
257260
try:
258261
yield

notebook2script/pointless_checker/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def initialize(linter):
2929
Initialize linter with checkers in this package
3030
"""
3131

32-
register_plugins(linter, __path__[0])
32+
register_plugins(linter, __path__[0]) # type: ignore
3333

3434

3535
__all__ = ("BaseChecker", "BaseTokenChecker", "initialize")

notebook2script/pointless_checker/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
from pylint.checkers import utils # type: ignore
3131
from pylint.checkers.base_checker import BaseChecker # type: ignore
3232

33+
__all__ = ["BasicChecker", "register"]
34+
3335

3436
class BasicChecker(BaseChecker):
3537
"""checks for :

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
astroid>=2.4.0,<=2.5
2-
IPython >= 7.14.0
3-
nbconvert >= 5.6.1
4-
pylint >=2.5.2
1+
astroid<=2.5,>=2.4.0
2+
IPython>=7.14.0
3+
nbconvert>=5.6.1
4+
pylint>=2.5.2

tests/test_pointless_checker.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66
from notebook2script.pointless import Pointless
77

88

9-
def test_pointless_checker():
9+
def test_pointless_checker(tmp_path):
10+
# Make a file with some "pointless" statements
1011

11-
with tempfile.TemporaryDirectory() as tmpdir:
12-
tmpdir = pathlib.Path(tmpdir)
12+
outfile = tmp_path / "test_script.py"
1313

14-
# Make a file with some "pointless" statements
15-
16-
outfile = tmpdir / "test_script.py"
17-
18-
outfile.write_text(
19-
"""\
14+
outfile.write_text(
15+
"""\
2016
#!/use/bin/python3
2117
2218
# Based on https://realpython.com/how-to-use-numpy-arange/
@@ -41,13 +37,13 @@ def test_pointless_checker():
4137
data
4238
4339
"""
44-
)
40+
)
4541

46-
linter = Pointless()
42+
linter = Pointless()
4743

48-
linter.process_file(outfile)
44+
linter.process_file(outfile)
4945

50-
assert outfile.read_text() == """\
46+
assert outfile.read_text() == """\
5147
#!/use/bin/python3
5248
5349
# Based on https://realpython.com/how-to-use-numpy-arange/

0 commit comments

Comments
 (0)