From d49a166605b9a5b862c140f1d563e9a215a15b1e Mon Sep 17 00:00:00 2001 From: Alejandra Date: Fri, 2 Jan 2026 16:03:36 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=90=9B=20Handle=20project=20name=20in?= =?UTF-8?q?itialization=20for=20current=20dir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fastapi_new/new.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fastapi_new/new.py b/src/fastapi_new/new.py index 7ac32ac..a562bf8 100644 --- a/src/fastapi_new/new.py +++ b/src/fastapi_new/new.py @@ -162,6 +162,9 @@ def new( ), ] = None, ) -> None: + if project_name == ".": + project_name = None + if project_name: name = project_name path = pathlib.Path.cwd() / project_name From e0e2962890087f65c2bf0776b40a19d704c2696c Mon Sep 17 00:00:00 2001 From: Alejandra Date: Fri, 2 Jan 2026 16:07:16 +0100 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9C=85=20Add=20test=20for=20initializing?= =?UTF-8?q?=20project=20in=20current=20dir=20with=20dot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_new.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_new.py b/tests/test_new.py index 5103b70..d77bf17 100644 --- a/tests/test_new.py +++ b/tests/test_new.py @@ -79,6 +79,18 @@ def test_initializes_in_current_directory(temp_project_dir: Path) -> None: _assert_project_created(temp_project_dir) +def test_initializes_in_current_directory_with_dot(temp_project_dir: Path) -> None: + result = runner.invoke(app, ["."]) + + assert result.exit_code == 0 + assert "No project name provided" in result.output + assert "Initializing in current directory" in result.output + _assert_project_created(temp_project_dir) + + readme_content = (temp_project_dir / "README.md").read_text() + assert f"# {temp_project_dir.name}" in readme_content + + def test_rejects_existing_directory(temp_project_dir: Path) -> None: existing_dir = temp_project_dir / "existing_project" existing_dir.mkdir() From d51f6661bd50762a405a464e571f634b4d07fbb3 Mon Sep 17 00:00:00 2001 From: Alejandra Date: Fri, 2 Jan 2026 17:40:00 +0100 Subject: [PATCH 3/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20project=20n?= =?UTF-8?q?ame=20handling=20in=20new=20project=20initialization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fastapi_new/new.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/fastapi_new/new.py b/src/fastapi_new/new.py index a562bf8..dbfc3cb 100644 --- a/src/fastapi_new/new.py +++ b/src/fastapi_new/new.py @@ -147,10 +147,10 @@ def _write_template_files(toolkit: RichToolkit, config: ProjectConfig) -> None: def new( ctx: typer.Context, - project_name: Annotated[ + project: Annotated[ str | None, typer.Argument( - help="The name of the new FastAPI project. If not provided, initializes in the current directory.", + help="The name/path of the new FastAPI project. If not provided, initializes in the current directory.", ), ] = None, python: Annotated[ @@ -162,18 +162,18 @@ def new( ), ] = None, ) -> None: - if project_name == ".": - project_name = None - - if project_name: - name = project_name - path = pathlib.Path.cwd() / project_name + if project: + path = (pathlib.Path.cwd() / project).resolve() else: - name = pathlib.Path.cwd().name path = pathlib.Path.cwd() + project_name = None + + if path != pathlib.Path.cwd(): + project_name = project + config = ProjectConfig( - name=name, + name=path.name, path=path, python=python, ) From f73828ccc462ab03d89a283f232c2f24ac7ade37 Mon Sep 17 00:00:00 2001 From: Alejandra Date: Fri, 2 Jan 2026 18:56:36 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Simplify=20project=20i?= =?UTF-8?q?nitialization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fastapi_new/new.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/fastapi_new/new.py b/src/fastapi_new/new.py index dbfc3cb..e7a3776 100644 --- a/src/fastapi_new/new.py +++ b/src/fastapi_new/new.py @@ -107,7 +107,7 @@ def _setup(toolkit: RichToolkit, config: ProjectConfig) -> None: if config.path == pathlib.Path.cwd(): init_cmd = ["uv", "init", "--bare"] else: - init_cmd = ["uv", "init", "--bare", config.name] + init_cmd = ["uv", "init", "--bare", str(config.path)] if config.python: init_cmd.extend(["--python", config.python]) @@ -167,10 +167,7 @@ def new( else: path = pathlib.Path.cwd() - project_name = None - - if path != pathlib.Path.cwd(): - project_name = project + current_dir = path == pathlib.Path.cwd() config = ProjectConfig( name=path.name, @@ -183,16 +180,16 @@ def new( toolkit.print_line() - if not project_name: + if current_dir: toolkit.print( - f"[yellow]⚠️ No project name provided. Initializing in current directory: {path}[/yellow]", + f"[yellow]⚠️ Initializing in current directory: {config.path}[/yellow]", tag="warning", ) toolkit.print_line() # Check if project directory already exists (only for new subdirectory) - if project_name and config.path.exists(): - _exit_with_error(toolkit, f"Directory '{project_name}' already exists.") + if not current_dir and config.path.exists(): + _exit_with_error(toolkit, f"Directory '{config.name}' already exists.") if shutil.which("uv") is None: _exit_with_error( @@ -213,16 +210,16 @@ def new( toolkit.print_line() # Print success message - if project_name: + if not current_dir: toolkit.print( - f"[bold green]✨ Success![/bold green] Created FastAPI project: [cyan]{project_name}[/cyan]", + f"[bold green]✨ Success![/bold green] Created FastAPI project: [cyan]{config.name}[/cyan]", tag="success", ) toolkit.print_line() toolkit.print("[bold]Next steps:[/bold]") - toolkit.print(f" [dim]$[/dim] cd {project_name}") + toolkit.print(f" [dim]$[/dim] cd {config.name}") toolkit.print(" [dim]$[/dim] uv run fastapi dev") else: toolkit.print( From ab452c94c5bf69f41420c44324ef9925ad09526e Mon Sep 17 00:00:00 2001 From: Alejandra Date: Fri, 2 Jan 2026 19:06:31 +0100 Subject: [PATCH 5/5] =?UTF-8?q?=E2=9C=85=20Update=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_new.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_new.py b/tests/test_new.py index d77bf17..d3d13da 100644 --- a/tests/test_new.py +++ b/tests/test_new.py @@ -74,7 +74,6 @@ def test_initializes_in_current_directory(temp_project_dir: Path) -> None: result = runner.invoke(app, []) assert result.exit_code == 0 - assert "No project name provided" in result.output assert "Initializing in current directory" in result.output _assert_project_created(temp_project_dir) @@ -83,7 +82,6 @@ def test_initializes_in_current_directory_with_dot(temp_project_dir: Path) -> No result = runner.invoke(app, ["."]) assert result.exit_code == 0 - assert "No project name provided" in result.output assert "Initializing in current directory" in result.output _assert_project_created(temp_project_dir)