toolsos 0.2.2__tar.gz → 0.2.4__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.
Files changed (30) hide show
  1. {toolsos-0.2.2 → toolsos-0.2.4}/PKG-INFO +2 -2
  2. {toolsos-0.2.2 → toolsos-0.2.4}/pyproject.toml +2 -2
  3. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/database/database_connection.py +59 -0
  4. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/huisstijl/graphs/bargraph.py +11 -1
  5. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/huisstijl/graphs/graph_styles.py +3 -1
  6. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/huisstijl/graphs/linegraph.py +13 -2
  7. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/huisstijl/graphs/piegraph.py +5 -0
  8. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/huisstijl/graphs/styler.py +21 -14
  9. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/huisstijl/tables/tables.py +17 -5
  10. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos.egg-info/PKG-INFO +2 -2
  11. {toolsos-0.2.2 → toolsos-0.2.4}/README.md +0 -0
  12. {toolsos-0.2.2 → toolsos-0.2.4}/setup.cfg +0 -0
  13. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/__init__.py +0 -0
  14. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/cbs_tools.py +0 -0
  15. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/create_tables.py +0 -0
  16. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/database/database_transfer.py +0 -0
  17. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/download.py +0 -0
  18. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/geo.py +0 -0
  19. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/helpers.py +0 -0
  20. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/huisstijl/__init__.py +0 -0
  21. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/huisstijl/colors.py +0 -0
  22. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/huisstijl/graphs/__init__.py +0 -0
  23. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/huisstijl/tables/__init__.py +0 -0
  24. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/huisstijl/tables/table_helpers.py +0 -0
  25. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/huisstijl/tables/table_styles.py +0 -0
  26. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos/polars_helpers.py +0 -0
  27. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos.egg-info/SOURCES.txt +0 -0
  28. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos.egg-info/dependency_links.txt +0 -0
  29. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos.egg-info/requires.txt +0 -0
  30. {toolsos-0.2.2 → toolsos-0.2.4}/src/toolsos.egg-info/top_level.txt +0 -0
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: toolsos
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: OS tools
5
5
  Author-email: OS <d.schmitz@amsterdam.nl>
6
6
  Keywords: tools,Onderzoek & Statistiek
7
7
  Classifier: License :: OSI Approved :: MIT License
8
8
  Classifier: Programming Language :: Python
9
9
  Classifier: Programming Language :: Python :: 3
10
- Requires-Python: >=3.11
10
+ Requires-Python: >=3.10
11
11
  Description-Content-Type: text/markdown
12
12
  Provides-Extra: dev
13
13
  Requires-Dist: black; extra == "dev"
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "toolsos"
9
- version = "0.2.2"
9
+ version = "0.2.4"
10
10
  description = "OS tools"
11
11
  readme = "README.md"
12
12
  authors = [{ name = "OS", email = "d.schmitz@amsterdam.nl" }]
@@ -25,7 +25,7 @@ keywords = ["tools", "Onderzoek & Statistiek"]
25
25
  # use pip install "toolsos[all]" to pip install with al dependencies
26
26
 
27
27
  dependencies = []
28
- requires-python = ">=3.11"
28
+ requires-python = ">=3.10"
29
29
 
30
30
  [project.optional-dependencies]
31
31
  dev = [
@@ -2,8 +2,10 @@ from __future__ import annotations
2
2
 
3
3
  import getpass
4
4
  import json
5
+ import os
5
6
  import subprocess
6
7
  from json import JSONDecodeError
8
+ from pathlib import Path
7
9
  from typing import Optional
8
10
 
9
11
  import keyring
@@ -99,6 +101,63 @@ def get_azure_access_token():
99
101
  subprocess.run("az login", shell=True)
100
102
 
101
103
 
104
+ def get_token_from_pgpass() -> None:
105
+ p = Path(os.getenv("APPDATA")) / "postgresql" / "pgpass.conf"
106
+ with open(p) as f:
107
+ token = f.readline().split(":")[4]
108
+
109
+ return token
110
+
111
+
112
+ def write_pgpass(
113
+ host: str, port: str, database: str, user: str, path: str | None = None
114
+ ) -> None:
115
+ password = get_azure_access_token()
116
+ conn_string = f"{host}:{port}:{database}:{user}:{password}"
117
+
118
+ if not path:
119
+ if os.name == "nt":
120
+ path = Path(os.getenv("APPDATA")) / "postgresql" / "pgpass.conf"
121
+ else:
122
+ path = Path("$home/.pgpass")
123
+
124
+ if not path.parent.exists():
125
+ path.parent.mkdir()
126
+
127
+ with open(path, "w") as f:
128
+ f.write(conn_string)
129
+
130
+ if os.name != "nt":
131
+ path.chmod("0600")
132
+
133
+
134
+ def write_multiple_pgpass(conn_details, path: str | None = None):
135
+ password = get_azure_access_token()
136
+
137
+ conn_strings = []
138
+ for c in conn_details:
139
+ c_string = f'{c["host"]}:{c["port"]}:{c["database"]}:{c["user"]}:{password}'
140
+ conn_strings.append(c_string)
141
+
142
+ if not path:
143
+ if os.name == "nt":
144
+ path = Path(os.getenv("APPDATA")) / "postgresql" / "pgpass.conf"
145
+ else:
146
+ path = Path("$home/.pgpass")
147
+
148
+ if not path.parent.exists():
149
+ path.parent.mkdir()
150
+
151
+ with open(path, "w") as f:
152
+ f.writelines(line + "\n" for line in conn_strings)
153
+
154
+ if os.name != "nt":
155
+ path.chmod("0600")
156
+
157
+
158
+ # Writing connection settings to pgpass.conf
159
+
160
+
102
161
  if __name__ == "__main__":
103
162
  ...
104
163
  # Examples
@@ -1,4 +1,5 @@
1
1
  import plotly.express as px
2
+
2
3
  from .styler import BaseStyle
3
4
 
4
5
  basestyle = BaseStyle()
@@ -14,6 +15,7 @@ def bar(
14
15
  barmode=None,
15
16
  width=750,
16
17
  height=490,
18
+ font="Amsterdam Sans",
17
19
  **kwargs,
18
20
  ):
19
21
  fig = px.bar(
@@ -21,7 +23,7 @@ def bar(
21
23
  x=x,
22
24
  y=y,
23
25
  color=color,
24
- template=basestyle.get_base_template("bar", orientation=orientation),
26
+ template=basestyle.get_base_template("bar", orientation=orientation, font=font),
25
27
  width=width,
26
28
  color_discrete_sequence=color_discrete_sequence,
27
29
  height=height,
@@ -43,6 +45,7 @@ def stacked_single(
43
45
  color: str = None,
44
46
  color_discrete_sequence: list = None,
45
47
  orientation="v",
48
+ font="Amsterdam Sans",
46
49
  **kwargs,
47
50
  ):
48
51
  fig = bar(
@@ -53,6 +56,7 @@ def stacked_single(
53
56
  color_discrete_sequence=color_discrete_sequence,
54
57
  barmode="relative",
55
58
  orientation=orientation,
59
+ font=font,
56
60
  **kwargs,
57
61
  )
58
62
 
@@ -71,6 +75,7 @@ def stacked_multiple(
71
75
  color: str = None,
72
76
  color_discrete_sequence: list = None,
73
77
  orientation="v",
78
+ font="Amsterdam Sans",
74
79
  **kwargs,
75
80
  ):
76
81
  fig = bar(
@@ -81,6 +86,7 @@ def stacked_multiple(
81
86
  color_discrete_sequence=color_discrete_sequence,
82
87
  barmode="stack",
83
88
  orientation=orientation,
89
+ font=font,
84
90
  **kwargs,
85
91
  )
86
92
 
@@ -94,6 +100,7 @@ def grouped(
94
100
  color: str = None,
95
101
  color_discrete_sequence: list = None,
96
102
  orientation="v",
103
+ font="Amsterdam Sans",
97
104
  **kwargs,
98
105
  ):
99
106
  fig = bar(
@@ -104,6 +111,7 @@ def grouped(
104
111
  color_discrete_sequence=color_discrete_sequence,
105
112
  barmode="group",
106
113
  orientation=orientation,
114
+ font=font,
107
115
  **kwargs,
108
116
  )
109
117
 
@@ -116,6 +124,7 @@ def single(
116
124
  y: str,
117
125
  color_discrete_sequence: list = None,
118
126
  orientation="v",
127
+ font="Amsterdam Sans",
119
128
  **kwargs,
120
129
  ):
121
130
  fig = bar(
@@ -124,6 +133,7 @@ def single(
124
133
  y=y,
125
134
  color_discrete_sequence=color_discrete_sequence,
126
135
  orientation=orientation,
136
+ font=font,
127
137
  **kwargs,
128
138
  )
129
139
 
@@ -16,8 +16,10 @@ STYLE_OLD = {
16
16
 
17
17
  STYLE_NEW = {
18
18
  "font_bold": {"family": "Amsterdam Sans ExtraBold, Corbel", "size": 15},
19
+ "font_bold_corbel": {"family": "Corbel Bold", "size": 15},
19
20
  "font": {"family": "Amsterdam Sans, Corbel", "size": 15},
20
- "axis_font": {"family": font, "size": 15},
21
+ "font_corbel": {"family": "Corbel", "size": 15},
22
+ "axis_font": {"family": "Amsterdam Sans ExtraBold, Corbel", "size": 15},
21
23
  "plot_bgcolor": "#FFFFFF",
22
24
  "gridline_color": "#dbdbdb",
23
25
  "gridline_width": 0.75,
@@ -5,7 +5,17 @@ from .styler import BaseStyle
5
5
  basestyle = BaseStyle()
6
6
 
7
7
 
8
- def line(data, x, y, color: None, width=750, height=490, **kwargs):
8
+ def line(
9
+ data,
10
+ x,
11
+ y,
12
+ color: None,
13
+ width=750,
14
+ height=490,
15
+ color_discrete_sequence=None,
16
+ font="Amsterdam Sans",
17
+ **kwargs,
18
+ ):
9
19
  fig = px.line(
10
20
  data_frame=data,
11
21
  x=x,
@@ -13,7 +23,8 @@ def line(data, x, y, color: None, width=750, height=490, **kwargs):
13
23
  color=color,
14
24
  width=width,
15
25
  height=height,
16
- template=BaseStyle().get_base_template(graph_type="line"),
26
+ color_discrete_sequence=color_discrete_sequence,
27
+ template=BaseStyle().get_base_template(graph_type="line", font=font),
17
28
  **kwargs,
18
29
  )
19
30
 
@@ -1,4 +1,5 @@
1
1
  import plotly.express as px
2
+
2
3
  from .styler import BaseStyle
3
4
 
4
5
  basestyle = BaseStyle()
@@ -12,6 +13,8 @@ def pie(
12
13
  width=750,
13
14
  height=490,
14
15
  text_format: str = None,
16
+ color_discrete_sequence=None,
17
+ font="Amsterdam Sans",
15
18
  **kwargs,
16
19
  ):
17
20
  fig = px.pie(
@@ -22,6 +25,8 @@ def pie(
22
25
  height=height,
23
26
  hole=hole,
24
27
  template=BaseStyle().get_base_template(),
28
+ color_discrete_sequence=color_discrete_sequence,
29
+ font=font,
25
30
  **kwargs,
26
31
  )
27
32
 
@@ -109,7 +109,6 @@ class BaseStyle:
109
109
  self.style = json.load(file)
110
110
 
111
111
  def _get_axis_format(self):
112
- self.gridline_color = "#dbdbdb" # Jorren vragen om deze aan te passen
113
112
 
114
113
  return {
115
114
  "zerolinecolor": self.style["gridline_color"],
@@ -121,29 +120,37 @@ class BaseStyle:
121
120
  "showgrid": self.style["showgrid"],
122
121
  }
123
122
 
124
- def _get_base_template_layout(self):
123
+ def _get_base_template_layout(self, font):
124
+ if font == "Amsterdam Sans":
125
+ font_ = self.style["font"]
126
+ font_bold_ = self.style["font_bold"]
127
+ elif font == "Corbel":
128
+ font_ = self.style["font_corbel"]
129
+ font_bold_ = self.style["font_bold_corbel"]
130
+ else:
131
+ raise ValueError("Font should be 'Amsterdam Sans' or 'Corbel'")
132
+
125
133
  return go.layout.Template(
126
134
  layout={
127
- # "font": self.styles["font_bold"],
128
135
  "xaxis": {
129
- "tickfont": self.style["font_bold"],
136
+ "tickfont": font_bold_,
130
137
  },
131
138
  "yaxis": {
132
- "tickfont": {
133
- "family": self.style["axis_font"]["family"],
134
- "size": self.style["axis_font"]["size"],
135
- },
139
+ "tickfont": font_bold_,
136
140
  },
137
- "legend": {"font": self.style["font"]},
141
+ "legend": {"font": font_},
138
142
  "plot_bgcolor": self.style["plot_bgcolor"],
139
- # "colorway": self.colors["darkblue_lightblue_gradient_5"],
140
- "separators": ",", # Jorren vragen om deze toe te voegen
141
- "font": self.style["font_bold"],
143
+ "separators": ",",
144
+ "font": font_bold_,
142
145
  }
143
146
  )
144
147
 
145
148
  def get_base_template(
146
- self, graph_type: str = None, orientation: str = None, colors: str = None
149
+ self,
150
+ graph_type: str = None,
151
+ orientation: str = None,
152
+ colors: str = None,
153
+ font: str = "Amsterdam Sans",
147
154
  ):
148
155
  """[summary]
149
156
 
@@ -158,7 +165,7 @@ class BaseStyle:
158
165
  Returns:
159
166
  [type]: [description]
160
167
  """
161
- base_template = self._get_base_template_layout()
168
+ base_template = self._get_base_template_layout(font)
162
169
  axis_format = self._get_axis_format()
163
170
 
164
171
  if graph_type == "bar":
@@ -379,6 +379,7 @@ def write_to_worksheet(
379
379
  source: str | None = None,
380
380
  col_filter: bool | None = None,
381
381
  col_widths: list | None = None,
382
+ min_column_width: int | None = None,
382
383
  cells_to_merge: list[list[int]] | None = None,
383
384
  ) -> None:
384
385
  """Writing data to worksheet. Used for writing values to cells and formatting the cells
@@ -423,7 +424,7 @@ def write_to_worksheet(
423
424
  _insert_source(ws, source, arr)
424
425
 
425
426
  if col_widths:
426
- _set_column_widths(ws, col_widths)
427
+ _set_column_widths(ws, col_widths, min_column_width)
427
428
 
428
429
  if title:
429
430
  _insert_title(ws, title)
@@ -432,9 +433,16 @@ def write_to_worksheet(
432
433
  _merge_cells(ws, cells_to_merge, title)
433
434
 
434
435
 
435
- def _set_column_widths(ws: Any, col_widths: list[int]) -> None:
436
+ def _set_column_widths(
437
+ ws: Any, col_widths: list[int], min_column_width: int | None
438
+ ) -> None:
436
439
  for idx, col_width in enumerate(col_widths):
437
440
  col_letter = get_column_letter(idx + 1)
441
+
442
+ if min_column_width:
443
+ if col_width < min_column_width:
444
+ col_width = min_column_width
445
+
438
446
  ws.column_dimensions[col_letter].width = col_width
439
447
 
440
448
 
@@ -493,6 +501,7 @@ def write_table(
493
501
  blue_border_row_ids: int | list[int] | None = None,
494
502
  number_format: str = "0.0",
495
503
  autofit_columns: str | None = "column_names",
504
+ min_column_width: int | None = None,
496
505
  col_filter: bool | None = False,
497
506
  style: str = "old",
498
507
  combine_multiindex: bool | int = False,
@@ -508,9 +517,6 @@ def write_table(
508
517
  data = {"Sheet1": data}
509
518
 
510
519
  for sheet_name, df in data.items():
511
- if column_names_to_string == True:
512
- df = cols_to_str(df)
513
-
514
520
  format_worksheet(
515
521
  wb=wb,
516
522
  df=df,
@@ -534,6 +540,7 @@ def write_table(
534
540
  blue_border_row_ids=blue_border_row_ids,
535
541
  number_format=number_format,
536
542
  autofit_columns=autofit_columns,
543
+ min_column_width=min_column_width,
537
544
  col_filter=col_filter,
538
545
  combine_multiindex=combine_multiindex,
539
546
  column_names_to_string=column_names_to_string,
@@ -582,6 +589,7 @@ def format_worksheet(
582
589
  blue_border_row_ids: int | list[int] | None = None,
583
590
  number_format: str = "0.0",
584
591
  autofit_columns: str | None = "column_names",
592
+ min_column_width: int | None = None,
585
593
  col_filter: bool | None = False,
586
594
  combine_multiindex: bool | int = False,
587
595
  column_names_to_string: bool = True,
@@ -607,6 +615,9 @@ def format_worksheet(
607
615
  perc_col_format (str, optional): The formatting string of percentage columns. Defaults to None.
608
616
  col_filter (bool, optional): Set filter on columns. Defaults to False.
609
617
  """
618
+ if column_names_to_string == True:
619
+ df = cols_to_str(df)
620
+
610
621
  arr = df_to_array(df)
611
622
 
612
623
  blue_rows = []
@@ -711,4 +722,5 @@ def format_worksheet(
711
722
  col_filter=col_filter,
712
723
  col_widths=col_widths,
713
724
  cells_to_merge=cells_to_merge,
725
+ min_column_width=min_column_width,
714
726
  )
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: toolsos
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: OS tools
5
5
  Author-email: OS <d.schmitz@amsterdam.nl>
6
6
  Keywords: tools,Onderzoek & Statistiek
7
7
  Classifier: License :: OSI Approved :: MIT License
8
8
  Classifier: Programming Language :: Python
9
9
  Classifier: Programming Language :: Python :: 3
10
- Requires-Python: >=3.11
10
+ Requires-Python: >=3.10
11
11
  Description-Content-Type: text/markdown
12
12
  Provides-Extra: dev
13
13
  Requires-Dist: black; extra == "dev"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes