Skip to content

Commit

Permalink
Make release transpiler argument types more strict
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-eq committed Aug 14, 2023
1 parent 3fb834a commit 710cdd5
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions komodo/release_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,25 +205,36 @@ def main():
matrix_parser.add_argument(
"--release-folder",
required=True,
type=Path,
type=dir_path,
help="Folder with existing release file (default: None)",
)
matrix_parser.add_argument(
"--override-mapping",
required=True,
type=open,
type=check_if_valid_file,
help="File containing explicit matrix packages (default: None)",
)

def checkValidPythonVersion(input: str) -> list:
output_list = []
for item in input.split(','):
if (re.match(r"^[2,3](\.\d+)?$", item) == None):
raise TypeError(item)
else:
output_list.append(item)
return output_list
matrix_parser.add_argument(
"--py_coords",
help="""Comma delimitated list of python versions to be combined,
for example, "3.6,3.8" (without spaces).
If None, the release files in release-folder will be used to imply
the versions to combine.""",
type=lambda s: re.split(",", s),
type=checkValidPythonVersion, #lambda s: [x for x in s.split(',') if (re.match(r"^[2,3](\.\d+)?$", x) != None)], #re.split(",", s),
required=False,
default=None,
)



transpile_parser = subparsers.add_parser(
"transpile",
Expand All @@ -234,13 +245,13 @@ def main():
transpile_parser.add_argument(
"--matrix-file",
required=True,
type=open,
type=check_if_valid_file,
help="Yaml file describing the release matrix",
)
transpile_parser.add_argument(
"--output-folder",
required=True,
type=Path,
type=dir_path,
help="Folder to output new release files",
)
transpile_parser.add_argument(
Expand All @@ -254,5 +265,17 @@ def main():
args.func(args)


def check_if_valid_file(path: str) -> str:
if (os.path.isfile(path)):
return path
raise TypeError(path)


def dir_path(should_be_valid_path: str) -> str:
if os.path.isdir(should_be_valid_path):
return should_be_valid_path
raise TypeError(should_be_valid_path)


if __name__ == "__main__":
main()

0 comments on commit 710cdd5

Please sign in to comment.