datamarket 0.9.19__py3-none-any.whl → 0.9.20__py3-none-any.whl

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.

Potentially problematic release.


This version of datamarket might be problematic. Click here for more details.

datamarket/utils/main.py CHANGED
@@ -2,8 +2,6 @@
2
2
  # IMPORTS
3
3
 
4
4
  import asyncio
5
- from dataclasses import dataclass
6
- import inspect
7
5
  import logging
8
6
  import random
9
7
  import re
@@ -12,26 +10,25 @@ import shutil
12
10
  import subprocess
13
11
  import time
14
12
  from pathlib import Path
15
- from typing import Literal, Optional, Union
13
+ from typing import Any, Literal, Self, Union
16
14
 
17
15
  import pendulum
18
16
  from croniter import croniter
19
- from configparser import RawConfigParser
20
17
  from dynaconf import Dynaconf, add_converter
21
18
 
22
19
  logger = logging.getLogger(__name__)
23
20
 
24
- ########################################################################################################################
25
- # CLASSES
21
+
22
+ class NoProjectFoundError(Exception):
23
+ def __init__(self):
24
+ super().__init__("Could not detect project. Did you add the config file?")
26
25
 
27
26
 
28
- @dataclass
29
- class ProjectMetadata:
30
- cmd_prefix: str
31
- package_name: str
32
- env_name: str
33
- path: Path
34
- config_path: Path
27
+ class NoPackageFoundError(Exception):
28
+ def __init__(self):
29
+ super().__init__(
30
+ "A project was detected but it has no packages inside the 'src' directory"
31
+ )
35
32
 
36
33
 
37
34
  ########################################################################################################################
@@ -79,62 +76,80 @@ def read_converter(path_str: str):
79
76
  return f.read()
80
77
 
81
78
 
82
- def get_config(
83
- config_file: Optional[Path] = None, tz: str = "Europe/Madrid"
84
- ) -> Dynaconf:
85
- config_file = config_file or get_project_metadata().config_path
86
-
87
- if Path(config_file).suffix == ".ini":
88
- logger.warning("Using legacy INI config reader. Please migrate to TOML")
89
- cfg = RawConfigParser()
90
- cfg.read(config_file)
91
- return cfg
92
-
93
- add_converter("read", read_converter)
94
-
95
- dt_now = get_granular_date("now", tz)
96
- dt_weekly = get_granular_date("weekly", tz)
97
- dt_biweekly = get_granular_date("biweekly", tz)
98
-
99
- config = Dynaconf(
100
- environments=True,
101
- env_switcher="SYSTYPE",
102
- )
103
-
104
- config.load_file(path=config_file)
105
- config.load_file(path=Path.home() / config_file.name)
106
-
107
- config.vars = {
108
- "year": dt_now.strftime("%Y"),
109
- "month": dt_now.strftime("%m"),
110
- "day": dt_now.strftime("%d"),
111
- "now": dt_now.strftime("%Y-%m-%d %H:%M:%S"),
112
- "now_stripped": dt_now.strftime("%Y%m%d%H%M%S"),
113
- "today": dt_now.strftime("%Y-%m-%d"),
114
- "today_stripped": dt_now.strftime("%Y%m%d"),
115
- "weekly_date": dt_weekly.strftime("%Y-%m-%d"),
116
- "weekly_date_stripped": dt_weekly.strftime("%Y%m%d"),
117
- "biweekly_date": dt_biweekly.strftime("%Y-%m-%d"),
118
- "biweekly_date_stripped": dt_biweekly.strftime("%Y%m%d"),
119
- "dynaconf_merge": True,
120
- }
121
-
122
- return config
123
-
124
- def get_project_metadata() -> ProjectMetadata:
125
- caller_frame = inspect.stack()[1]
126
- current_file_parts = Path(caller_frame.filename).resolve().parts
127
- src_index = current_file_parts.index("src")
128
-
129
- cmd_prefix = "dix vnc run --" if shutil.which("dix") else ""
130
- package_name = current_file_parts[src_index + 1]
131
- env_name = f"{package_name}_env"
132
- project_path = Path(*current_file_parts[:src_index])
133
- config_path = project_path / "config.toml"
134
-
135
- return ProjectMetadata(
136
- cmd_prefix, package_name, env_name, project_path, config_path
137
- )
79
+ class Project:
80
+ CONFIG_FILE_NAME = "config.toml"
81
+
82
+ def __init__(self, path: Path):
83
+ self.path = path
84
+
85
+ try:
86
+ self.pkg_name = next((self.path / "src").glob("*")).name
87
+ except StopIteration:
88
+ raise NoPackageFoundError()
89
+
90
+ self.env_name = f"{self.pkg_name}_env"
91
+ self.config_path = self.path / self.CONFIG_FILE_NAME
92
+ self.tests_path = self.path / "tests"
93
+ self.cmd_prefix = "dix vnc run --" if shutil.which("dix") else ""
94
+
95
+ @classmethod
96
+ def from_file(cls, file: Path | str) -> Self:
97
+ file_path = Path(file).resolve()
98
+
99
+ while file_path != file_path.parent:
100
+ config_file = file_path / cls.CONFIG_FILE_NAME
101
+
102
+ if not config_file.is_file():
103
+ file_path = file_path.parent
104
+ continue
105
+
106
+ if file_path.parent == Path("/home"):
107
+ raise NoProjectFoundError()
108
+
109
+ return cls(file_path)
110
+
111
+ raise NoProjectFoundError()
112
+
113
+ def to_dict(self) -> dict[str, Any]:
114
+ return {
115
+ "project_path": self.path,
116
+ "cmd_prefix": self.cmd_prefix,
117
+ "env_name": self.env_name,
118
+ "pkg_name": self.pkg_name,
119
+ "config_path": self.config_path,
120
+ }
121
+
122
+ def get_config(self, tz: str = "Europe/Madrid") -> Dynaconf:
123
+ add_converter("read", read_converter)
124
+
125
+ dt_now = get_granular_date("now", tz)
126
+ dt_weekly = get_granular_date("weekly", tz)
127
+ dt_biweekly = get_granular_date("biweekly", tz)
128
+
129
+ config = Dynaconf(
130
+ environments=True,
131
+ env_switcher="SYSTYPE",
132
+ )
133
+
134
+ config.load_file(path=self.config_path)
135
+ config.load_file(path=Path.home() / self.config_path.name)
136
+
137
+ config.vars = {
138
+ "year": dt_now.strftime("%Y"),
139
+ "month": dt_now.strftime("%m"),
140
+ "day": dt_now.strftime("%d"),
141
+ "now": dt_now.strftime("%Y-%m-%d %H:%M:%S"),
142
+ "now_stripped": dt_now.strftime("%Y%m%d%H%M%S"),
143
+ "today": dt_now.strftime("%Y-%m-%d"),
144
+ "today_stripped": dt_now.strftime("%Y%m%d"),
145
+ "weekly_date": dt_weekly.strftime("%Y-%m-%d"),
146
+ "weekly_date_stripped": dt_weekly.strftime("%Y%m%d"),
147
+ "biweekly_date": dt_biweekly.strftime("%Y-%m-%d"),
148
+ "biweekly_date_stripped": dt_biweekly.strftime("%Y%m%d"),
149
+ "dynaconf_merge": True,
150
+ }
151
+
152
+ return config
138
153
 
139
154
 
140
155
  def set_logger(level):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: datamarket
3
- Version: 0.9.19
3
+ Version: 0.9.20
4
4
  Summary: Utilities that integrate advanced scraping knowledge into just one library.
5
5
  License: GPL-3.0-or-later
6
6
  Author: DataMarket
@@ -13,11 +13,11 @@ datamarket/params/nominatim.py,sha256=pBYRfoBkkLBg2INbFymefmYSzaAVujQSpEro5c1hD_
13
13
  datamarket/utils/__init__.py,sha256=8D5a8oKgqd6WA1RUkiKCn4l_PVemtyuckxQut0vDHXM,20
14
14
  datamarket/utils/airflow.py,sha256=al0vc0YUikNu3Oy51VSn52I7pMU40akFBOl_UlHa2E4,795
15
15
  datamarket/utils/alchemy.py,sha256=SRq6kgh1aANXVShBPgAuglmNhZssPWwWEY503gKSia8,635
16
- datamarket/utils/main.py,sha256=O6rX-65h4h0j2zs9dofdTPlly5reKDnvgLtTwbLmbWg,6529
16
+ datamarket/utils/main.py,sha256=j8wnAxeLvijdRU9M4V6HunWH7vgWWHP4u4xamzkWcUU,7009
17
17
  datamarket/utils/selenium.py,sha256=IMKlbLzXABFhACnWzhHmB0l2hhVzNwHGZwbo14nEewQ,2499
18
18
  datamarket/utils/soda.py,sha256=eZTXFbI1P3WoMd1MM-YjoVTpdjTcDSWuvBb7ViBMhSQ,941
19
19
  datamarket/utils/typer.py,sha256=FDF3l6gh3UlAFPsHCtesnekvct2rKz0oFn3uKARBQvE,814
20
- datamarket-0.9.19.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
21
- datamarket-0.9.19.dist-info/METADATA,sha256=yMqp6i6mEyKhwB6VOxXF5Gg1sldJSbkuB9HH2w3NdPQ,6459
22
- datamarket-0.9.19.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
23
- datamarket-0.9.19.dist-info/RECORD,,
20
+ datamarket-0.9.20.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
21
+ datamarket-0.9.20.dist-info/METADATA,sha256=2BsxMukyGFYw-lk455Ksf7NJ_M-mjNB7-_vl3nOdxQ4,6459
22
+ datamarket-0.9.20.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
23
+ datamarket-0.9.20.dist-info/RECORD,,