Skip to content

Commit eabe02c

Browse files
committed
Tidying up code and added new functions (doctools.py) to aid in documenting functions, classes and methods
1 parent 1a94bfa commit eabe02c

File tree

6 files changed

+86
-25
lines changed

6 files changed

+86
-25
lines changed

doc-source/docs.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
:private-members:
1010
:special-members:
1111

12+
==================================
13+
:mod:`domdf_python_tools.doctools`
14+
==================================
15+
16+
17+
.. automodule:: domdf_python_tools.doctools
18+
:members:
19+
:private-members:
20+
:special-members:
21+
1222
==================================
1323
:mod:`domdf_python_tools.paths`
1424
==================================

domdf_python_tools/__init__.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
# Compiled 2018-2019 by Dominic Davis-Foster <[email protected]>
2-
3-
42
#
53
# terminal.py
64
# Copyright 2014-2019 Dominic Davis-Foster <[email protected]>
75
#
86
# get_terminal_size, _get_terminal_size_windows, _get_terminal_size_tput and _get_terminal_size_linux
9-
# from https://gist.github.com/jtriley/1108174
7+
# from https://gist.github.com/jtriley/1108174
108
# Copyright 2011 jtriley
119
#
1210
# paths.py
13-
# Copyright 2018-2019 Dominic Davis-Foster <[email protected]>
11+
# Copyright 2018-2019 Dominic Davis-Foster <[email protected]>
1412
#
1513
# copytree based on https://stackoverflow.com/a/12514470/3092681
16-
# Copyright 2012 atzz
17-
# Licensed under CC-BY-SA
14+
# Copyright 2012 atzz
15+
# Licensed under CC-BY-SA
1816
#
1917

18+
19+
import sys
20+
21+
from domdf_python_tools.utils import *
22+
from domdf_python_tools import paths, terminal, utils, doctools
23+
2024
__all__ = ["paths", "terminal", "utils"]
2125

2226
__author__ = "Dominic Davis-Foster"
@@ -27,11 +31,4 @@
2731
__email__ = "[email protected]"
2832

2933

30-
import sys
31-
32-
from . import paths
33-
from . import terminal
34-
from . import utils
35-
from domdf_python_tools.utils import *
36-
3734
pyversion = int(sys.version[0]) # Python Version

domdf_python_tools/doctools.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# !/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# doctools.py
5+
"""
6+
Utilities for documenting functions, classes and methods
7+
"""
8+
#
9+
# Based on https://softwareengineering.stackexchange.com/a/386758
10+
# Copyright (c) amon (https://softwareengineering.stackexchange.com/users/60357/amon)
11+
# Licensed under CC BY-SA 4.0
12+
#
13+
# This program is free software; you can redistribute it and/or modify
14+
# it under the terms of the GNU Lesser General Public License as published by
15+
# the Free Software Foundation; either version 3 of the License, or
16+
# (at your option) any later version.
17+
#
18+
# This program is distributed in the hope that it will be useful,
19+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
# GNU Lesser General Public License for more details.
22+
#
23+
# You should have received a copy of the GNU Lesser General Public License
24+
# along with this program; if not, write to the Free Software
25+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26+
# MA 02110-1301, USA.
27+
#
28+
29+
30+
def is_documented_by(original):
31+
def wrapper(target):
32+
target.__doc__ = original.__doc__
33+
return target
34+
return wrapper
35+
36+
37+
def append_docstring_from(original):
38+
def wrapper(target):
39+
target.__doc__ = target.__doc__ + "\n" + original.__doc__
40+
return target
41+
return wrapper

domdf_python_tools/paths.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
# -*- coding: utf-8 -*-
33
#
44
# paths.py
5-
"""Functions for paths and files"""
5+
"""
6+
Functions for paths and files
7+
"""
68
#
79
# Copyright 2018-2019 Dominic Davis-Foster <[email protected]>
810
#
911
# check_dependencies based on https://stackoverflow.com/a/29044693/3092681
1012
# Copyright 2015 TehTechGuy
11-
# Licensed under CC-BY-SA
13+
# Licensed under CC-BY-SA
1214
#
1315
# as_text from https://stackoverflow.com/a/40935194
14-
# Copyright 2016 User3759685
15-
# Available under the MIT License
16+
# Copyright 2016 User3759685
17+
# Available under the MIT License
1618
#
1719
# chunks from https://stackoverflow.com/a/312464/3092681
18-
# Copytight 2008 Ned Batchelder
19-
# Licensed under CC-BY-SA
20-
#
20+
# Copytight 2008 Ned Batchelder
21+
# Licensed under CC-BY-SA
2122
#
2223
# This program is free software; you can redistribute it and/or modify
2324
# it under the terms of the GNU Lesser General Public License as published by
@@ -39,6 +40,7 @@
3940
import os
4041
import pathlib
4142

43+
4244
def copytree(src, dst, symlinks=False, ignore=None):
4345
"""
4446
Because shutil.copytree is borked
@@ -70,6 +72,7 @@ def copytree(src, dst, symlinks=False, ignore=None):
7072
else:
7173
return shutil.copy2(s, d)
7274

75+
7376
def maybe_make(directory):
7477
"""
7578
Makes a directory only if it doesn't already exist
@@ -82,6 +85,7 @@ def maybe_make(directory):
8285
if not os.path.exists(directory):
8386
os.makedirs(directory)
8487

88+
8589
def parent_path(path):
8690
"""
8791
Returns the path of the parent directory for the given file or directory
@@ -94,6 +98,7 @@ def parent_path(path):
9498

9599
return os.path.abspath(os.path.join(path,os.pardir))
96100

101+
97102
def relpath(path, relative_to=None):
98103
"""
99104
Returns the path for the given file or directory relative to the given directory
@@ -209,4 +214,3 @@ def append(var, filename):
209214

210215
with open(os.path.join(os.getcwd(), filename), 'a') as f:
211216
f.write(var)
212-

domdf_python_tools/terminal.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
# -*- coding: utf-8 -*-
33
#
44
# terminal.py
5-
"""Useful functions for terminal-based programs"""
5+
"""
6+
Useful functions for terminal-based programs
7+
"""
68
#
79
# Copyright 2014-2019 Dominic Davis-Foster <[email protected]>
810
#
911
# get_terminal_size, _get_terminal_size_windows, _get_terminal_size_tput and _get_terminal_size_linux
10-
# from https://gist.github.com/jtriley/1108174
12+
# from https://gist.github.com/jtriley/1108174
1113
# Copyright 2011 jtriley
1214
#
1315
# This program is free software; you can redistribute it and/or modify
@@ -27,13 +29,16 @@
2729
#
2830
#
2931

32+
# stdlib
3033
import os
3134
import sys
3235
import shlex
3336
import struct
3437
import platform
3538
import subprocess
36-
from .__init__ import pyversion
39+
40+
# this package
41+
from domdf_python_tools import pyversion
3742

3843

3944
def clear():
@@ -55,6 +60,7 @@ def br():
5560

5661
print("")
5762

63+
5864
def entry(text_to_print):
5965
"""
6066
Version-agnostic input function
@@ -195,6 +201,7 @@ def ioctl_GWINSZ(fd):
195201
return None
196202
return int(cr[1]), int(cr[0])
197203

204+
198205
if __name__ == "__main__":
199206
sizex, sizey = get_terminal_size()
200207
print('width =', sizex, 'height =', sizey)

domdf_python_tools/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# -*- coding: utf-8 -*-
33
#
44
# utils.py
5-
"""General Functions"""
5+
"""
6+
General Functions
7+
"""
68
#
79
# Copyright 2018-2019 Dominic Davis-Foster <[email protected]>
810
#

0 commit comments

Comments
 (0)