Skip to content

Commit 4fdebcd

Browse files
authored
Repo and project names should not start with an underscore (#1597)
* repo and project name should not start with an underscore Signed-off-by: ted chang <htchang@us.ibm.com> * Test invalid project name Signed-off-by: ted chang <htchang@us.ibm.com>
1 parent 17231d0 commit 4fdebcd

2 files changed

Lines changed: 48 additions & 7 deletions

File tree

‎sdk/python/feast/repo_operations.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ def apply_total(repo_config: RepoConfig, repo_path: Path):
115115
os.chdir(repo_path)
116116
registry_config = repo_config.get_registry_config()
117117
project = repo_config.project
118-
if not_valid_name(project):
118+
if not is_valid_name(project):
119119
print(
120120
f"{project} is not valid. Project name should only have "
121-
f"alphanumerical values and underscores."
121+
f"alphanumerical values and underscores but not start with an underscore."
122122
)
123123
sys.exit(1)
124124
registry = Registry(
@@ -292,9 +292,9 @@ def init_repo(repo_name: str, template: str):
292292

293293
from colorama import Fore, Style
294294

295-
if not_valid_name(repo_name):
295+
if not is_valid_name(repo_name):
296296
raise BadParameter(
297-
message="Name should be alphanumeric values and underscores",
297+
message="Name should be alphanumeric values and underscores but not start with an underscore",
298298
param_hint="PROJECT_DIRECTORY",
299299
)
300300
repo_path = Path(os.path.join(Path.cwd(), repo_name))
@@ -349,9 +349,9 @@ def init_repo(repo_name: str, template: str):
349349
click.echo()
350350

351351

352-
def not_valid_name(name: str) -> bool:
353-
"""Test project or repo names. True if names have characters other than alphanumeric values and underscores"""
354-
return re.compile(r"\W+").search(name) is not None
352+
def is_valid_name(name: str) -> bool:
353+
"""A name should be alphanumeric values and underscores but not start with an underscore"""
354+
return not name.startswith("_") and re.compile(r"\W+").search(name) is None
355355

356356

357357
def replace_str_in_file(file_path, match_str, sub_str):

‎sdk/python/tests/test_init.py‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import tempfile
22
from datetime import datetime, timedelta
33
from pathlib import Path
4+
from textwrap import dedent
45

56
from tests.cli_utils import CliRunner
67

@@ -25,3 +26,43 @@ def test_repo_init() -> None:
2526
["materialize", start_date.isoformat(), end_date.isoformat()], cwd=repo_path
2627
)
2728
assert result.returncode == 0
29+
30+
31+
def test_repo_init_with_underscore_in_project_name() -> None:
32+
"""
33+
Test `feast init` with underscore in the project name
34+
"""
35+
with tempfile.TemporaryDirectory() as temp_dir:
36+
temp_path = Path(temp_dir)
37+
runner = CliRunner()
38+
39+
# `feast init` should fail with repo names start with underscore
40+
invalid_repo_names = ["_test", "_test_1"]
41+
for repo_name in invalid_repo_names:
42+
result = runner.run(["init", repo_name], cwd=temp_path)
43+
assert result.returncode != 0
44+
45+
# `feast init` should succeed with underscore in repo name
46+
valid_repo_names = ["test_1"]
47+
for repo_name in valid_repo_names:
48+
result = runner.run(["init", repo_name], cwd=temp_path)
49+
assert result.returncode == 0
50+
51+
# `feast apply` should fail with underscore in project name
52+
project_name = "test_1"
53+
repo_dir = temp_path / project_name
54+
data_dir = repo_dir / "data"
55+
repo_config = repo_dir / "feature_store.yaml"
56+
repo_config.write_text(
57+
dedent(
58+
f"""
59+
project: __foo
60+
registry: {data_dir / "registry.db"}
61+
provider: local
62+
online_store:
63+
path: {data_dir / "online_store.db"}
64+
"""
65+
)
66+
)
67+
result = runner.run(["apply"], cwd=repo_dir)
68+
assert result.returncode != 0

0 commit comments

Comments
 (0)