22from pathlib import Path
33from typing import Optional
44
5- from pyscaffold import api
5+ from pyscaffold import api , file_system , shell
66from pyscaffoldext .markdown .extension import Markdown
77
88__author__ = "Jayaram Kancherla"
1212
1313def create_repository (
1414 project_path : str ,
15- description : Optional [str ] = None ,
15+ description : Optional [str ] = "Add a short description here!" ,
1616 license : str = "MIT" ,
1717) -> None :
1818 """
1919 Create a new BiocPy Python package repository.
2020
2121 Args:
2222 project_path:
23- Path where the new project should be created
23+ Path where the new project should be created.
2424
2525 description:
26- Optional project description
26+ Optional project description.
2727
2828 license:
29- License to use (default: MIT)
29+ License to use.
30+ Defaults to 'MIT'.
3031 """
3132 # Create project using pyscaffold with markdown extension
33+ if description is None :
34+ description = "Add a short description here!"
35+
3236 opts = {
3337 "project_path" : project_path ,
34- "description" : description or "Add a short description here!" ,
38+ "description" : description ,
3539 "license" : license ,
3640 "extensions" : [Markdown ()],
3741 }
3842 api .create_project (** opts )
3943
44+ modified_files = []
45+
4046 # Get absolute path to templates directory
4147 template_dir = Path (__file__ ).parent / "templates"
4248
@@ -48,11 +54,13 @@ def create_repository(
4854 src = template_dir / "github_workflows" / workflow
4955 dst = gh_actions_dir / workflow
5056 shutil .copy2 (src , dst )
57+ modified_files .append (dst )
5158
5259 # Add pre-commit config
5360 precommit_src = template_dir / "precommit" / "pre-commit-config.yaml"
5461 precommit_dst = Path (project_path ) / ".pre-commit-config.yaml"
5562 shutil .copy2 (precommit_src , precommit_dst )
63+ modified_files .append (precommit_dst )
5664
5765 # Modify sphinx conf.py
5866 conf_py_path = Path (project_path ) / "docs" / "conf.py"
@@ -61,6 +69,7 @@ def create_repository(
6169
6270 # Add myst-nb extension and configuration
6371 myst_config = """
72+
6473# -- Biocsetup configuration -------------------------------------------------
6574
6675# Enable execution of code chunks in markdown
@@ -77,24 +86,25 @@ def create_repository(
7786
7887autosummary_generate = True
7988autosummary_imported_members = True
80-
81- html_theme = "furo"
8289"""
8390
91+ conf_content = conf_content .replace ("alabaster" , "furo" )
92+
8493 with open (conf_py_path , "w" ) as f :
8594 f .write (conf_content + myst_config )
95+ modified_files .append (conf_py_path )
8696
8797 # Update requirements.txt for docs
8898 docs_requirements = Path (project_path ) / "docs" / "requirements.txt"
8999 with open (docs_requirements , "a" ) as f :
90- f .write ("\n myst-nb\n furo\n sphinx-autodoc-typehints\n " )
100+ f .write ("myst-nb\n furo\n sphinx-autodoc-typehints\n " )
101+ modified_files .append (docs_requirements )
91102
92103 # Modify README
93104 readme_path = Path (project_path ) / "README.md"
94105 proj_name = Path (project_path ).parts [- 1 ]
95106
96- new_readme = f"""
97- [](https://pypi.org/project/{ proj_name } /)
107+ new_readme = f"""[](https://pypi.org/project/{ proj_name } /)
98108
99109
100110# { proj_name }
@@ -121,6 +131,7 @@ def create_repository(
121131
122132 with open (readme_path , "w" ) as f :
123133 f .write (new_readme )
134+ modified_files .append (readme_path )
124135
125136 # Modify ppyproject.toml to add ruff configuration
126137 pyprj_path = Path (project_path ) / "pyproject.toml"
@@ -147,3 +158,12 @@ def create_repository(
147158
148159 with open (pyprj_path , "w" ) as f :
149160 f .write (pyprj_content + ruff_config )
161+ modified_files .append (pyprj_path )
162+
163+ with file_system .chdir (project_path ):
164+ for f in modified_files :
165+ shell .git ("add" , str (f .relative_to (project_path )))
166+
167+ shell .git ("commit" , "-m" , "BiocSetup configuration" )
168+
169+ print ("BiocSetup complete! 🚀 💥" )
0 commit comments