metripy 0.3.2__py3-none-any.whl → 0.3.3__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 metripy might be problematic. Click here for more details.

@@ -1,6 +1,8 @@
1
1
  import os
2
2
  import shutil
3
+ import sys
3
4
  from datetime import datetime
5
+ from pathlib import Path
4
6
 
5
7
 
6
8
  from metripy.Application.Config.ReportConfig import ReportConfig
@@ -16,7 +18,16 @@ class Reporter(ReporterInterface):
16
18
  ):
17
19
  self.config: ReportConfig = config
18
20
  self.output = output
19
- self.template_dir = os.path.join(os.getcwd(), "templates/html_report")
21
+
22
+ # Find templates directory - works both in development and when installed
23
+ template_dir = self._find_template_dir()
24
+ if not template_dir.exists():
25
+ raise FileNotFoundError(
26
+ f"Could not find templates directory. Searched in: "
27
+ f"{template_dir}"
28
+ )
29
+
30
+ self.template_dir = str(template_dir)
20
31
  self.project_name = project_name
21
32
 
22
33
  self.page_renderer_factory = PageRendererFactory(
@@ -27,6 +38,28 @@ class Reporter(ReporterInterface):
27
38
  "project_name": project_name,
28
39
  "last_updated": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
29
40
  }
41
+
42
+ def _find_template_dir(self) -> Path:
43
+ """Find the templates directory, checking multiple possible locations"""
44
+ package_dir = Path(__file__).parent.parent.parent # metripy package root
45
+
46
+ # List of possible locations to check
47
+ possible_locations = [
48
+ # Development: templates at project root
49
+ package_dir.parent / "templates" / "html_report",
50
+ # Alternative: templates inside metripy package
51
+ package_dir / "templates" / "html_report",
52
+ # System install location
53
+ Path(sys.prefix) / "share" / "metripy" / "templates" / "html_report",
54
+ # Fallback to cwd (for development)
55
+ Path.cwd() / "metripy" / "templates" / "html_report",
56
+ ]
57
+
58
+ for location in possible_locations:
59
+ if location.exists() and (location / "index.html").exists():
60
+ return location
61
+
62
+ return possible_locations[0]
30
63
 
31
64
  def generate(self, metrics: ProjectMetrics):
32
65
 
@@ -63,12 +96,6 @@ class Reporter(ReporterInterface):
63
96
  )
64
97
  # shutil.copytree(os.path.join(self.template_dir, "fonts"), os.path.join(self.config.path, "fonts"), dirs_exist_ok=True)
65
98
 
66
- # copy logo, lies 2 down from the templates directory
67
- shutil.copy(
68
- os.path.join(self.template_dir, "../..", "logo.svg"),
69
- os.path.join(self.config.path, "images", "logo.svg"),
70
- )
71
-
72
99
  # Render main pages
73
100
  self.render_index_page(metrics)
74
101
  self.render_files_page(metrics)