Skip to content

Commit

Permalink
fix: Fix the default slug used for the package name (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijeetSaroha authored Mar 29, 2024
1 parent 96a3373 commit 9c53ee3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/scicookie/profiles/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ package_slug:
message: Type the code name for your package (the name used to import your package)
help: https://osl-incubator.github.io/scicookie/guide/#information-about-the-project
type: text
default: "{{project_slug.replace('-', '_')}}"
default: "{{project_slug.replace('-', '_') | sanitize_package_slug}} "
visible: true

project_version:
Expand Down
18 changes: 16 additions & 2 deletions src/scicookie/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from __future__ import annotations

import os
import re

from typing import Any, Optional, Type

import inquirer

from colorama import Fore, Style, init
from jinja2 import Template
from jinja2 import Environment

from scicookie.logs import SciCookieErrorType, SciCookieLogs

Expand Down Expand Up @@ -76,6 +77,13 @@ def check_dependencies_satisfied(
return True


def sanitize_package_slug(package_slug: str) -> str:
"""Filter to sanitize the package slug."""
return re.sub(
r"^\s+|\s+$", "", re.sub(r"[^a-zA-Z0-9_]+", "", package_slug)
)


def make_questions(questions: dict[str, Any]) -> dict[str, str]:
"""Generate all the visible questions."""
answers: dict[str, str] = {}
Expand All @@ -96,11 +104,17 @@ def make_questions(questions: dict[str, Any]) -> dict[str, str]:
)
print("." * columns)

# Create a Jinja2 environment and add the custom filter
env = Environment()
env.filters["sanitize_package_slug"] = sanitize_package_slug

for question_id, question in questions.items():
question_obj = _create_question(question_id, question)

default_answer = question.get("default", "")
default_answer = Template(default_answer).render(answers)
default_answer = (
env.from_string(default_answer).render(answers).strip()
)

# note: if question_object is None, that means that the question is
# not visible
Expand Down

0 comments on commit 9c53ee3

Please sign in to comment.