Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit d97c725

Browse files
author
PokestarFan
committed
Added docstrings and moved messages
1 parent 6031841 commit d97c725

File tree

4 files changed

+101
-27
lines changed

4 files changed

+101
-27
lines changed

Diff for: markdowntable/__init__.py

+59-24
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,28 @@
88
from .exceptions import (SuppressedError,
99
TooManyValues,
1010
DoNotOverwrite)
11+
from .messages import (not_enough_values,
12+
overwrite_message)
13+
14+
15+
# Todo: Add remove_column and remove row
1116

1217

1318
class Table:
1419
"""docstring for Table.
1520
This is the main class. It adds rows and columns, with data
1621
"""
1722

18-
def __init__(self, name, debug=True):
19-
super(Table, self).__init__()
20-
self.todebug = debug
21-
self.rows = 0
22-
self.columns = 1
23+
def __init__(self, name, debug=True): # creates self variables
24+
"""
25+
26+
:param name: string
27+
:param debug: boolean
28+
"""
29+
super(Table, self).__init__() # idk
30+
self.todebug = debug # debug?
31+
self.rows = 0 # rows
32+
self.columns = 1 # columns
2333
self.table = '''|{}|'''.format(str(name))
2434
self.finalized = False
2535
if self.todebug:
@@ -28,11 +38,13 @@ def __init__(self, name, debug=True):
2838

2939
def debug(self, print_d=True):
3040
"""
31-
:rtype: str
41+
42+
:param print_d: bool
43+
:return: string
3244
"""
33-
global dmessage
45+
global debugmessage
3446
try:
35-
dmessage = '''Printing debug information:
47+
debugmessage = '''Printing debug information:
3648
Rows: {rows}
3749
Columns: {cols}
3850
Finalized?: {fin}
@@ -43,15 +55,21 @@ def debug(self, print_d=True):
4355
table=self.table,
4456
funcs=self.functions)
4557
if print_d:
46-
print(dmessage)
58+
print(debugmessage)
4759
else:
48-
return dmessage
60+
return debugmessage
4961
except NameError:
5062
pass
5163
except Exception as e:
52-
raise SuppressedError(type(e).__name__, str(e), dmessage)
64+
raise SuppressedError(type(e).__name__, str(e), debugmessage)
5365

5466
def add_column(self, name, all_cols=False):
67+
"""
68+
69+
:param name: string
70+
:param all_cols: string
71+
:return: None
72+
"""
5573
self.columns += 1
5674
self.table += '{}|'.format(str(name))
5775
try:
@@ -65,6 +83,11 @@ def add_column(self, name, all_cols=False):
6583
raise SuppressedError(type(e).__name__, str(e), self.debug(print_d=False))
6684

6785
def all_columns(self, *args):
86+
"""
87+
88+
:param args: string
89+
:return: None
90+
"""
6891
try:
6992
all_col_data = {'function': 'all_columns', 'data': []}
7093
for value in args:
@@ -74,6 +97,10 @@ def all_columns(self, *args):
7497
raise SuppressedError(type(e).__name__, str(e), self.debug(print_d=False))
7598

7699
def finalize_cols(self):
100+
"""
101+
102+
:return: None
103+
"""
77104
try:
78105
finalizer = '\n|'
79106
for i in range(self.columns):
@@ -84,6 +111,12 @@ def finalize_cols(self):
84111
raise SuppressedError(type(e).__name__, str(e), self.debug(print_d=False))
85112

86113
def add_row(self, show_warning_message=True, *args):
114+
"""
115+
116+
:param show_warning_message: bool
117+
:param args: string
118+
:return: None
119+
"""
87120
try:
88121
if self.finalized_run:
89122
self.finalized_run = False
@@ -104,16 +137,12 @@ def add_row(self, show_warning_message=True, *args):
104137
add_row_data['data']['values'].append(args[i])
105138
if self.columns > rows_made:
106139
if show_warning_message:
107-
print(
108-
"You did not enter in enough values. You entered in {} values out of {} values. The values "
109-
"that you did not enter in will be filled in with a blank space. You can stop this message "
110-
"from appearing by adding the argument show_warning_message = False".format(
111-
str(rows_made), str(self.columns)))
140+
print(not_enough_values(rows_made, self.columns))
112141
add_row_data['data']['message_shown'] = True
113142
for i in range(int(self.columns - rows_made)):
114143
row += ' |'
115-
add_row_data['data']['values'].append('{} blank values added'.format(str(int(self.columns) - int(
116-
rows_made))))
144+
# noinspection PyTypeChecker
145+
add_row_data['data']['values'].append('{} blank values added'.format(str(self.columns - rows_made)))
117146
elif self.columns < rows_made:
118147
raise TooManyValues(self.columns)
119148
self.table += '\n{}'.format(row)
@@ -124,7 +153,15 @@ def add_row(self, show_warning_message=True, *args):
124153
raise SuppressedError(type(e).__name__, str(e), self.debug(print_d=False))
125154

126155
def export_table_to_file(self, filename='markdowntable', extension='txt', mode='w+', overwrite_warning=True):
127-
global mode_check, message_displayed, fileread
156+
"""
157+
158+
:param filename: string
159+
:param extension: string
160+
:param mode: string
161+
:param overwrite_warning: bool
162+
:return: None
163+
"""
164+
global mode_check, message_displayed, file_read
128165
try:
129166
with open('{fname}.{ext}'.format(fname=str(filename), ext=str(extension)), str(mode)) as file:
130167
try:
@@ -133,16 +170,14 @@ def export_table_to_file(self, filename='markdowntable', extension='txt', mode='
133170
if mode == 'w' or mode == 'w+':
134171
mode_check = True
135172
if len(contents) > 0 and overwrite_warning and mode_check:
136-
print(
137-
'This file already contains content. Do you want to overwrite the contents of the file? '
138-
'You can add the argument mode = a[+] to not overwrite.')
173+
print()
139174
true = True
140175
false = False
141176
overwrite = input('Write True or False:')
142177
if overwrite:
143178
raise DoNotOverwrite
144179
message_displayed = True
145-
fileread = True
180+
file_read = True
146181
except io.UnsupportedOperation:
147182
pass
148183
except DoNotOverwrite:
@@ -151,6 +186,6 @@ def export_table_to_file(self, filename='markdowntable', extension='txt', mode='
151186
file.write(self.table)
152187
self.functions.append({'function': 'export_table_to_file',
153188
'data': {'filename': filename, 'extension': extension, 'writemode': mode,
154-
'overwrite_warning': overwrite_warning, 'file read': fileread}})
189+
'overwrite_warning': overwrite_warning, 'file read': file_read}})
155190
except Exception as e:
156191
raise SuppressedError(type(e).__name__, str(e), self.debug(print_d=False))

Diff for: markdowntable/exceptions.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33

44
class MarkdownTableException(Exception):
5+
"""
6+
Base class exception for all exceptions.
7+
"""
58
def __init__(self, debug):
9+
"""
10+
11+
:param debug: string
12+
"""
613
Exception.__init__(self,
714
'There is an error with your Markdown Table. Printing debug information. \n {debug}'.format(
815
debug=debug))
@@ -13,7 +20,10 @@ class SuppressedError(MarkdownTableException):
1320

1421
def __init__(self, error, message, debug):
1522
"""
16-
:rtype: None
23+
24+
:param error: string
25+
:param message: string
26+
:param debug: string
1727
"""
1828
Exception.__init__(self, '''An error has occured. Printing error. information:
1929
Error Name: {n}
@@ -23,9 +33,17 @@ def __init__(self, error, message, debug):
2333

2434
class TooManyValues(MarkdownTableException):
2535
def __init__(self, columns):
36+
"""
37+
38+
:param columns: string
39+
"""
2640
Exception.__init__(self,
2741
'You entered in too many row values. Please only enter {} row names.'.format(str(columns)))
2842

2943

3044
class DoNotOverwrite(MarkdownTableException):
31-
pass
45+
def __init__(self):
46+
"""
47+
48+
"""
49+
Exception.__init__(self, 'The user stated to not overwrite the file.')

Diff for: markdowntable/messages.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Part of Python-Markdown-Table. Contains the messages the main program uses.
3+
"""
4+
5+
6+
def not_enough_values(rows_made, columns):
7+
"""
8+
9+
:param rows_made: string
10+
:param columns: string
11+
:return: string
12+
"""
13+
message = "You did not enter in enough values. You entered in {} values out of {} values. The values that you did" \
14+
" " \
15+
"not enter in will be filled in with a blank space. You can stop this message from appearing by adding " \
16+
"the argument show_warning_message = False".format(str(rows_made), str(columns))
17+
return message
18+
19+
20+
overwrite_message = 'This file already contains content. Do you want to overwrite the contents of the file? You can ' \
21+
'add the argument mode = a[+] to not overwrite. '

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
setup(name='markdowntable',
5-
version='5.0.1.2',
5+
version='5.0.1.3',
66
description='Easy way to make markdown code for tables',
77
url='https://github.com/PokestarFan/Python-Markdown-Table',
88
author='PokestarFan',

0 commit comments

Comments
 (0)