Skip to content

Commit

Permalink
Minor changes to improve UX (#3)
Browse files Browse the repository at this point in the history
Update tests, docstring, README etc.
  • Loading branch information
jkanche authored Dec 10, 2024
1 parent fb83f67 commit ca1966d
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.1.1

Minor changes to improve user experience.

## Version 0.1.0

- Uses PyScaffold with Markdown extension for base project structure
Expand All @@ -10,4 +14,4 @@
- Furo theme
- Type hints documentation
- Adds Ruff configuration for consistent code formatting
- Creates standardized README with PyPI and CI badges
- Creates README
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ create_repository(
)
```

## After setup

- (Optional) Enable [pre-commit.ci](https://pre-commit.ci/) bot for your new repository.
- (Optional) Install [ruff](https://docs.astral.sh/ruff/) for code formatting.

<!-- pyscaffold-notes -->

## Note
Expand Down
21 changes: 19 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = "alabaster"
html_theme = "furo"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -301,4 +301,21 @@
"pyscaffold": ("https://pyscaffold.org/en/stable", None),
}

print(f"loading configurations for {project} {version} ...", file=sys.stderr)
print(f"loading configurations for {project} {version} ...", file=sys.stderr)

# -- Biocsetup configuration -------------------------------------------------

# Enable execution of code chunks in markdown
extensions.append('myst_nb')

# Less verbose api documentation
extensions.append('sphinx_autodoc_typehints')

autodoc_default_options = {
"special-members": True,
"undoc-members": True,
"exclude-members": "__weakref__, __dict__, __str__, __module__",
}

autosummary_generate = True
autosummary_imported_members = True
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
furo
# Requirements file for ReadTheDocs, check .readthedocs.yml.
# To build the module reference correctly, make sure every external package
# under `install_requires` in `setup.cfg` is also listed here!
Expand Down
4 changes: 2 additions & 2 deletions src/biocsetup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

@click.command()
@click.argument("project_path")
@click.option("--description", "-d", help="Project description")
@click.option("--description", "-d", help="Project description", default="Add a short description here!")
@click.option("--license", "-l", default="MIT", help="License (default: MIT)")
def main(project_path: str, description: str, license: str):
"""Create a new Python package repository with consistent configuration."""
"""Create a new BiocPy Python package."""
create_repository(
project_path=project_path,
description=description,
Expand Down
42 changes: 31 additions & 11 deletions src/biocsetup/create_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from typing import Optional

from pyscaffold import api
from pyscaffold import api, file_system, shell
from pyscaffoldext.markdown.extension import Markdown

__author__ = "Jayaram Kancherla"
Expand All @@ -12,31 +12,37 @@

def create_repository(
project_path: str,
description: Optional[str] = None,
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
Path where the new project should be created.
description:
Optional project description
Optional project description.
license:
License to use (default: MIT)
License to use.
Defaults to 'MIT'.
"""
# Create project using pyscaffold with markdown extension
if description is None:
description = "Add a short description here!"

opts = {
"project_path": project_path,
"description": description or "Add a short description here!",
"description": description,
"license": license,
"extensions": [Markdown()],
}
api.create_project(**opts)

modified_files = []

# Get absolute path to templates directory
template_dir = Path(__file__).parent / "templates"

Expand All @@ -48,11 +54,13 @@ def create_repository(
src = template_dir / "github_workflows" / workflow
dst = gh_actions_dir / workflow
shutil.copy2(src, dst)
modified_files.append(dst)

# Add pre-commit config
precommit_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.py
conf_py_path = Path(project_path) / "docs" / "conf.py"
Expand All @@ -61,6 +69,7 @@ def create_repository(

# Add myst-nb extension and configuration
myst_config = """
# -- Biocsetup configuration -------------------------------------------------
# Enable execution of code chunks in markdown
Expand All @@ -77,24 +86,25 @@ def create_repository(
autosummary_generate = True
autosummary_imported_members = True
html_theme = "furo"
"""

conf_content = conf_content.replace("alabaster", "furo")

with open(conf_py_path, "w") as f:
f.write(conf_content + myst_config)
modified_files.append(conf_py_path)

# Update requirements.txt for docs
docs_requirements = Path(project_path) / "docs" / "requirements.txt"
with open(docs_requirements, "a") as f:
f.write("\nmyst-nb\nfuro\nsphinx-autodoc-typehints\n")
f.write("myst-nb\nfuro\nsphinx-autodoc-typehints\n")
modified_files.append(docs_requirements)

# Modify README
readme_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}/)
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}
Expand All @@ -121,6 +131,7 @@ def create_repository(

with open(readme_path, "w") as f:
f.write(new_readme)
modified_files.append(readme_path)

# Modify ppyproject.toml to add ruff configuration
pyprj_path = Path(project_path) / "pyproject.toml"
Expand All @@ -147,3 +158,12 @@ def create_repository(

with open(pyprj_path, "w") as f:
f.write(pyprj_content + ruff_config)
modified_files.append(pyprj_path)

with file_system.chdir(project_path):
for f in modified_files:
shell.git("add", str(f.relative_to(project_path)))

shell.git("commit", "-m", "BiocSetup configuration")

print("BiocSetup complete! 🚀 💥")
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ def test_cli_help():
runner = CliRunner()
result = runner.invoke(main, ["--help"])
assert result.exit_code == 0
assert "Create a new Python package repository" in result.output
assert "Create a new BiocPy Python package" in result.output
assert "--description" in result.output
assert "--license" in result.output

0 comments on commit ca1966d

Please sign in to comment.