icplot 0.0.2__py3-none-any.whl → 0.0.4__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.
icplot/image_utils.py CHANGED
@@ -4,13 +4,33 @@ from pathlib import Path
4
4
  from wand.image import Image
5
5
  from wand.color import Color
6
6
 
7
+ import cairosvg
8
+
7
9
  logger = logging.getLogger(__name__)
8
10
 
9
11
 
10
- def pdf_to_png(source_path: Path):
11
- png_filename = source_path.parent / f"{source_path.stem}.png"
12
- with Image(filename=source_path, resolution=300) as img:
12
+ def _get_out_filename(source: Path, target: Path | None, extension: str) -> Path:
13
+ if target:
14
+ return target
15
+ else:
16
+ return source.parent / f"{source.stem}.{extension}"
17
+
18
+
19
+ def pdf_to_png(source: Path, target: Path | None = None):
20
+
21
+ outfile = _get_out_filename(source, target, "png")
22
+ with Image(filename=source, resolution=300) as img:
13
23
  img.format = "png"
14
24
  img.background_color = Color("white")
15
25
  img.alpha_channel = "remove"
16
- img.save(filename=png_filename)
26
+ img.save(filename=outfile)
27
+
28
+
29
+ def svg_to_png(source: Path, target: Path | None = None):
30
+ outfile = _get_out_filename(source, target, "png")
31
+ cairosvg.svg2png(url=str(source), write_to=str(outfile))
32
+
33
+
34
+ def svg_to_pdf(source: Path, target: Path | None = None):
35
+ outfile = _get_out_filename(source, target, "pdf")
36
+ cairosvg.svg2pdf(url=str(source), write_to=str(outfile))
icplot/main_cli.py ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env python3
2
+ import argparse
3
+ import logging
4
+ from pathlib import Path
5
+
6
+ from iccore import logging_utils
7
+ from iccore import runtime
8
+
9
+ from icplot.image_utils import pdf_to_png, svg_to_png, svg_to_pdf
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+
14
+ def launch_common(args):
15
+ runtime.ctx.set_is_dry_run(args.dry_run)
16
+ logging_utils.setup_default_logger()
17
+
18
+
19
+ def convert(args):
20
+ launch_common(args)
21
+
22
+ logger.info("Attempting coversion between %s %s", args.source, args.target)
23
+
24
+ if args.target:
25
+ target = Path(args.target).resolve()
26
+ else:
27
+ target = None
28
+
29
+ if args.source.suffix == ".pdf":
30
+ pdf_to_png(args.source.resolve(), target)
31
+ elif args.source.suffix == ".svg":
32
+ if target:
33
+ if target.suffix == ".png":
34
+ svg_to_png(args.source.resolve(), target)
35
+ elif target.suffix == ".pdf":
36
+ svg_to_pdf(args.source.resolve(), target)
37
+ else:
38
+ svg_to_png(args.source)
39
+ logger.info("Finished conversion")
40
+
41
+
42
+ def main_cli():
43
+ parser = argparse.ArgumentParser()
44
+ parser.add_argument(
45
+ "--dry_run",
46
+ type=int,
47
+ default=0,
48
+ help="Dry run script - 0 can modify, 1 can read, 2 no modify - no read",
49
+ )
50
+ subparsers = parser.add_subparsers(required=True)
51
+
52
+ convert_parser = subparsers.add_parser("convert")
53
+ convert_parser.add_argument(
54
+ "--source",
55
+ type=Path,
56
+ help="Path to file to be converted from",
57
+ )
58
+ convert_parser.add_argument(
59
+ "--target",
60
+ type=str,
61
+ default="",
62
+ help="Path to file to be converted to",
63
+ )
64
+ convert_parser.set_defaults(func=convert)
65
+
66
+ args = parser.parse_args()
67
+ args.func(args)
68
+
69
+
70
+ if __name__ == "__main__":
71
+ main_cli()
@@ -1,47 +1,4 @@
1
- import json
2
-
3
-
4
1
  class GitlabUser:
5
2
 
6
3
  def __init__(self):
7
4
  self.name = ""
8
-
9
-
10
- class Issue:
11
-
12
- def __init__(self):
13
- self.title = ""
14
- self.description = ""
15
- self.start_date = ""
16
- self.due_date = ""
17
- self.assignee = None
18
-
19
-
20
- class Milestone:
21
-
22
- def __init__(self, json_input=None):
23
- self.title = ""
24
- self.description = ""
25
- self.start_date = None
26
- self.due_date = None
27
- self.issues = []
28
-
29
- if json_input:
30
- self.load(json_input)
31
-
32
- def load(self, json):
33
- self.title = json["title"]
34
- self.description = json["description"]
35
- self.start_date = json["start_date"]
36
- self.due_date = json["due_date"]
37
-
38
- def serialize(self):
39
- return {
40
- "title": self.title,
41
- "description": self.description,
42
- "start_date": self.start_date,
43
- "due_date": self.due_date,
44
- }
45
-
46
- def __str__(self):
47
- return json.dumps(self.serialize())
icplot/tex_interface.py CHANGED
@@ -11,19 +11,16 @@ logger = logging.getLogger(__name__)
11
11
 
12
12
 
13
13
  class TexInterface:
14
+ def __init__(self, build_dir: Path | None, output_dir: Path | None):
14
15
 
15
- def __init__(self, build_dir: Path, output_dir: Path):
16
-
17
- if not build_dir.is_absolute():
18
- build_dir = Path(os.getcwd()) / build_dir
19
-
16
+ if build_dir:
17
+ self.build_dir: Path = build_dir.resolve()
18
+ else:
19
+ self.build_dir = Path()
20
20
  if not output_dir:
21
- output_dir = build_dir
22
-
23
- if not output_dir.is_absolute():
24
- output_dir = Path(os.getcwd()) / output_dir
25
- self.build_dir = build_dir
26
- self.output_dir = output_dir
21
+ self.output_dir: Path = self.build_dir
22
+ else:
23
+ self.output_dir = output_dir.resolve()
27
24
  self.build_engine = "pdflatex"
28
25
 
29
26
  def build_pdf(self, source_path: Path, build_dir: Path):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: icplot
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Utilities for generating plots and graphics for technical reports.
5
5
  Author-email: "James Grogan, Irish Centre for High End Computing" <james.grogan@ichec.ie>
6
6
  Project-URL: Repository, https://git.ichec.ie/performance/toolshed/icplot
@@ -15,8 +15,9 @@ Requires-Python: >=3.8
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
17
  Requires-Dist: wand
18
- Provides-Extra: cairo
19
- Requires-Dist: pycairo ; extra == 'cairo'
18
+ Requires-Dist: pycairo
19
+ Requires-Dist: CairoSVG
20
+ Requires-Dist: iccore ==0.0.7
20
21
  Provides-Extra: test
21
22
  Requires-Dist: pytest ; extra == 'test'
22
23
  Requires-Dist: pytest-cov ; extra == 'test'
@@ -28,6 +29,35 @@ Requires-Dist: mypy ; extra == 'test'
28
29
 
29
30
  This project is a utility library used at ICHEC for generating plots and graphics for use in technical documents.
30
31
 
32
+ # Installation #
33
+
34
+ The package is available on PyPI. For a minimal installation you can do:
35
+
36
+ ``` shell
37
+ pip install icplot
38
+ ```
39
+
40
+ For full functionality, particularly for conversion of image formats `imagemagick` and `cairo` are required. On Mac you can install them with:
41
+
42
+ ``` shell
43
+ brew install imagemagick cairo
44
+ ```
45
+
46
+ # Features #
47
+
48
+ The project has support for:
49
+
50
+ * Coverting image formats between pdf, svg and png
51
+ * Building pdf output from tex files, including tikz.
52
+
53
+ There is a command line interface included, mainly for testing, which may be heplful in getting to know available features.
54
+
55
+ To covert between image formats you can do:
56
+
57
+ ``` shell
58
+ icplot convert --source my_image.svg --target my_image.png
59
+ ```
60
+
31
61
  # Copyright #
32
62
 
33
63
  Copyright 2024 Irish Centre for High End Computing
@@ -0,0 +1,14 @@
1
+ icplot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ icplot/cairo_interface.py,sha256=55JqNKmZ-KeN0nEHEmCxZcioP7aTJtRp-gdW-Sqi4fM,2105
3
+ icplot/gantt.py,sha256=pbk2fkpM6eep_LAgGUnu2mOn646IAokuqc44qKD8FSA,1909
4
+ icplot/geometry.py,sha256=C8y3u2oBnGNL7o1gqb-JotH7zOwH9iRSUB811OycYMc,1033
5
+ icplot/image_utils.py,sha256=wwMQHuu-wkP_pkssCaTGpF7-OY450APruxxI1wZdkk4,1014
6
+ icplot/main_cli.py,sha256=Xc2bs-MpyTeJWhzEhYHxBZlVQpf51XFfzetDQ2MKyWM,1766
7
+ icplot/project_elements.py,sha256=xXCNc4vTNCo9PKCsxe28GBMG4WDNYK_wGnKjliVjyY4,66
8
+ icplot/tex_interface.py,sha256=QtyT5KLi8LnnuefpTF5QOi43Yl-6rnO-zWQW4qCPGA0,2605
9
+ icplot-0.0.4.dist-info/LICENSE,sha256=JedcPd23DfREo3CH5_Sc8He0jmmbOWIm1_sQaisXZ9E,34592
10
+ icplot-0.0.4.dist-info/METADATA,sha256=AkqhhPYegUIuPvWuoBEJG5S5ruXgIStyV4jS2h4rT-Y,2156
11
+ icplot-0.0.4.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
12
+ icplot-0.0.4.dist-info/entry_points.txt,sha256=6CdEGO5Z4NTQoOeRITTKGtzT3xNX47CGHZuWNWxZuZs,52
13
+ icplot-0.0.4.dist-info/top_level.txt,sha256=T_ecIGmXlOO4_xP86S-OFL8nnoxmDQFXjcDoIwpiHQk,7
14
+ icplot-0.0.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.3.0)
2
+ Generator: setuptools (71.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ icplot = icplot.main_cli:main_cli
@@ -1,12 +0,0 @@
1
- icplot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- icplot/cairo_interface.py,sha256=55JqNKmZ-KeN0nEHEmCxZcioP7aTJtRp-gdW-Sqi4fM,2105
3
- icplot/gantt.py,sha256=pbk2fkpM6eep_LAgGUnu2mOn646IAokuqc44qKD8FSA,1909
4
- icplot/geometry.py,sha256=C8y3u2oBnGNL7o1gqb-JotH7zOwH9iRSUB811OycYMc,1033
5
- icplot/image_utils.py,sha256=roQOR02dEh2NTt3G_EYVGSNL-uYTWFwMBvqz1yVf3-w,451
6
- icplot/project_elements.py,sha256=bIMbiAucpIMZ_xeipJr-V6NwXLPc8DhvV7OdEL7lHXA,993
7
- icplot/tex_interface.py,sha256=fSI15lfee0D-H_r0QItpS3tR1-F0WdRA-MaICBu0cI0,2649
8
- icplot-0.0.2.dist-info/LICENSE,sha256=JedcPd23DfREo3CH5_Sc8He0jmmbOWIm1_sQaisXZ9E,34592
9
- icplot-0.0.2.dist-info/METADATA,sha256=vYO7-jtuO-1y4_SwiJcAwsUxhQdiqoVSvuQIOMD71nM,1433
10
- icplot-0.0.2.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
11
- icplot-0.0.2.dist-info/top_level.txt,sha256=T_ecIGmXlOO4_xP86S-OFL8nnoxmDQFXjcDoIwpiHQk,7
12
- icplot-0.0.2.dist-info/RECORD,,