diff --git a/.gitignore b/.gitignore index 12ee45f..2e17516 100644 --- a/.gitignore +++ b/.gitignore @@ -135,5 +135,4 @@ dmypy.json .pyre/ .activate.sh .DS_Store -.MyAppTest - +.MyAppTest/ \ No newline at end of file diff --git a/activate.sh b/activate.sh new file mode 100755 index 0000000..06fb501 --- /dev/null +++ b/activate.sh @@ -0,0 +1,50 @@ + +#!/bin/bash +set -e + +# Get the directory of the current script +script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +# Change to that directory +cd "$script_dir" + +# Confirm the current directory +echo "Changed directory to: $(pwd)" +echo "activate.sh change working directory to $(pwd)" + + +if [ "$IN_ACTIVATED_ENV" = "1" ]; then + IN_ACTIVATED_ENV=1 +else + IN_ACTIVATED_ENV=0 +fi + +# If the 'venv' directory doesn't exist, print a message and exit. +if [ ! -d "venv" ]; then + cwd=$(pwd) + echo "The 'venv' directory in $cwd does not exist, creating..." + echo "OSTYPE: $OSTYPE" + case "$OSTYPE" in + darwin*|linux-gnu*) + python3 ./install.py + ;; + *) + python ./install.py + ;; + esac + + . ./venv/bin/activate + export IN_ACTIVATED_ENV=1 + this_dir=$(pwd) + export PATH="$this_dir:$PATH" + echo "Environment created." + pip install -e . + exit 0 +fi + +if [[ "$IN_ACTIVATED_ENV" != "1" ]]; then + . ./venv/bin/activate + export IN_ACTIVATED_ENV=1 + this_dir=$(pwd) + export PATH="$this_dir:$PATH" +fi diff --git a/src/create_python_cmd/createapp.py b/src/create_python_cmd/createapp.py index 3dd6311..6ca2e99 100644 --- a/src/create_python_cmd/createapp.py +++ b/src/create_python_cmd/createapp.py @@ -17,9 +17,7 @@ def check_name(app_name: str) -> None: """Check the name of the application.""" if not app_name.isidentifier(): - raise ValueError( - "The name of the application is not a valid Python identifier." - ) + raise ValueError("The name of the application is not a valid Python identifier.") def check_semantic_version(version: str) -> None: @@ -27,9 +25,7 @@ def check_semantic_version(version: str) -> None: version_list = version.split(".") for v in version_list: if not v.isnumeric(): - raise ValueError( - "The version of the application is not a valid semantic version." - ) + raise ValueError("The version of the application is not a valid semantic version.") def remove_double_blank_lines(lines: list) -> list: @@ -49,6 +45,7 @@ def remove_double_blank_lines(lines: list) -> list: def do_create_python_app( + app_name: str, app_description: str, app_author: str, app_keywords: str, # Example "keyword1, keyword2, keyword3" @@ -61,7 +58,6 @@ def do_create_python_app( # get app name from the github url cwd = cwd or os.getcwd() os.makedirs(cwd, exist_ok=True) - app_name = github_url.split("/")[-1] app_name_underscore = app_name.replace("-", "_") with tempfile.TemporaryDirectory() as tmpdir: # download https://github.com/zackees/template-python-cmd @@ -72,9 +68,7 @@ def do_create_python_app( for root, dirs, files in os.walk(tmpdir): for d in dirs: if d == "template-python-cmd" or d == "template_python_cmd": - shutil.move( - os.path.join(root, d), os.path.join(root, app_name_underscore) - ) + shutil.move(os.path.join(root, d), os.path.join(root, app_name_underscore)) pyproject = os.path.join(tmpdir, "pyproject.toml") with open(pyproject, encoding="utf-8", mode="r") as pyproject_file: pyproject_lines = pyproject_file.read().splitlines() @@ -94,9 +88,7 @@ def do_create_python_app( pyproject_lines[i] = "" else: if line.startswith("test_cmd ="): - pyproject_lines[ - i - ] = f'{command_name} = "{app_name_underscore}.cli:main"' + pyproject_lines[i] = f'{command_name} = "{app_name_underscore}.cli:main"' ######## # Transform pyproject file with the new information pyproject_lines = remove_double_blank_lines(pyproject_lines) @@ -154,6 +146,7 @@ def create_python_app() -> None: # check if git exists if not shutil.which("git"): raise RuntimeError("Git is not installed.") + app_name: str while True: try: app_name = input("Python app name: ").replace("-", "_") @@ -190,6 +183,7 @@ def create_python_app() -> None: print(f"Error: {e}, try again") continue do_create_python_app( + app_name=app_name, app_description=app_description, app_author=app_author, app_keywords=app_keywords, diff --git a/test b/test new file mode 100755 index 0000000..4d584b5 --- /dev/null +++ b/test @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +pytest tests \ No newline at end of file diff --git a/tests/test_createapp.py b/tests/test_createapp.py index 441e9c8..3df0817 100644 --- a/tests/test_createapp.py +++ b/tests/test_createapp.py @@ -27,6 +27,7 @@ def test_imports(self) -> None: if os.path.exists(outdir): shutil.rmtree(outdir) do_create_python_app( + "my-app", app_description="MyAppTest description", app_author="Firstname Lastname", app_keywords="myapp test",