|
1 | 1 | import importlib |
2 | 2 | import os |
3 | 3 | import random |
| 4 | +import re |
4 | 5 | import sys |
5 | 6 | from datetime import timedelta |
6 | 7 | from importlib.abc import Loader |
7 | 8 | from pathlib import Path |
8 | 9 | from typing import List, NamedTuple, Set, Union |
9 | 10 |
|
10 | 11 | import click |
| 12 | +from click.exceptions import BadParameter |
11 | 13 |
|
12 | 14 | from feast import Entity, FeatureTable |
13 | 15 | from feast.feature_view import FeatureView |
@@ -112,6 +114,12 @@ def apply_total(repo_config: RepoConfig, repo_path: Path): |
112 | 114 | sys.path.append("") |
113 | 115 | registry_config = repo_config.get_registry_config() |
114 | 116 | project = repo_config.project |
| 117 | + if not_valid_name(project): |
| 118 | + print( |
| 119 | + f"{project} is not valid. Project name should only have " |
| 120 | + f"alphanumerical values and underscores." |
| 121 | + ) |
| 122 | + sys.exit(1) |
115 | 123 | registry = Registry( |
116 | 124 | registry_path=registry_config.path, |
117 | 125 | repo_path=repo_path, |
@@ -267,6 +275,11 @@ def init_repo(repo_name: str, template: str): |
267 | 275 |
|
268 | 276 | from colorama import Fore, Style |
269 | 277 |
|
| 278 | + if not_valid_name(repo_name): |
| 279 | + raise BadParameter( |
| 280 | + message="Name should be alphanumeric values and underscores", |
| 281 | + param_hint="PROJECT_DIRECTORY", |
| 282 | + ) |
270 | 283 | repo_path = Path(os.path.join(Path.cwd(), repo_name)) |
271 | 284 | repo_path.mkdir(exist_ok=True) |
272 | 285 | repo_config_path = repo_path / "feature_store.yaml" |
@@ -319,6 +332,11 @@ def init_repo(repo_name: str, template: str): |
319 | 332 | click.echo() |
320 | 333 |
|
321 | 334 |
|
| 335 | +def not_valid_name(name: str) -> bool: |
| 336 | + """Test project or repo names. True if names have characters other than alphanumeric values and underscores""" |
| 337 | + return re.compile(r"\W+").search(name) is not None |
| 338 | + |
| 339 | + |
322 | 340 | def replace_str_in_file(file_path, match_str, sub_str): |
323 | 341 | with open(file_path, "r") as f: |
324 | 342 | contents = f.read() |
|
0 commit comments