[docs]defcreate_repository(project_path:str,description:Optional[str]="Add a short description here!",license:str="MIT",)->None:""" Create a new BiocPy Python package repository. Args: project_path: Path where the new project should be created. description: Optional project description. license: License to use. Defaults to 'MIT'. """# Create project using pyscaffold with markdown extensionifdescriptionisNone:description="Add a short description here!"opts={"project_path":project_path,"description":description,"license":license,"extensions":[Markdown()],}api.create_project(**opts)modified_files=[]# Get absolute path to templates directorytemplate_dir=Path(__file__).parent/"templates"# Add GitHub Actionsgh_actions_dir=Path(project_path)/".github"/"workflows"gh_actions_dir.mkdir(parents=True,exist_ok=True)forworkflowin["run-tests.yml","publish-pypi.yml"]:src=template_dir/"github_workflows"/workflowdst=gh_actions_dir/workflowshutil.copy2(src,dst)modified_files.append(dst)# Add pre-commit configprecommit_src=template_dir/"precommit"/"pre-commit-config.yaml"precommit_dst=Path(project_path)/".pre-commit-config.yaml"shutil.copy2(precommit_src,precommit_dst)modified_files.append(precommit_dst)# Modify sphinx conf.pyconf_py_path=Path(project_path)/"docs"/"conf.py"withopen(conf_py_path,"r")asf:conf_content=f.read()# Add myst-nb extension and configurationmyst_config="""# -- Biocsetup configuration -------------------------------------------------# Enable execution of code chunks in markdownextensions.remove('myst_parser')extensions.append('myst_nb')# Less verbose api documentationextensions.append('sphinx_autodoc_typehints')autodoc_default_options = { "special-members": True, "undoc-members": True, "exclude-members": "__weakref__, __dict__, __str__, __module__",}autosummary_generate = Trueautosummary_imported_members = Truehtml_theme = "furo""""# conf_content = conf_content.replace("alabaster", "furo")withopen(conf_py_path,"w")asf:f.write(conf_content+myst_config)modified_files.append(conf_py_path)# Update requirements.txt for docsdocs_requirements=Path(project_path)/"docs"/"requirements.txt"withopen(docs_requirements,"a")asf:f.write("myst-nb\nfuro\nsphinx-autodoc-typehints\n")modified_files.append(docs_requirements)# Modify READMEreadme_path=Path(project_path)/"README.md"proj_name=Path(project_path).parts[-1]new_readme=f"""[![PyPI-Server](https://img.shields.io/pypi/v/{proj_name}.svg)](https://pypi.org/project/{proj_name}/)![Unit tests](https://github.com/BiocPy/{proj_name}/actions/workflows/pypi-test.yml/badge.svg)# {proj_name}> {description}A longer description of your project goes here...## InstallTo get started, install the package from [PyPI](https://pypi.org/project/{proj_name}/)```bashpip install {proj_name}```<!-- biocsetup-notes -->## NoteThis project has been set up using [BiocSetup](https://github.com/biocpy/biocsetup)and [PyScaffold](https://pyscaffold.org/)."""withopen(readme_path,"w")asf:f.write(new_readme)modified_files.append(readme_path)# Modify ppyproject.toml to add ruff configurationpyprj_path=Path(project_path)/"pyproject.toml"withopen(pyprj_path,"r")asf:pyprj_content=f.read()ruff_config="""[tool.ruff]line-length = 120src = ["src"]exclude = ["tests"]extend-ignore = ["F821"][tool.ruff.pydocstyle]convention = "google"[tool.ruff.format]docstring-code-format = truedocstring-code-line-length = 20[tool.ruff.per-file-ignores]"__init__.py" = ["E402", "F401"]"""withopen(pyprj_path,"w")asf:f.write(pyprj_content+ruff_config)modified_files.append(pyprj_path)withfile_system.chdir(project_path):forfinmodified_files:shell.git("add",str(f.relative_to(project_path)))shell.git("commit","-m","BiocSetup configuration")print("BiocSetup complete! 🚀 💥")