libjam 0.0.14__tar.gz → 0.0.16__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.14
3
+ Version: 0.0.16
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
libjam-0.0.16/build.sh ADDED
@@ -0,0 +1,28 @@
1
+ #! /bin/bash
2
+
3
+ # Functions
4
+ function Ask {
5
+ while true; do
6
+ read -p "$* [y/N]: " yn
7
+ case $yn in
8
+ [Yy]*) return 0 ;;
9
+ [Nn]*) return 1 ;;
10
+ *) return 1 ;;
11
+ esac
12
+ done
13
+ }
14
+
15
+ function Publish {
16
+ python3 -m twine upload --repository pypi dist/*
17
+ }
18
+
19
+ function Build {
20
+ echo "Deleting 'dist' directory..."
21
+ rm ./dist -r
22
+ echo "Building..."
23
+ python3 -m build
24
+ }
25
+
26
+ # Running
27
+ Build
28
+ Ask "Publish new version to PyPi?" && Publish
@@ -90,13 +90,12 @@ class Drawer:
90
90
 
91
91
  # Returns a list of files in a given folder
92
92
  def get_files(self, path: str):
93
- path = realpath(path)
94
93
  unfiltered_files = self.get_all(path)
95
94
  files = []
96
95
  for file in unfiltered_files:
97
- if self.is_file:
96
+ if self.is_file(path):
98
97
  files.append(file)
99
- return outpath(files)
98
+ return files
100
99
 
101
100
  # Returns a list of folders in a given folder
102
101
  def get_folders(self, path: str):
@@ -8,9 +8,17 @@ drawer = Drawer()
8
8
  # Deals with configs and reading/writing files
9
9
  class Notebook:
10
10
 
11
+ # Reads a text file and returns a string.
12
+ def read_file(self, path):
13
+ if drawer.is_folder(path):
14
+ raise FileExistsError(f"Attempted to read folder '{path}' as a text file.")
15
+ elif drawer.is_file(path) is False:
16
+ raise FileNotFoundError(f"File '{path}' not found.")
17
+ return open(path, 'r').read()
18
+
11
19
  # Checking if config exists, and creating one if it does not
12
20
  def check_config(self, config_template_file: str, config_file: str):
13
- config_template = open(config_template_file, 'r').read()
21
+ config_template = self.read_file(config_template_file)
14
22
  config_folder = drawer.get_parent(config_file)
15
23
  if drawer.is_folder(config_folder) is False:
16
24
  drawer.make_folder(config_folder)
@@ -23,36 +31,24 @@ class Notebook:
23
31
 
24
32
  # parsing a toml config
25
33
  def read_toml(self, config_file: str):
26
- config_file = drawer.absolute_path(config_file)
27
- # Parsing config
28
- data = open(config_file, 'r').read()
29
- try:
30
- data = tomllib.loads(data)
31
- for category in data:
32
- for item in data.get(category):
33
- path = data.get(category).get(item)
34
- if type(path) == str:
35
- data[category][item] = drawer.absolute_path(path)
36
- return data
37
- except:
38
- print(f"Encountered error reading '{config_file}'")
39
- print(f"Contents of '{config_file}':")
40
- print(data)
41
- return None
34
+ data = self.read_file(config_file)
35
+ data = tomllib.loads(data)
36
+ for category in data:
37
+ for item in data.get(category):
38
+ path = data.get(category).get(item)
39
+ if type(path) == str:
40
+ data[category][item] = drawer.absolute_path(path)
41
+ return data
42
42
 
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
46
  def read_ini(self, ini_file: str, allow_duplicates=False):
47
- if drawer.is_file(ini_file) is False:
48
- return None
49
- ini_file = drawer.absolute_path(ini_file)
50
- parser = configparser.ConfigParser()
47
+ # Checking file
48
+ data = self.read_file(ini_file)
49
+ parser = configparser.ConfigParser(inline_comment_prefixes=('#', ';'))
51
50
  try:
52
- parser.read(ini_file)
53
- except configparser.InterpolationSyntaxError:
54
- parser = configparser.ConfigParser(inline_comment_prefixes=('#', ';'))
55
- parser.read(ini_file)
51
+ parser.read_string(data)
56
52
  except configparser.DuplicateSectionError:
57
53
  if allow_duplicates is True:
58
54
  ini_string = open(ini_file, 'r').read()
@@ -95,7 +91,6 @@ class Notebook:
95
91
  def write_ini(self, ini_file: str, contents: dict):
96
92
  if drawer.is_file(ini_file) is False:
97
93
  return None
98
- ini_file = drawer.absolute_path(ini_file)
99
94
  parser = configparser.ConfigParser()
100
95
  for section in contents:
101
96
  for var_name in contents.get(section):
@@ -109,10 +104,7 @@ class Notebook:
109
104
  # Reads a given json file as a dictionary.
110
105
  # Returns None if file doesn't exist.
111
106
  def read_json(self, json_file: str):
112
- if drawer.is_file(json_file) is False:
113
- return None
114
- json_file = drawer.absolute_path(json_file)
115
- json_string = open(json_file, 'r').read()
107
+ json_string = self.read_file(json_file)
116
108
  json_string = json_string.replace('null', 'None')
117
109
  # Trying the sane method
118
110
  try:
@@ -83,7 +83,10 @@ class Typewriter:
83
83
  # Adding spaces
84
84
  current_text = 0
85
85
  for text in column:
86
- spaces = ' ' * ((column_width - len(text)) + 1)
86
+ if current_column == len(columns) - 1:
87
+ spaces = ''
88
+ else:
89
+ spaces = ' ' * ((column_width - len(text)) + 1)
87
90
  columns[current_column][current_text] = text + spaces
88
91
  current_text += 1
89
92
  current_column += 1
@@ -121,4 +124,4 @@ class Typewriter:
121
124
  for text in row:
122
125
  output += text
123
126
  # Returning string
124
- return output
127
+ return output.rstrip()
@@ -14,7 +14,7 @@ include = [
14
14
 
15
15
  [project]
16
16
  name = "libjam"
17
- version = "0.0.14"
17
+ version = "0.0.16"
18
18
  authors = [
19
19
  { name="Philipp Kosarev", email="philipp.kosarev@gmail.com" },
20
20
  ]
libjam-0.0.14/build.sh DELETED
@@ -1,8 +0,0 @@
1
- #! /bin/bash
2
-
3
- echo "Removing 'dist' directory..."
4
- rm ./dist -r
5
- python3 -m build
6
-
7
- # Publish command:
8
- # python3 -m twine upload --repository pypi dist/*
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes