camel-core 0.1.0__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 (73) hide show
  1. camel_core-0.1.0/.gitignore +1 -0
  2. camel_core-0.1.0/PKG-INFO +48 -0
  3. camel_core-0.1.0/README.md +16 -0
  4. camel_core-0.1.0/camel.log +9 -0
  5. camel_core-0.1.0/camel_core.egg-info/PKG-INFO +48 -0
  6. camel_core-0.1.0/camel_core.egg-info/SOURCES.txt +52 -0
  7. camel_core-0.1.0/camel_core.egg-info/dependency_links.txt +1 -0
  8. camel_core-0.1.0/camel_core.egg-info/requires.txt +17 -0
  9. camel_core-0.1.0/camel_core.egg-info/top_level.txt +1 -0
  10. camel_core-0.1.0/camelcore/__init__.py +0 -0
  11. camel_core-0.1.0/camelcore/app/__init__.py +0 -0
  12. camel_core-0.1.0/camelcore/app/command.py +139 -0
  13. camel_core-0.1.0/camelcore/app/errors.py +23 -0
  14. camel_core-0.1.0/camelcore/app/io/__init__.py +0 -0
  15. camel_core-0.1.0/camelcore/app/io/toolio.py +49 -0
  16. camel_core-0.1.0/camelcore/app/io/tooliodirectory.py +80 -0
  17. camel_core-0.1.0/camelcore/app/io/tooliofile.py +98 -0
  18. camel_core-0.1.0/camelcore/app/io/tooliovalue.py +64 -0
  19. camel_core-0.1.0/camelcore/app/logger.py +21 -0
  20. camel_core-0.1.0/camelcore/app/reports/__init__.py +0 -0
  21. camel_core-0.1.0/camelcore/app/reports/htmlbase.py +235 -0
  22. camel_core-0.1.0/camelcore/app/reports/htmlcitation.py +71 -0
  23. camel_core-0.1.0/camelcore/app/reports/htmlelement.py +67 -0
  24. camel_core-0.1.0/camelcore/app/reports/htmlexpandablediv.py +56 -0
  25. camel_core-0.1.0/camelcore/app/reports/htmlexpandabletable.py +79 -0
  26. camel_core-0.1.0/camelcore/app/reports/htmlreport.py +94 -0
  27. camel_core-0.1.0/camelcore/app/reports/htmlreportsection.py +112 -0
  28. camel_core-0.1.0/camelcore/app/reports/htmltablecell.py +36 -0
  29. camel_core-0.1.0/camelcore/app/reports/htmltableformatter.py +75 -0
  30. camel_core-0.1.0/camelcore/app/testsuite.py +83 -0
  31. camel_core-0.1.0/camelcore/app/utils/__init__.py +0 -0
  32. camel_core-0.1.0/camelcore/app/utils/fastautils.py +183 -0
  33. camel_core-0.1.0/camelcore/app/utils/fastqutils.py +86 -0
  34. camel_core-0.1.0/camelcore/app/utils/fileutils.py +194 -0
  35. camel_core-0.1.0/camelcore/app/utils/galaxyutils.py +31 -0
  36. camel_core-0.1.0/camelcore/app/utils/reportutils.py +142 -0
  37. camel_core-0.1.0/camelcore/app/utils/sambamutils.py +44 -0
  38. camel_core-0.1.0/camelcore/app/utils/snakeutils.py +99 -0
  39. camel_core-0.1.0/camelcore/app/utils/vcfutils.py +67 -0
  40. camel_core-0.1.0/camelcore/resources/__init__.py +4 -0
  41. camel_core-0.1.0/camelcore/resources/reports/jquery-3.2.1.min.js +4 -0
  42. camel_core-0.1.0/camelcore/resources/reports/logo-sciensano.png +0 -0
  43. camel_core-0.1.0/camelcore/resources/reports/style.css +224 -0
  44. camel_core-0.1.0/camelcore/resources/tests/fq_1.fq +16 -0
  45. camel_core-0.1.0/camelcore/resources/tests/fq_1.fq.gz +0 -0
  46. camel_core-0.1.0/camelcore/resources/tests/fq_2.fq +12 -0
  47. camel_core-0.1.0/camelcore/resources/tests/fq_2.fq.gz +0 -0
  48. camel_core-0.1.0/camelcore/resources/tests/interleaved.fq +16 -0
  49. camel_core-0.1.0/camelcore/resources/tests/interleaved.fq.gz +0 -0
  50. camel_core-0.1.0/camelcore/resources/tests/toy.bam +0 -0
  51. camel_core-0.1.0/camelcore/resources/tests/toy.fasta +4 -0
  52. camel_core-0.1.0/camelcore/resources/tests/toy.sam +8 -0
  53. camel_core-0.1.0/camelcore/resources/tests/toy_with_dupl.fasta +4 -0
  54. camel_core-0.1.0/camelcore/resources/tests/variants-filt.vcf.gz +0 -0
  55. camel_core-0.1.0/camelcore/resources/tests/workflow_test.smk +23 -0
  56. camel_core-0.1.0/camelcore/tests/__init__.py +0 -0
  57. camel_core-0.1.0/camelcore/tests/reports/__init__.py +0 -0
  58. camel_core-0.1.0/camelcore/tests/reports/test_htmlreport.py +60 -0
  59. camel_core-0.1.0/camelcore/tests/reports/test_htmltableformatter.py +123 -0
  60. camel_core-0.1.0/camelcore/tests/snakemake/__init__.py +0 -0
  61. camel_core-0.1.0/camelcore/tests/snakemake/test_snakeutils.py +52 -0
  62. camel_core-0.1.0/camelcore/tests/test_command.py +57 -0
  63. camel_core-0.1.0/camelcore/tests/utils/__init__.py +0 -0
  64. camel_core-0.1.0/camelcore/tests/utils/test_fastautils.py +143 -0
  65. camel_core-0.1.0/camelcore/tests/utils/test_fastqutils.py +260 -0
  66. camel_core-0.1.0/camelcore/tests/utils/test_fileutils.py +136 -0
  67. camel_core-0.1.0/camelcore/tests/utils/test_sambamutils.py +64 -0
  68. camel_core-0.1.0/camelcore/tests/utils/test_vcfutils.py +33 -0
  69. camel_core-0.1.0/camelcore/version.py +1 -0
  70. camel_core-0.1.0/codebase_audit_report.md +43 -0
  71. camel_core-0.1.0/pyproject.toml +89 -0
  72. camel_core-0.1.0/script.deb.sh +232 -0
  73. camel_core-0.1.0/uv.lock +992 -0
@@ -0,0 +1 @@
1
+ .idea/
@@ -0,0 +1,48 @@
1
+ Metadata-Version: 2.4
2
+ Name: camel_core
3
+ Version: 0.1.0
4
+ Summary: CAMEL core is a set of utilities used by Bioinformatics Platform at the Belgian Public Health institute (Sciensano).
5
+ Project-URL: Homepage, https://github.com/BioinformaticsPlatformWIV-ISP/MiST
6
+ Project-URL: Issues, https://github.com/BioinformaticsPlatformWIV-ISP/MiST/issues
7
+ Author-email: Sciensano BIOIT team <bioit@sciensano.be>
8
+ License-Expression: GPL-3.0-or-later
9
+ Keywords: genomics,microbial,research
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
14
+ Requires-Python: ==3.12.*
15
+ Requires-Dist: biopython
16
+ Requires-Dist: bs4
17
+ Requires-Dist: click
18
+ Requires-Dist: cyvcf2
19
+ Requires-Dist: furl
20
+ Requires-Dist: humanize
21
+ Requires-Dist: pandas
22
+ Requires-Dist: pysam
23
+ Requires-Dist: rauth
24
+ Requires-Dist: requests
25
+ Requires-Dist: scipy
26
+ Requires-Dist: snakemake
27
+ Requires-Dist: yattag
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest; extra == 'dev'
30
+ Requires-Dist: pytest-xdist; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # CAMEL core
34
+
35
+ CAMEL core is a set of utilities used by Bioinformatics Platform at the Belgian Public Health institute (Sciensano).
36
+
37
+ This package is not meant to be used directly, but contains functionality that is shared between various projects.
38
+
39
+
40
+ ## Functionality
41
+
42
+ - Command execution through subprocess
43
+ - Input/output (IO) classes for handling tool / input output
44
+ - Utility functions for handling common bioinformatics formats such as FASTQ, FASTA, BAM
45
+ - HTML reports
46
+ - Utility functions for working with Snakemake
47
+ - BaseTool class
48
+ - Logging
@@ -0,0 +1,16 @@
1
+ # CAMEL core
2
+
3
+ CAMEL core is a set of utilities used by Bioinformatics Platform at the Belgian Public Health institute (Sciensano).
4
+
5
+ This package is not meant to be used directly, but contains functionality that is shared between various projects.
6
+
7
+
8
+ ## Functionality
9
+
10
+ - Command execution through subprocess
11
+ - Input/output (IO) classes for handling tool / input output
12
+ - Utility functions for handling common bioinformatics formats such as FASTQ, FASTA, BAM
13
+ - HTML reports
14
+ - Utility functions for working with Snakemake
15
+ - BaseTool class
16
+ - Logging
@@ -0,0 +1,9 @@
1
+ 2026-03-10 13:29:33,135 - lmodservice - DEBUG - Loading environment using LMOD
2
+ 2026-03-10 13:29:33,135 - command - INFO - Executing command: module load amrfinder/4.0.19 blast/2.16.0 hmmer/3.4; amrfinder --version
3
+ 2026-03-10 13:29:33,258 - command - DEBUG - stdout: 4.0.19
4
+
5
+ 2026-03-10 13:29:33,258 - command - DEBUG - stderr:
6
+ 2026-03-10 13:29:33,258 - tool - DEBUG - Initializing tool: AMRFinder 4.0.19
7
+ 2026-03-10 13:29:33,258 - tool - INFO - Running tool AMRFinder
8
+ 2026-03-10 13:29:33,258 - tool - INFO - Working directory: /home/bebogaerts/PycharmProjects/CAMEL_core
9
+ 2026-03-10 13:29:33,259 - tool - INFO - Tool parameters: output_path: amrfinder_out.tsv, organism: Salmonella, min_cov: 0.5
@@ -0,0 +1,48 @@
1
+ Metadata-Version: 2.4
2
+ Name: camel_core
3
+ Version: 0.1.0
4
+ Summary: CAMEL core is a set of utilities used by Bioinformatics Platform at the Belgian Public Health institute (Sciensano).
5
+ Author-email: Sciensano BIOIT team <bioit@sciensano.be>
6
+ License-Expression: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/BioinformaticsPlatformWIV-ISP/MiST
8
+ Project-URL: Issues, https://github.com/BioinformaticsPlatformWIV-ISP/MiST/issues
9
+ Keywords: research,microbial,genomics
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: biopython
17
+ Requires-Dist: bs4
18
+ Requires-Dist: click
19
+ Requires-Dist: cyvcf2
20
+ Requires-Dist: furl
21
+ Requires-Dist: humanize
22
+ Requires-Dist: pandas
23
+ Requires-Dist: pysam
24
+ Requires-Dist: rauth
25
+ Requires-Dist: requests
26
+ Requires-Dist: scipy
27
+ Requires-Dist: snakemake
28
+ Requires-Dist: yattag
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest; extra == "dev"
31
+ Requires-Dist: pytest-xdist; extra == "dev"
32
+
33
+ # CAMEL core
34
+
35
+ CAMEL core is a set of utilities used by Bioinformatics Platform at the Belgian Public Health institute (Sciensano).
36
+
37
+ This package is not meant to be used directly, but contains functionality that is shared between various projects.
38
+
39
+
40
+ ## Functionality
41
+
42
+ - Command execution through subprocess
43
+ - Input/output (IO) classes for handling tool / input output
44
+ - Utility functions for handling common bioinformatics formats such as FASTQ, FASTA, BAM
45
+ - HTML reports
46
+ - Utility functions for working with Snakemake
47
+ - BaseTool class
48
+ - Logging
@@ -0,0 +1,52 @@
1
+ README.md
2
+ pyproject.toml
3
+ camel_core.egg-info/PKG-INFO
4
+ camel_core.egg-info/SOURCES.txt
5
+ camel_core.egg-info/dependency_links.txt
6
+ camel_core.egg-info/requires.txt
7
+ camel_core.egg-info/top_level.txt
8
+ camelcore/__init__.py
9
+ camelcore/version.py
10
+ camelcore/app/__init__.py
11
+ camelcore/app/command.py
12
+ camelcore/app/errors.py
13
+ camelcore/app/logger.py
14
+ camelcore/app/testsuite.py
15
+ camelcore/app/io/__init__.py
16
+ camelcore/app/io/toolio.py
17
+ camelcore/app/io/tooliodirectory.py
18
+ camelcore/app/io/tooliofile.py
19
+ camelcore/app/io/tooliovalue.py
20
+ camelcore/app/reports/__init__.py
21
+ camelcore/app/reports/htmlbase.py
22
+ camelcore/app/reports/htmlcitation.py
23
+ camelcore/app/reports/htmlelement.py
24
+ camelcore/app/reports/htmlexpandablediv.py
25
+ camelcore/app/reports/htmlexpandabletable.py
26
+ camelcore/app/reports/htmlreport.py
27
+ camelcore/app/reports/htmlreportsection.py
28
+ camelcore/app/reports/htmltablecell.py
29
+ camelcore/app/reports/htmltableformatter.py
30
+ camelcore/app/utils/__init__.py
31
+ camelcore/app/utils/fastautils.py
32
+ camelcore/app/utils/fastqutils.py
33
+ camelcore/app/utils/fileutils.py
34
+ camelcore/app/utils/galaxyutils.py
35
+ camelcore/app/utils/reportutils.py
36
+ camelcore/app/utils/sambamutils.py
37
+ camelcore/app/utils/snakeutils.py
38
+ camelcore/app/utils/vcfutils.py
39
+ camelcore/resources/__init__.py
40
+ camelcore/tests/__init__.py
41
+ camelcore/tests/test_command.py
42
+ camelcore/tests/reports/__init__.py
43
+ camelcore/tests/reports/test_htmlreport.py
44
+ camelcore/tests/reports/test_htmltableformatter.py
45
+ camelcore/tests/snakemake/__init__.py
46
+ camelcore/tests/snakemake/test_snakeutils.py
47
+ camelcore/tests/utils/__init__.py
48
+ camelcore/tests/utils/test_fastautils.py
49
+ camelcore/tests/utils/test_fastqutils.py
50
+ camelcore/tests/utils/test_fileutils.py
51
+ camelcore/tests/utils/test_sambamutils.py
52
+ camelcore/tests/utils/test_vcfutils.py
@@ -0,0 +1,17 @@
1
+ biopython
2
+ bs4
3
+ click
4
+ cyvcf2
5
+ furl
6
+ humanize
7
+ pandas
8
+ pysam
9
+ rauth
10
+ requests
11
+ scipy
12
+ snakemake
13
+ yattag
14
+
15
+ [dev]
16
+ pytest
17
+ pytest-xdist
@@ -0,0 +1 @@
1
+ camelcore
File without changes
File without changes
@@ -0,0 +1,139 @@
1
+ import os
2
+ import subprocess
3
+ import warnings
4
+ from pathlib import Path
5
+ from typing import Any
6
+ from camelcore.app.logger import logger
7
+
8
+
9
+ class Command:
10
+ """
11
+ Helper class to run commands.
12
+ """
13
+
14
+ def __init__(self, command: str | list[str] = None, stdout_path: Path | None = None) -> None:
15
+ """
16
+ Initializes the command object.
17
+ Note it is strongly recommended to initialize commands as a list of string for security
18
+ :param command: (optional) Command line call or list of arguments
19
+ :param stdout_path: stdout path
20
+ :return: None
21
+ """
22
+ self._stdout = None
23
+ self._stderr = None
24
+ self._procedure = None
25
+ self._return_code = None
26
+ self._command = command
27
+ self._stdout_path = stdout_path
28
+
29
+ @property
30
+ def stderr(self) -> str:
31
+ """
32
+ Returns the stderr from the command execution.
33
+ :return: Standard error
34
+ """
35
+ return self._stderr
36
+
37
+ @property
38
+ def stdout(self) -> str:
39
+ """
40
+ Returns the stdout from the command execution.
41
+ :return: Standard error
42
+ """
43
+ return self._stdout
44
+
45
+ @property
46
+ def exit_code(self) -> int:
47
+ """
48
+ Returns the exit code from the command execution.
49
+ """
50
+ return self._return_code
51
+
52
+ @property
53
+ def command(self) -> str | list[str]:
54
+ """
55
+ Returns the command line call.
56
+ :return: Command line call
57
+ """
58
+ return self._command
59
+
60
+ @command.setter
61
+ def command(self, cmd: str) -> None:
62
+ """
63
+ Sets the command line call.
64
+ :param cmd: Command
65
+ :return: None
66
+ """
67
+ self._command = cmd
68
+
69
+ def run(
70
+ self,
71
+ folder: Path,
72
+ stderr_handle=subprocess.PIPE,
73
+ disable_logging: bool = False,
74
+ prefix: str | None = None,
75
+ env: dict[str, Any] | None = None,
76
+ ) -> None:
77
+ """
78
+ Runs the command given at command initialization
79
+ :param folder: Folder where the command is executed
80
+ :param stderr_handle: Handle for the standard error (e.g. PIPE or STDOUT)
81
+ :param disable_logging: If True, logging is disabled
82
+ :param prefix: If given, this prefix will be added to the commands
83
+ :param env: Environment variables to be set for the command
84
+ :return: None
85
+ """
86
+ if self.command is None:
87
+ raise ValueError("Invalid command 'None'")
88
+ is_shell = isinstance(self._command, str)
89
+
90
+ # Add the prefix
91
+ command = self._command
92
+ if prefix:
93
+ if is_shell:
94
+ command = f"{prefix}{self._command}"
95
+ else:
96
+ logger.info('Prefix is not supported when providing command as a list')
97
+
98
+ # Log the execution
99
+ if disable_logging is False:
100
+ logger.info(
101
+ f"Executing command: {' '.join(self.command) if isinstance(self.command, list) else self.command}"
102
+ )
103
+
104
+ # Output file
105
+ stdout_handle = self._stdout_path.open('w', encoding='utf-8') if self._stdout_path else subprocess.PIPE
106
+
107
+ try:
108
+ self._procedure = subprocess.run(
109
+ command,
110
+ stdout=stdout_handle,
111
+ stderr=stderr_handle,
112
+ shell=is_shell,
113
+ env={**os.environ, **env} if env is not None else None,
114
+ cwd=folder,
115
+ text=True,
116
+ )
117
+ self._stdout = self._procedure.stdout or ''
118
+ self._stderr = self._procedure.stderr or ''
119
+ self._return_code = self._procedure.returncode
120
+ except FileNotFoundError as err:
121
+ self._stdout = ''
122
+ self._stderr = str(err)
123
+ self._return_code = 1
124
+ finally:
125
+ if stdout_handle is not subprocess.PIPE:
126
+ stdout_handle.close()
127
+ if disable_logging is False:
128
+ logger.debug(f'stdout: {self._stdout}')
129
+ logger.debug(f'stderr: {self._stderr}')
130
+
131
+ def run_command(self, folder: Path, stderr_handle=subprocess.PIPE) -> None:
132
+ """
133
+ Runs the command given at command initialization
134
+ :param folder: Folder where the command is executed
135
+ :param stderr_handle: Handle for the standard error (e.g. PIPE or STDOUT)
136
+ :return: None
137
+ """
138
+ warnings.warn('The run_command method is deprecated, please use the run() method instead.', DeprecationWarning)
139
+ self.run(folder, stderr_handle)
@@ -0,0 +1,23 @@
1
+ class SnakemakeExecutionError(RuntimeError):
2
+ """
3
+ This error is raised when a Snakemake execution error occurs.
4
+ """
5
+
6
+ def __init__(self, stdout: str, stderr: str, failed_rule: str | None = None) -> None:
7
+ """
8
+ This class is raised when a snakemake error occurs.
9
+ :param stdout: Standard output
10
+ :param stderr: Error output
11
+ """
12
+ super().__init__(f"Failed at rule: {failed_rule if failed_rule else 'n/a'}")
13
+ self.stdout = stdout
14
+ self.stderr = stderr
15
+ self.failed_rule = failed_rule
16
+
17
+
18
+ class DependencyError(ValueError):
19
+ """
20
+ Error that is raised when a dependency is not available..
21
+ """
22
+
23
+ pass
File without changes
@@ -0,0 +1,49 @@
1
+ import abc
2
+ from abc import ABCMeta
3
+
4
+
5
+ class ToolIO(metaclass=ABCMeta):
6
+ """
7
+ Class that represents the input or output of a tool.
8
+ """
9
+
10
+ def __init__(self, logged: bool) -> None:
11
+ """
12
+ Initializes a tool input / output.
13
+ :param logged: If true, the output can be logged
14
+ """
15
+ self._logged = logged
16
+
17
+ @property
18
+ def is_logged(self) -> bool:
19
+ """
20
+ Returns True if the output is logged.
21
+ :return: True / False
22
+ """
23
+ return self._logged
24
+
25
+ @abc.abstractmethod
26
+ def is_valid(self) -> bool:
27
+ """
28
+ Checks whether the tool input / output is valid.
29
+ :return: None
30
+ """
31
+ pass
32
+
33
+ @property
34
+ @abc.abstractmethod
35
+ def hash(self) -> str:
36
+ """
37
+ Returns the hash value.
38
+ :return: Hash value
39
+ """
40
+ pass
41
+
42
+ @property
43
+ @abc.abstractmethod
44
+ def type_name(self) -> str:
45
+ """
46
+ Returns the type of the IO object.
47
+ :return: Type value
48
+ """
49
+ pass
@@ -0,0 +1,80 @@
1
+ from pathlib import Path
2
+
3
+ from camelcore.app.utils import fileutils
4
+ from camelcore.app.io.toolio import ToolIO
5
+
6
+
7
+ class ToolIODirectory(ToolIO):
8
+ """
9
+ Class that represents an input / output directory of a tool.
10
+ """
11
+
12
+ def __init__(self, path: Path, logged: bool = True) -> None:
13
+ """
14
+ Initializes a tool input / output directory.
15
+ :param path: Path to the directory
16
+ :param logged: If True, the output can be logged
17
+ """
18
+ super().__init__(logged)
19
+ self._path = path.absolute()
20
+
21
+ def __str__(self) -> str:
22
+ """
23
+ String representation.
24
+ :return: String representation
25
+ """
26
+ return str(self._path)
27
+
28
+ def __repr__(self) -> str:
29
+ """
30
+ Internal representation.
31
+ :return: Internal representation
32
+ """
33
+ return f'ToolIODirectory("{self.path}")'
34
+
35
+ def is_valid(self) -> bool:
36
+ """
37
+ Checks if the tool input / output directory is valid.
38
+ :return: True if valid
39
+ """
40
+ return self.exists
41
+
42
+ @property
43
+ def hash(self) -> str:
44
+ """
45
+ Returns the hash value.
46
+ :return: Hash value
47
+ """
48
+ return fileutils.hash_directory(self.path)
49
+
50
+ @property
51
+ def path(self) -> Path:
52
+ """
53
+ Returns the path to the input / output directory.
54
+ :return: Path
55
+ """
56
+ return self._path
57
+
58
+ @property
59
+ def basename(self) -> str:
60
+ """
61
+ Returns the basename of the input / output directory.
62
+ :return: Basename
63
+ """
64
+ return self.path.name
65
+
66
+ @property
67
+ def exists(self) -> bool:
68
+ """
69
+ Checks whether this directory exists.
70
+ :return: True if the directory exists, False otherwise
71
+ """
72
+ return self._path.is_dir()
73
+
74
+ @property
75
+ def type_name(self) -> str:
76
+ """
77
+ Returns the type of the IO object.
78
+ :return: Type value
79
+ """
80
+ return 'dir'
@@ -0,0 +1,98 @@
1
+ from pathlib import Path
2
+
3
+ import humanize
4
+
5
+ from camelcore.app.utils import fileutils
6
+ from camelcore.app.io.toolio import ToolIO
7
+
8
+
9
+ class ToolIOFile(ToolIO):
10
+ """
11
+ Class that represents an input / output file of a tool.
12
+ """
13
+
14
+ def __init__(self, path: Path, logged: bool = True) -> None:
15
+ """
16
+ Initializes a tool input / output file.
17
+ :param path: Path to the file
18
+ :param logged: If True, the output can be logged
19
+ """
20
+ super().__init__(logged)
21
+ self._path = path.absolute()
22
+
23
+ def __str__(self) -> str:
24
+ """
25
+ String representation.
26
+ :return: String representation
27
+ """
28
+ return str(self._path)
29
+
30
+ def __repr__(self) -> str:
31
+ """
32
+ Internal representation.
33
+ :return: Internal representation
34
+ """
35
+ return f'ToolIOFile("{self.path}", {humanize.naturalsize(self.size)})'
36
+
37
+ def is_valid(self) -> bool:
38
+ """
39
+ Checks if the tool input / output file is valid.
40
+ :return: True if valid
41
+ """
42
+ return self.exists
43
+
44
+ @property
45
+ def path(self) -> Path:
46
+ """
47
+ Returns the path to the input / output file.
48
+ :return: Path
49
+ """
50
+ return self._path
51
+
52
+ @property
53
+ def basename(self) -> str:
54
+ """
55
+ Returns the basename of the input / output file.
56
+ :return: Basename
57
+ """
58
+ return self.path.name
59
+
60
+ @property
61
+ def file_extension(self) -> str:
62
+ """
63
+ Returns the file extension.
64
+ :return: File extension
65
+ """
66
+ return self.path.suffix
67
+
68
+ @property
69
+ def exists(self) -> bool:
70
+ """
71
+ Checks whether this file exists.
72
+ :return: True if the file exists, False otherwise
73
+ """
74
+ return self._path.is_file()
75
+
76
+ @property
77
+ def size(self) -> int:
78
+ """
79
+ Returns the size of this file.
80
+ :return: Size
81
+ """
82
+ return self.path.stat().st_size
83
+
84
+ @property
85
+ def hash(self) -> str:
86
+ """
87
+ Returns the hash value of this file.
88
+ :return: Hash
89
+ """
90
+ return fileutils.hash_file(self.path)
91
+
92
+ @property
93
+ def type_name(self) -> str:
94
+ """
95
+ Returns the type of the IO object.
96
+ :return: Type value
97
+ """
98
+ return 'file'
@@ -0,0 +1,64 @@
1
+ from typing import Any
2
+
3
+ from camelcore.app.utils import fileutils
4
+ from camelcore.app.io.toolio import ToolIO
5
+
6
+
7
+ class ToolIOValue(ToolIO):
8
+ """
9
+ Class that represents an input / output value of a tool.
10
+ """
11
+
12
+ def __init__(self, value: Any, logged: bool = True) -> None:
13
+ """
14
+ Initializes a tool input / output value.
15
+ :param value: Value
16
+ :param logged: If True, the output can be logged
17
+ """
18
+ super().__init__(logged)
19
+ self._value = value
20
+
21
+ @property
22
+ def value(self) -> Any:
23
+ """
24
+ Returns the value.
25
+ :return: Value
26
+ """
27
+ return self._value
28
+
29
+ @property
30
+ def hash(self) -> str:
31
+ """
32
+ Returns the hash value.
33
+ :return: Hash value
34
+ """
35
+ return fileutils.hash_value(self.value)
36
+
37
+ @property
38
+ def type_name(self) -> str:
39
+ """
40
+ Returns the type of the IO object.
41
+ :return: Type value
42
+ """
43
+ return 'value'
44
+
45
+ def __str__(self) -> str:
46
+ """
47
+ String representation.
48
+ :return: String representation
49
+ """
50
+ return str(self.value)
51
+
52
+ def __repr__(self) -> str:
53
+ """
54
+ Internal representation.
55
+ :return: Internal representation representation
56
+ """
57
+ return f'ToolIOValue({repr(self.value)})'
58
+
59
+ def is_valid(self) -> bool:
60
+ """
61
+ Checks if the tool input / output value is valid.
62
+ :return: True if valid
63
+ """
64
+ return False if self._value is None else True
@@ -0,0 +1,21 @@
1
+ import logging
2
+
3
+ logger = logging.getLogger('camel')
4
+ DEFAULT_FMT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
5
+
6
+
7
+ def initialize_logging() -> None:
8
+ """
9
+ Initializes the logging.
10
+ :return: None
11
+ """
12
+ if logger.hasHandlers():
13
+ return
14
+
15
+ # General logging level
16
+ logger.setLevel(logging.DEBUG)
17
+ logger.propagate = False
18
+ logger.addHandler(logging.NullHandler())
19
+
20
+
21
+ initialize_logging()