prepare-toolbox 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 prepare-assignment
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.1
2
+ Name: prepare-toolbox
3
+ Version: 0.1.0
4
+ Summary: Toolbox containing helper functions for prepare-assignment actions
5
+ License: MIT
6
+ Author: Bonajo
7
+ Author-email: m.bonajo@fontys.nl
8
+ Requires-Python: >=3.8,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Requires-Dist: braceexpand (>=0.1.7,<0.2.0)
16
+ Description-Content-Type: text/markdown
17
+
18
+ # toolbox
@@ -0,0 +1 @@
1
+ # toolbox
File without changes
@@ -0,0 +1,16 @@
1
+ import json
2
+ import os
3
+ from typing import Any
4
+
5
+
6
+ def get_input(key: str) -> Any:
7
+ """
8
+ Get input passed to the action
9
+ :param key: The key of the input
10
+ :return: value of the key if present, None otherwise
11
+ """
12
+ sanitized = key.replace(" ", "_").upper()
13
+ value = os.environ.get(f"PREPARE_{sanitized}")
14
+ if value is not None:
15
+ return json.loads(value)
16
+ return None
@@ -0,0 +1,51 @@
1
+ import glob
2
+ import os
3
+ import sys
4
+ from pathlib import Path
5
+ from typing import Union, List, Iterable, Set, Iterator
6
+
7
+ from braceexpand import braceexpand
8
+
9
+
10
+ def __expand(path: str) -> Iterator[str]:
11
+ if sys.platform == "win32":
12
+ return braceexpand(path, escape=False)
13
+ return braceexpand(path)
14
+
15
+
16
+ def __get_matching_files(globs: Union[str, List[str]], relative_to: Union[str, Path, None] = None,
17
+ recursive: bool = True) -> Set[str]:
18
+ if globs is None:
19
+ raise ValueError("Cannot find matching files without included glob")
20
+ if not isinstance(globs, list):
21
+ globs = [globs]
22
+ matched: Set[str] = set()
23
+ if relative_to is not None:
24
+ relative_to = Path(os.path.join(os.getcwd(), relative_to))
25
+ else:
26
+ relative_to = Path(os.getcwd())
27
+ for g in globs:
28
+ path = os.path.join(relative_to, g)
29
+ for expanded in __expand(path):
30
+ for file in glob.glob(expanded, recursive=recursive):
31
+ relative = Path(file).relative_to(relative_to)
32
+ matched.add(str(relative))
33
+ return matched
34
+
35
+
36
+ def get_matching_files(included: Union[str, List[str]], excluded: Union[str, List[str], None] = None,
37
+ relative_to: Union[str, Path, None] = None, recursive: bool = True) -> List[str]:
38
+ """
39
+ Get files matching the included glob and not matching the excluded glob.
40
+ :param included: Glob(s) that should be matched
41
+ :param excluded: Glob(s) that should not be matched
42
+ :param relative_to: Set relative path, the globs are matched relative to this path, defaults to pwd
43
+ :param recursive: Whether the glob should recurse directories
44
+ :return List[str]: List of matched files (as posix strings)
45
+ :raises ValueError: If any of the matched files is outside the relative_to directory (or its children)
46
+ """
47
+ matched_included = __get_matching_files(included, relative_to=relative_to, recursive=recursive)
48
+ if excluded is not None:
49
+ matched_excluded = __get_matching_files(excluded, relative_to=relative_to, recursive=recursive)
50
+ matched_included -= matched_excluded
51
+ return sorted(list(matched_included))
@@ -0,0 +1,23 @@
1
+ import os.path
2
+ from typing import List, Optional
3
+ from zipfile import ZipFile
4
+
5
+
6
+ def create_zip(name: str, files: List[str], output: Optional[str] = None) -> None:
7
+ """
8
+ Create a zip file with a name and the given files.
9
+ Optionally give an output path where the file should be written
10
+ :param name: Name of the archive
11
+ :param files: Files that should be added to the archive
12
+ :param output: output directory
13
+ :return: None
14
+ """
15
+ file = name
16
+ n, extension = os.path.splitext(name)
17
+ if extension is None or extension != ".zip":
18
+ file += ".zip"
19
+ if output:
20
+ file = os.path.join(output, file)
21
+ with ZipFile(file, 'w') as handle:
22
+ for f in files:
23
+ handle.write(f)
@@ -0,0 +1,22 @@
1
+ [tool.poetry]
2
+ name = "prepare-toolbox"
3
+ version = "0.1.0"
4
+ description = "Toolbox containing helper functions for prepare-assignment actions"
5
+ authors = ["Bonajo <m.bonajo@fontys.nl>"]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+ packages = [{include = "prepare_toolbox"}]
9
+
10
+ [tool.poetry.dependencies]
11
+ python = "^3.8"
12
+ braceexpand = "^0.1.7"
13
+
14
+
15
+ [tool.poetry.group.test.dependencies]
16
+ pytest = "^7.4.0"
17
+ mypy = "^1.4.1"
18
+ pytest-cov = "^4.1.0"
19
+
20
+ [build-system]
21
+ requires = ["poetry-core"]
22
+ build-backend = "poetry.core.masonry.api"