Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VS Code integration #312

Merged
merged 10 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/assets/cookiecutter-scverse-instance.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"github_user": "scverse",
"github_repo": "cookiecutter-scverse-instance",
"license": "BSD 3-Clause License",
"ide_integration": true,
"_copy_without_render": [
".github/workflows/**.yaml",
"docs/_templates/autosummary/**.rst"
Expand Down
7 changes: 7 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
overrides:
# JSON with comments and trailing commas
- files: "**/*.vscode*/*.json"
options:
parser: json5
quoteProps: preserve
singleQuote: false
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"GNU General Public License Version 3",
"Unlicense"
],
"ide_integration": true,
"_copy_without_render": [
".github/workflows/build.yaml",
".github/workflows/test.yaml",
Expand Down
17 changes: 16 additions & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
#!/bin/env python3
import shutil
from subprocess import run
{% if not cookiecutter._render_devdocs %}
from pathlib import Path

{% if not cookiecutter._render_devdocs %}
# Post processing
Path("docs/template_usage.md").unlink()
{% endif %}

# Skip directories marked for skipping
def skipped_dirs():
for toplevel in Path().iterdir():
if toplevel.name == ".git":
continue
if toplevel.name == "DELETE-ME":
yield toplevel
else:
yield from toplevel.rglob("DELETE-ME")

for path in skipped_dirs():
assert path.is_dir(), path
shutil.rmtree(path)

# Update pre commit hooks
run("pre-commit autoupdate -c .pre-commit-config.yaml".split(), check=True)
run("pre-commit install".split(), check=True)
Expand Down
17 changes: 12 additions & 5 deletions scripts/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@
@pytest.mark.parametrize(
("params", "path", "pattern"),
[
({}, "docs/conf.py", r'"github_repo": project_name,'),
({"github_repo": "floob"}, "docs/conf.py", r'"github_repo": "floob",'),
pytest.param({}, "docs/conf.py", r'"github_repo": project_name,', id="no_gh_repo"),
pytest.param({"github_repo": "floob"}, "docs/conf.py", r'"github_repo": "floob",', id="gh_repo"),
pytest.param({}, ".vscode/extensions.json", r'"ms-python.python",', id="no_ide_integ"),
pytest.param({"ide_integration": False}, ".vscode", None, id="ide_integ"),
],
)
def test_build(tmp_path: Path, params: Mapping[str, Any], path: Path | str, pattern: re.Pattern | str):
def test_build(tmp_path: Path, params: Mapping[str, Any], path: Path | str, pattern: re.Pattern | str | None):
cookiecutter(str(HERE.parent.parent), output_dir=tmp_path, no_input=True, extra_context=params)
proj_dir = tmp_path / "project-name"
assert proj_dir.is_dir()
path = proj_dir / path
pattern = re.compile(pattern, re.MULTILINE)
assert pattern.search(path.read_text())
if pattern is None:
assert not path.exists()
else:
pattern = re.compile(pattern, re.MULTILINE)
assert pattern.search(path.read_text())

assert not list(proj_dir.rglob("DELETE-ME"))
11 changes: 7 additions & 4 deletions {{cookiecutter.project_name}}/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
*~
buck-out/

{% if not cookiecutter.ide_integration -%}
Zethson marked this conversation as resolved.
Show resolved Hide resolved
# IDEs
/.idea/
Zethson marked this conversation as resolved.
Show resolved Hide resolved
/.vscode/

{% endif -%}

# Compiled files
.venv/
__pycache__/
Expand All @@ -18,7 +25,3 @@ __pycache__/
# docs
/docs/generated/
/docs/_build/

# IDEs
/.idea/
/.vscode/
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
overrides:
# JSON with comments and trailing commas
- files: .vscode/*.json
options:
parser: json5
quoteProps: preserve
singleQuote: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"recommendations": [
// GitHub integration
"github.vscode-github-actions",
"github.vscode-pull-request-github",
// Language support
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter",
"tamasfe.even-better-toml",
// Dependency management
"ninoseki.vscode-mogami",
// Linting and formatting
"editorconfig.editorconfig",
"charliermarsh.ruff",
"esbenp.prettier-vscode",
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Build Documentation",
"type": "debugpy",
"request": "launch",
"module": "sphinx",
"args": ["-M", "html", ".", "_build"],
"cwd": "${workspaceFolder}/docs",
"console": "internalConsole",
"justMyCode": false,
},
{
"name": "Python: Debug Test",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "internalConsole",
"justMyCode": false,
"env": {
"PYTEST_ADDOPTS": "--color=yes",
},
"presentation": {
"hidden": true,
},
},
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"[python][jsonc][yaml]": {
"editor.formatOnSave": true,
},
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.fixAll": "always",
"source.organizeImports": "always",
},
},
"[jsonc][yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
},
"python.analysis.typeCheckingMode": "basic",
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["-vv", "--color=yes"],
}
Loading