libjam 0.0.12__tar.gz → 0.0.14__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libjam
3
- Version: 0.0.12
3
+ Version: 0.0.14
4
4
  Summary: A library jam for Python.
5
5
  Project-URL: Homepage, https://github.com/philippkosarev/libjam
6
6
  Project-URL: Issues, https://github.com/philippkosarev/libjam/issues
@@ -43,16 +43,16 @@ class Notebook:
43
43
  # Reads ini file and returns its contents in the form of a dict.
44
44
  # allow_duplicates is only to be used as a last resort due to the performance
45
45
  # impact and inaccuracy in results.
46
- def read_ini(self, ini_file: str, inline_comments=False, allow_duplicates=False):
46
+ def read_ini(self, ini_file: str, allow_duplicates=False):
47
47
  if drawer.is_file(ini_file) is False:
48
48
  return None
49
49
  ini_file = drawer.absolute_path(ini_file)
50
- if inline_comments is True:
51
- parser = configparser.ConfigParser(inline_comment_prefixes=('#', ';'))
52
- else:
53
- parser = configparser.ConfigParser()
50
+ parser = configparser.ConfigParser()
54
51
  try:
55
52
  parser.read(ini_file)
53
+ except configparser.InterpolationSyntaxError:
54
+ parser = configparser.ConfigParser(inline_comment_prefixes=('#', ';'))
55
+ parser.read(ini_file)
56
56
  except configparser.DuplicateSectionError:
57
57
  if allow_duplicates is True:
58
58
  ini_string = open(ini_file, 'r').read()
@@ -107,16 +107,18 @@ class Notebook:
107
107
  parser.write(file)
108
108
 
109
109
  # Reads a given json file as a dictionary.
110
+ # Returns None if file doesn't exist.
110
111
  def read_json(self, json_file: str):
111
112
  if drawer.is_file(json_file) is False:
112
113
  return None
113
114
  json_file = drawer.absolute_path(json_file)
114
115
  json_string = open(json_file, 'r').read()
116
+ json_string = json_string.replace('null', 'None')
117
+ # Trying the sane method
115
118
  try:
116
119
  data = json.loads(json_string)
120
+ # Exception in case json contains multiline values
117
121
  except json.decoder.JSONDecodeError:
118
- json_string = json_string.replace('\n', ' ').strip()
122
+ json_string = ' '.join(json_string.split())
119
123
  data = ast.literal_eval(json_string)
120
- except:
121
- data = None
122
124
  return data
@@ -3,26 +3,31 @@ import shutil
3
3
 
4
4
  # Responsible for formatting, modification and printing of strings
5
5
  class Typewriter:
6
- def __init__(self):
7
- # Shorthand vars
8
- self.BOLD = '\033[1m'
9
- self.NORMAL = '\033[0m'
10
- self.CLEAR = '\x1b[2K'
11
- self.CURSOR_UP = '\033[1A'
6
+ # Shorthand vars
7
+ BOLD = '\033[1m'
8
+ NORMAL = '\033[0m'
9
+ CLEAR = '\x1b[2K'
10
+ CURSOR_UP = '\033[1A'
12
11
 
13
12
  # Gets a string, makes it bold, returns the string
14
13
  def bolden(self, text: str):
15
14
  text = f'{self.BOLD}{text}{self.NORMAL}'
16
15
  return text
17
16
 
18
- # Clears a given number of lines in the terminal
19
- # if given 0 the current line will be erased
17
+ # Returns current terminal width and height (columns and lines) as a tuple.
18
+ def get_terminal_size(self):
19
+ size = shutil.get_terminal_size()
20
+ x, y = size[0], size[1]
21
+ return (x, y)
22
+
23
+ # Clears a given number of lines in the terminal.
24
+ # If the specified number of lines is 0 then the current line will be erased.
20
25
  def clear_lines(self, lines: int):
21
26
  if lines == 0:
22
27
  print("\r" + self.CLEAR, end='')
23
28
  return
24
29
  for line in range(lines):
25
- print(self.CURSOR_UP + self.CLEAR, end='')
30
+ print(self.CLEAR, end=self.CURSOR_UP)
26
31
 
27
32
  # Clears current line to print a new one.
28
33
  # Usecase: after typewriter.print_status()
@@ -38,7 +43,7 @@ class Typewriter:
38
43
  # Prints on the same line
39
44
  def print_progress(self, status: str, current: int, total: int):
40
45
  width = 25
41
- progress_float= (current / total)
46
+ progress_float = (current / total)
42
47
  percent = int(round((progress_float* 100), 0))
43
48
  percent_string = str(percent)
44
49
  if percent < 100:
@@ -14,7 +14,7 @@ include = [
14
14
 
15
15
  [project]
16
16
  name = "libjam"
17
- version = "0.0.12"
17
+ version = "0.0.14"
18
18
  authors = [
19
19
  { name="Philipp Kosarev", email="philipp.kosarev@gmail.com" },
20
20
  ]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes