Skip to content

Commit

Permalink
update exceptions (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda committed Jul 20, 2023
1 parent d30ef2f commit 2c7b4d0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,5 @@ lightning_logs
*.gz
.DS_Store
.*_submit.py

.ruff_cache/
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ repos:
- id: yesqa
additional_dependencies:
- pep8-naming
- flake8-pytest-style
- flake8-bandit
- flake8-builtins
- flake8-bugbear

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
Expand Down
24 changes: 14 additions & 10 deletions _actions/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def list_runtimes(pr: Optional[int] = None, auth_token: Optional[str] = None) ->
def _load_config(config_file: str = "config.yaml", strict: bool = True) -> dict:
if not os.path.isfile(config_file):
config_file = os.path.join("configs", config_file)
assert _file_exits(config_file), f"Missing config file: {config_file}"
if not _file_exits(config_file):
raise FileNotFoundError(f"Missing config file: {config_file}")
with open(_file_exits(config_file)) as fp:
config = yaml.safe_load(fp)
if strict:
Expand Down Expand Up @@ -164,7 +165,8 @@ def _install_pip(repo: Dict[str, str]) -> str:
Args:
repo: it is package or repository with additional key fields
"""
assert any(k in repo for k in ["HTTPS", "name"]), f"Missing key `HTTPS` or `name` among {repo.keys()}"
if not any(k in repo for k in ["HTTPS", "name"]):
raise ValueError(f"Missing key `HTTPS` or `name` among {repo.keys()}")
# pip install -q 'https://github.com/...#egg=lightning-flash[tabular]
name = repo.get("name")
if not name:
Expand All @@ -181,7 +183,7 @@ def _install_pip(repo: Dict[str, str]) -> str:

pkg = f"git+{url}"
if "checkout" in repo:
assert isinstance(repo["checkout"], str)
assert isinstance(repo["checkout"], str) # noqa: S101
pkg += f"@{repo['checkout']}"
if "install_extras" in repo:
pkg += f"#egg={name}[{AssistantCLI._extras(repo['install_extras'])}]"
Expand All @@ -198,15 +200,16 @@ def _install_pip(repo: Dict[str, str]) -> str:
@staticmethod
def _install_repo(repo: Dict[str, str], remove_dir: bool = True) -> List[str]:
"""Create command for installing a project from source assuming it is Git project."""
assert "HTTPS" in repo, f"Missing key `HTTPS` among {repo.keys()}"
if "HTTPS" not in repo:
raise ValueError(f"Missing key `HTTPS` among {repo.keys()}")
url = AssistantCLI._https(
repo.get("HTTPS"), token=repo.get("token"), username=repo.get("username"), password=repo.get("password")
)
cmd_git = f"git clone {url}"
repo_name, _ = os.path.splitext(os.path.basename(repo.get("HTTPS")))
cmds = [cmd_git, f"cd {repo_name}"]
if "checkout" in repo:
assert isinstance(repo["checkout"], str)
assert isinstance(repo["checkout"], str) # noqa: S101
cmds.append(f"git checkout {repo['checkout']}")

if "requirements_file" in repo:
Expand All @@ -220,7 +223,7 @@ def _install_repo(repo: Dict[str, str], remove_dir: bool = True) -> List[str]:
pip_install += f"[{AssistantCLI._extras(repo['install_extras'])}]"

flags = AssistantCLI._get_flags(repo)
cmds.append("pip install " + " ".join([pip_install] + flags))
cmds.append("pip install " + " ".join([pip_install, *flags]))
cmds.append("pip list")
cmds.append("cd ..")

Expand Down Expand Up @@ -302,8 +305,7 @@ def prepare_env(config_file: str = "config.yaml", path_root: str = _PATH_ROOT) -
script.append(f'rm -rf "{repo_name}"')

reqs = config.get("dependencies", [])
for req in reqs:
script.append(AssistantCLI._install_pip(req))
script += [AssistantCLI._install_pip(req) for req in reqs]
script.append("pip list")

script += AssistantCLI.before_commands(config_file, stage="test", as_append=True)
Expand Down Expand Up @@ -334,8 +336,10 @@ def slack_payload(fpath_results: str = "projects.json", dpath_configs: str = "co
Debugging in: https://app.slack.com/block-kit-builder
"""
assert os.path.isfile(fpath_results), f"missing results data / JSON: {fpath_results}"
assert os.path.isdir(dpath_configs), f"missing config folder: {dpath_configs}"
if not os.path.isfile(fpath_results):
raise FileNotFoundError(f"missing results data / JSON: {fpath_results}")
if not os.path.isdir(dpath_configs):
raise NotADirectoryError(f"missing config folder: {dpath_configs}")

with open(fpath_results) as fp:
data = json.load(fp)
Expand Down
2 changes: 1 addition & 1 deletion _actions/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
"specify_tests",
],
)
def test_assistant_commands(cmd):
def test_assistant_commands(cmd: str) -> None:
AssistantCLI().__getattribute__(cmd)(_PATH_CONFIG)
18 changes: 15 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,30 @@ line-length = 120
select = [
"E", "W", # see: https://pypi.org/project/pycodestyle
"F", # see: https://pypi.org/project/pyflakes
"I", #see: https://pypi.org/project/isort/
"D", # see: https://pypi.org/project/pydocstyle
"N", # see: https://pypi.org/project/pep8-naming
"S", # see: https://pypi.org/project/flake8-bandit
]
extend-select = [
"A", # see: https://pypi.org/project/flake8-builtins
"B", # see: https://pypi.org/project/flake8-bugbear
"C4", # see: https://pypi.org/project/flake8-comprehensions
"PT", # see: https://pypi.org/project/flake8-pytest-style
"RET", # see: https://pypi.org/project/flake8-return
"SIM", # see: https://pypi.org/project/flake8-simplify
"YTT", # see: https://pypi.org/project/flake8-2020
"ANN", # see: https://pypi.org/project/flake8-annotations
"TID", # see: https://pypi.org/project/flake8-tidy-imports/
"T10", # see: https://pypi.org/project/flake8-debugger
"Q", # see: https://pypi.org/project/flake8-quotes
"EXE", # see: https://pypi.org/project/flake8-executable
"ISC", # see: https://pypi.org/project/flake8-implicit-str-concat
"PIE", # see: https://pypi.org/project/flake8-pie
"PLE", # see: https://pypi.org/project/pylint/
"PERF", # see: https://pypi.org/project/perflint/
"PYI", # see: https://pypi.org/project/flake8-pyi/
]
#ignore = [
# "E731", # Do not assign a lambda expression, use a def
#]
# Exclude a variety of commonly ignored directories.
exclude = [
".eggs",
Expand Down

0 comments on commit 2c7b4d0

Please sign in to comment.