calkit-python 0.3.0__tar.gz → 0.3.2__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 (45) hide show
  1. {calkit_python-0.3.0 → calkit_python-0.3.2}/PKG-INFO +1 -2
  2. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/__init__.py +1 -1
  3. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/cli/office.py +21 -7
  4. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/git.py +4 -1
  5. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/models.py +5 -0
  6. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/office.py +15 -10
  7. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/server.py +30 -10
  8. {calkit_python-0.3.0 → calkit_python-0.3.2}/.github/FUNDING.yml +0 -0
  9. {calkit_python-0.3.0 → calkit_python-0.3.2}/.github/workflows/publish-test.yml +0 -0
  10. {calkit_python-0.3.0 → calkit_python-0.3.2}/.github/workflows/publish.yml +0 -0
  11. {calkit_python-0.3.0 → calkit_python-0.3.2}/.gitignore +0 -0
  12. {calkit_python-0.3.0 → calkit_python-0.3.2}/LICENSE +0 -0
  13. {calkit_python-0.3.0 → calkit_python-0.3.2}/README.md +0 -0
  14. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/cli/__init__.py +0 -0
  15. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/cli/config.py +0 -0
  16. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/cli/core.py +0 -0
  17. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/cli/import_.py +0 -0
  18. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/cli/list.py +0 -0
  19. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/cli/main.py +0 -0
  20. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/cli/new.py +0 -0
  21. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/cli/notebooks.py +0 -0
  22. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/cloud.py +0 -0
  23. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/config.py +0 -0
  24. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/core.py +0 -0
  25. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/data.py +0 -0
  26. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/docker.py +0 -0
  27. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/dvc.py +0 -0
  28. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/gui.py +0 -0
  29. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/jupyter.py +0 -0
  30. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/tests/__init__.py +0 -0
  31. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/tests/cli/__init__.py +0 -0
  32. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/tests/cli/test_list.py +0 -0
  33. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/tests/cli/test_main.py +0 -0
  34. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/tests/cli/test_new.py +0 -0
  35. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/tests/test_core.py +0 -0
  36. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/tests/test_dvc.py +0 -0
  37. {calkit_python-0.3.0 → calkit_python-0.3.2}/calkit/tests/test_jupyter.py +0 -0
  38. {calkit_python-0.3.0 → calkit_python-0.3.2}/examples/cfd-study/README.md +0 -0
  39. {calkit_python-0.3.0 → calkit_python-0.3.2}/examples/cfd-study/calkit.yaml +0 -0
  40. {calkit_python-0.3.0 → calkit_python-0.3.2}/examples/cfd-study/config/simulations/runs.csv +0 -0
  41. {calkit_python-0.3.0 → calkit_python-0.3.2}/examples/cfd-study/notebook.ipynb +0 -0
  42. {calkit_python-0.3.0 → calkit_python-0.3.2}/examples/ms-office/.gitignore +0 -0
  43. {calkit_python-0.3.0 → calkit_python-0.3.2}/examples/ms-office/README.md +0 -0
  44. {calkit_python-0.3.0 → calkit_python-0.3.2}/examples/ms-office/calkit.yaml +0 -0
  45. {calkit_python-0.3.0 → calkit_python-0.3.2}/pyproject.toml +0 -0
@@ -1,11 +1,10 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: calkit-python
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Reproducibility simplified.
5
5
  Project-URL: Homepage, https://github.com/calkit/calkit
6
6
  Project-URL: Issues, https://github.com/calkit/calkit/issues
7
7
  Author-email: Pete Bachant <petebachant@gmail.com>
8
- License-File: LICENSE
9
8
  Classifier: License :: OSI Approved :: MIT License
10
9
  Classifier: Operating System :: OS Independent
11
10
  Classifier: Programming Language :: Python :: 3
@@ -1,4 +1,4 @@
1
- __version__ = "0.3.0"
1
+ __version__ = "0.3.2"
2
2
 
3
3
  from .core import *
4
4
  from . import git
@@ -15,12 +15,14 @@ office_app = typer.Typer(no_args_is_help=True)
15
15
 
16
16
 
17
17
  @office_app.command(
18
- name="excel-chart-to-png",
19
- help="Extract a chart from Excel and save to PNG.",
18
+ name="excel-chart-to-image",
19
+ help="Extract a chart from Excel and save to image.",
20
20
  )
21
- def excel_chart_to_png(
21
+ def excel_chart_to_image(
22
22
  input_fpath: Annotated[str, typer.Argument(help="Input Excel file path.")],
23
- output_fpath: Annotated[str, typer.Argument(help="Output PNG file path.")],
23
+ output_fpath: Annotated[
24
+ str, typer.Argument(help="Output image file path.")
25
+ ],
24
26
  sheet: Annotated[
25
27
  int, typer.Option("--sheet", help="Sheet in workbook.")
26
28
  ] = 1,
@@ -34,7 +36,7 @@ def excel_chart_to_png(
34
36
  f"Exporting chart at index {chart_index} from sheet {sheet} "
35
37
  f"in {input_fpath} to {output_fpath}"
36
38
  )
37
- calkit.office.excel_chart_to_png(
39
+ calkit.office.excel_chart_to_image(
38
40
  input_fpath=input_fpath,
39
41
  output_fpath=output_fpath,
40
42
  sheet=sheet,
@@ -44,7 +46,19 @@ def excel_chart_to_png(
44
46
 
45
47
  @office_app.command(name="word-to-pdf", help="Convert a Word document to PDF.")
46
48
  def word_to_pdf(
47
- input_fpath: Annotated[str, typer.Argument(help="Input Excel file path.")],
48
- output_fpath: Annotated[str, typer.Argument(help="Output PNG file path.")],
49
+ input_fpath: Annotated[
50
+ str, typer.Argument(help="Input Word document file path.")
51
+ ],
52
+ output_fpath: Annotated[
53
+ str,
54
+ typer.Option(
55
+ "-o",
56
+ "--output",
57
+ help=(
58
+ "Output file path. If not specified, "
59
+ "will be the same as input with a .pdf extension."
60
+ ),
61
+ ),
62
+ ] = None,
49
63
  ):
50
64
  docx2pdf.convert(input_path=input_fpath, output_path=output_fpath)
@@ -8,7 +8,10 @@ import git
8
8
  def detect_project_name(path=None) -> str:
9
9
  """Read the project owner and name from the remote.
10
10
 
11
- TODO: Currently only works with GitHub remotes.
11
+ TODO: Currently only works with GitHub remotes where the GitHub repo
12
+ name is identical to the Calkit project name, which is not guaranteed.
13
+ We should probably look inside ``calkit.yaml`` at ``name``
14
+ first, and fallback to the GitHub remote URL if we can't find that.
12
15
  """
13
16
  url = git.Repo(path=path).remote().url
14
17
  return url.split("github.com")[-1][1:].removesuffix(".git")
@@ -107,6 +107,11 @@ class ProjectInfo(BaseModel):
107
107
  distinguish what has been newly created here.
108
108
  """
109
109
 
110
+ title: str | None = None
111
+ owner: str | None = None
112
+ description: str | None = None
113
+ name: str | None = None
114
+ git_repo_url: str | None = None
110
115
  parent: str | None = None
111
116
  questions: list[str] = []
112
117
  datasets: list[Dataset] = []
@@ -5,13 +5,13 @@ import os
5
5
  from PIL import ImageGrab
6
6
 
7
7
 
8
- def excel_chart_to_png(
8
+ def excel_chart_to_image(
9
9
  input_fpath: str,
10
10
  output_fpath: str,
11
11
  sheet: int = 1,
12
12
  chart_index: int = 0,
13
13
  ):
14
- """Export a chart from an Excel sheet to PNG."""
14
+ """Export a chart from an Excel sheet to image."""
15
15
  import win32com.client
16
16
 
17
17
  # Open the excel application using win32com
@@ -21,18 +21,23 @@ def excel_chart_to_png(
21
21
  excel.DisplayAlerts = 0
22
22
  # Open workbook
23
23
  wb = excel.Workbooks.Open(os.path.abspath(input_fpath))
24
- factor = 1.0
25
24
  # Extract sheet
25
+ # TODO: Close workbook if something fails
26
26
  sheet = excel.Sheets(sheet)
27
27
  shape = sheet.Shapes[chart_index]
28
28
  shape.Copy()
29
29
  image = ImageGrab.grabclipboard()
30
- length_x, width_y = image.size
31
- size = int(factor * length_x), int(factor * width_y)
32
- image_resize = image.resize(size)
33
- # Save the image into the existing png file, overwriting if exists
34
- image_resize.save(
35
- os.path.abspath(output_fpath), "png", quality=95, dpi=(300, 300)
36
- )
30
+ # Check if we need to change the mode of the image
31
+ _, ext = os.path.splitext(output_fpath)
32
+ if (
33
+ ext in [".jpg", ".eps", ".tiff", ".gif", ".bmp"]
34
+ and image.mode != "RGB"
35
+ ):
36
+ image = image.convert("RGB")
37
+ # Save the image, overwriting if exists
38
+ dirname = os.path.dirname(output_fpath)
39
+ if dirname and not os.path.isdir(dirname):
40
+ os.makedirs(dirname)
41
+ image.save(os.path.abspath(output_fpath), quality=95, dpi=(300, 300))
37
42
  wb.Close(True)
38
43
  excel.Quit()
@@ -59,7 +59,7 @@ class LocalProject(BaseModel):
59
59
 
60
60
 
61
61
  @app.get("/")
62
- def get_root() -> list[LocalProject]:
62
+ def get_root(get_jupyter_servers: bool = True) -> list[LocalProject]:
63
63
  """Return information about the current running server.
64
64
 
65
65
  - The project owner
@@ -68,9 +68,15 @@ def get_root() -> list[LocalProject]:
68
68
  - A Jupyter server running here, if applicable
69
69
  """
70
70
  resp = []
71
+ logger.info("Finding project directories")
71
72
  project_dirs = calkit.find_project_dirs()
72
- servers = calkit.jupyter.get_servers()
73
+ if get_jupyter_servers:
74
+ logger.info("Getting Jupyter servers")
75
+ servers = calkit.jupyter.get_servers()
76
+ else:
77
+ servers = []
73
78
  for pdir in project_dirs:
79
+ logger.info(f"Inspecting {pdir}")
74
80
  try:
75
81
  project = calkit.git.detect_project_name(path=pdir)
76
82
  except ValueError:
@@ -96,8 +102,10 @@ def get_root() -> list[LocalProject]:
96
102
 
97
103
 
98
104
  @app.get("/projects/{owner_name}/{project_name}")
99
- def get_local_project(owner_name: str, project_name: str) -> LocalProject:
100
- all_projects = get_root()
105
+ def get_local_project(
106
+ owner_name: str, project_name: str, get_jupyter_server: bool = True
107
+ ) -> LocalProject:
108
+ all_projects = get_root(get_jupyter_servers=get_jupyter_server)
101
109
  for project in all_projects:
102
110
  if (
103
111
  project.owner_name == owner_name
@@ -235,14 +243,22 @@ class Status(BaseModel):
235
243
 
236
244
 
237
245
  @app.get("/projects/{owner_name}/{project_name}/status")
238
- def get_status(owner_name: str, project_name: str):
246
+ def get_status(
247
+ owner_name: str,
248
+ project_name: str,
249
+ fetch_git: bool = True,
250
+ fetch_dvc: bool = True,
251
+ ):
239
252
  """Get status in working directory, from both Git and DVC."""
240
253
  errors = []
241
254
  logger.info(f"Looking for project {owner_name}/{project_name}")
242
- project = get_local_project(owner_name, project_name)
255
+ project = get_local_project(
256
+ owner_name, project_name, get_jupyter_server=False
257
+ )
243
258
  logger.info(f"Found project at {project.wdir}")
244
259
  git_repo = git.Repo(project.wdir)
245
- git_repo.git.fetch()
260
+ if fetch_git:
261
+ git_repo.git.fetch()
246
262
  untracked_git_files = git_repo.untracked_files
247
263
  # Get a list of diffs of the working tree to the index
248
264
  git_diff = git_repo.index.diff(None)
@@ -281,13 +297,17 @@ def get_status(owner_name: str, project_name: str):
281
297
  dvc_pipeline_status = dvc.repo.status.status(dvc_repo)
282
298
  # Remove any always changed entries so the pipeline doesn't look
283
299
  # out of date
300
+ logger.info(f"Raw DVC pipeline status: {dvc_pipeline_status}")
284
301
  dvc_pipeline_status = {
285
- k: v
302
+ k.split("dvc.yaml:")[-1]: v
286
303
  for k, v in dvc_pipeline_status.items()
287
- if v != ["always changed"] and "dvc.yaml:" in k
304
+ if v != ["always changed"] and not k.endswith(".dvc")
288
305
  }
306
+ logger.info(
307
+ f"DVC pipeline status after filtering: {dvc_pipeline_status}"
308
+ )
289
309
  dvc_data_status = dvc.repo.data.status(
290
- dvc_repo, not_in_remote=True, remote_refresh=True
310
+ dvc_repo, not_in_remote=fetch_dvc, remote_refresh=fetch_dvc
291
311
  )
292
312
  # Reformat this a bit, since it can be a little hard to understand
293
313
  # DVC calls a path committed when its DVC file is staged
File without changes
File without changes
File without changes