diff --git a/chasten/configuration.py b/chasten/configuration.py index 8a93569a..294fc612 100644 --- a/chasten/configuration.py +++ b/chasten/configuration.py @@ -7,14 +7,20 @@ from typing import Any, Dict, List, Tuple, Union from pathlib import Path from purl import URL -import yaml -import requests import platformdirs from rich.logging import RichHandler from rich.traceback import install +import yaml +import requests -from chasten import constants, validate, util, output +from chasten import ( + constants, + filesystem, + output, + util, + validate, +) def configure_tracebacks() -> None: @@ -104,7 +110,7 @@ def display_configuration_directory( def validate_configuration_files( - config: Union[Path, URL], + config: str, verbose: bool = False, ) -> Tuple[ bool, Union[Dict[str, List[Dict[str, Union[str, Dict[str, int]]]]], Dict[Any, Any]] @@ -118,12 +124,12 @@ def validate_configuration_files( # be used instead of the platform-specific directory # input configuration is valid URL - if (util.is_url(str(config))): + if util.is_url(config): # re-parse input config so it is of type URL config = URL(str(config)) chasten_user_config_url_str = str(config) # input configuration is valid file path - elif (Path(str(config)).exists()): + elif Path(config).exists(): # re-parse input config so it is of type Path config = Path(str(config)) chasten_user_config_dir_str = str(config) @@ -290,11 +296,11 @@ def extract_configuration_details_from_config_dir( return (False, None, None, None) # type: ignore configuration_file_yaml_str = configuration_file_path.read_text() # load the contents of the main configuration file - with open(configuration_file_path_str) as user_configuration_file_text: + with open(str(configuration_file_path)) as user_configuration_file_text: (yaml_success, yaml_data) = convert_configuration_text_to_yaml(user_configuration_file_text) # return success status, filename, file contents, and yaml parsed data upon success if yaml_success: - return (True, configuration_file_path_str, configuration_file_yaml_str, yaml_data) + return (True, str(configuration_file_path), configuration_file_yaml_str, yaml_data) # return none types upon failure in yaml parsing else: return (False, None, None, None) # type: ignore diff --git a/chasten/main.py b/chasten/main.py index 354936c1..3ca0661b 100644 --- a/chasten/main.py +++ b/chasten/main.py @@ -121,7 +121,7 @@ def configure( # noqa: PLR0913 None, "--config", "-c", - help="A directory or URL with configuration file(s).", + help="A directory with configuration file(s) or URL to configuration file.", ), debug_level: debug.DebugLevel = typer.Option( debug.DebugLevel.ERROR.value, @@ -242,7 +242,7 @@ def analyze( # noqa: PLR0913, PLR0915 None, "--config", "-c", - help="A directory with configuration file(s).", + help="A directory with configuration file(s) or URL to configuration file.", ), debug_level: debug.DebugLevel = typer.Option( debug.DebugLevel.ERROR.value, diff --git a/chasten/util.py b/chasten/util.py index 7d0aff44..f73c6619 100644 --- a/chasten/util.py +++ b/chasten/util.py @@ -54,6 +54,7 @@ def is_url(url: str) -> bool: # parse input url url_parsed = URL(url) # only input characters for initiatig query and/or fragments if necessary + port_character = ":" if (url_parsed.port() is not None) else "" query_character = "?" if url_parsed.query() else "" fragment_character = "#" if url_parsed.fragment() else "" # piece the url back together to make sure it matches what was input @@ -62,6 +63,8 @@ def is_url(url: str) -> bool: url_parsed.scheme(), "://", url_parsed.netloc(), + port_character, + str((url_parsed.port() is not None) or ""), # to handle if port() is `None` type url_parsed.path(), query_character, url_parsed.query(),