scitex-template 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. scitex_template/README.md +154 -0
  2. scitex_template/__init__.py +219 -0
  3. scitex_template/_code/__init__.py +0 -0
  4. scitex_template/_code/_code_templates.py +147 -0
  5. scitex_template/_code/templates/__init__.py +51 -0
  6. scitex_template/_code/templates/audio.py +233 -0
  7. scitex_template/_code/templates/canvas.py +312 -0
  8. scitex_template/_code/templates/capture.py +268 -0
  9. scitex_template/_code/templates/config.py +43 -0
  10. scitex_template/_code/templates/diagram.py +294 -0
  11. scitex_template/_code/templates/io.py +107 -0
  12. scitex_template/_code/templates/module.py +53 -0
  13. scitex_template/_code/templates/plt.py +202 -0
  14. scitex_template/_code/templates/scholar.py +267 -0
  15. scitex_template/_code/templates/session.py +130 -0
  16. scitex_template/_code/templates/session_minimal.py +43 -0
  17. scitex_template/_code/templates/session_plot.py +67 -0
  18. scitex_template/_code/templates/session_stats.py +77 -0
  19. scitex_template/_code/templates/stats.py +323 -0
  20. scitex_template/_code/templates/writer.py +296 -0
  21. scitex_template/_mcp/__init__.py +3 -0
  22. scitex_template/_mcp/handlers.py +329 -0
  23. scitex_template/_mcp/tool_schemas.py +167 -0
  24. scitex_template/_project/__init__.py +17 -0
  25. scitex_template/_project/_app_templates.py +405 -0
  26. scitex_template/_project/_clone_project.py +257 -0
  27. scitex_template/_project/_clone_template.py +122 -0
  28. scitex_template/_project/_customize.py +160 -0
  29. scitex_template/_project/_directory_structure.py +64 -0
  30. scitex_template/_project/_generate_configs.py +262 -0
  31. scitex_template/_project/_generate_readme.py +136 -0
  32. scitex_template/_project/_scholar_writer_integration.py +162 -0
  33. scitex_template/_project/clone_app.py +206 -0
  34. scitex_template/_project/clone_module.py +236 -0
  35. scitex_template/_project/clone_pip_project.py +107 -0
  36. scitex_template/_project/clone_research.py +107 -0
  37. scitex_template/_project/clone_research_minimal.py +124 -0
  38. scitex_template/_project/clone_scitex_minimal.py +103 -0
  39. scitex_template/_project/clone_singularity.py +107 -0
  40. scitex_template/_project/clone_writer_directory.py +107 -0
  41. scitex_template/_skills/SKILL.md +57 -0
  42. scitex_template/_skills/code-templates.md +263 -0
  43. scitex_template/_skills/config-generators.md +196 -0
  44. scitex_template/_skills/git-strategies.md +81 -0
  45. scitex_template/_skills/project-templates.md +184 -0
  46. scitex_template/_skills/scholar-writer-integration.md +130 -0
  47. scitex_template/_utils/__init__.py +0 -0
  48. scitex_template/_utils/_copy.py +106 -0
  49. scitex_template/_utils/_customize.py +117 -0
  50. scitex_template/_utils/_git_strategy.py +123 -0
  51. scitex_template/_utils/_logging_helpers.py +123 -0
  52. scitex_template/_utils/_rename.py +66 -0
  53. scitex_template/mcp_server.py +199 -0
  54. scitex_template-0.1.0.dist-info/METADATA +141 -0
  55. scitex_template-0.1.0.dist-info/RECORD +58 -0
  56. scitex_template-0.1.0.dist-info/WHEEL +4 -0
  57. scitex_template-0.1.0.dist-info/entry_points.txt +2 -0
  58. scitex_template-0.1.0.dist-info/licenses/LICENSE +661 -0
@@ -0,0 +1,154 @@
1
+ <!-- ---
2
+ !-- Timestamp: 2025-10-29 05:56:40
3
+ !-- Author: ywatanabe
4
+ !-- File: /home/ywatanabe/proj/scitex-python/src/scitex/template/README.md
5
+ !-- --- -->
6
+
7
+ # SciTeX Template Module
8
+
9
+ Project template creation utilities for SciTeX ecosystem.
10
+
11
+ ## Available Templates
12
+
13
+ ### 1. Research Project (`clone_research`)
14
+ Full scientific workflow structure for research projects.
15
+
16
+ **Use case:** Scientific research with data analysis, experiments, and paper writing
17
+
18
+ **Template:** [scitex_template_research](https://github.com/ywatanabe1989/scitex_template_research.git)
19
+
20
+ **Features:**
21
+ - `scripts/` - Analysis and preprocessing scripts
22
+ - `data/` - Raw and processed data management
23
+ - `docs/` - Manuscripts, notes, and references
24
+ - `results/` - Analysis outputs and reports
25
+ - `config/` - Project configuration files
26
+
27
+ ### 2. Python Package (`clone_pip_project`)
28
+ Pip-installable Python package template.
29
+
30
+ **Use case:** Creating distributable Python packages for PyPI
31
+
32
+ **Template:** [pip-project-template](https://github.com/ywatanabe1989/pip-project-template.git)
33
+
34
+ **Features:**
35
+ - `src/` - Package source code
36
+ - `tests/` - Unit and integration tests
37
+ - `docs/` - Sphinx documentation
38
+ - `setup.py` - Package configuration
39
+ - CI/CD - GitHub Actions workflows
40
+
41
+ ### 3. Singularity Container (`clone_singularity`)
42
+ Container-based project with Singularity.
43
+
44
+ **Use case:** Reproducible computational environments with containers
45
+
46
+ **Template:** [singularity-template](https://github.com/ywatanabe1989/singularity-template.git)
47
+
48
+ **Features:**
49
+ - Singularity definition files
50
+ - Container build scripts
51
+ - Environment specifications
52
+ - Deployment configuration
53
+
54
+ ### 4. Paper Directory (`clone_writer_directory`)
55
+ Academic paper writing template with scitex-writer.
56
+
57
+ **Use case:** Writing academic papers with LaTeX and BibTeX management
58
+
59
+ **Template:** [scitex-writer](git@github.com:ywatanabe1989/scitex-writer.git)
60
+
61
+ **Features:**
62
+ - LaTeX document structure
63
+ - BibTeX bibliography management
64
+ - Figure and table organization
65
+ - Manuscript tracking
66
+
67
+ ## Git Strategy Options
68
+
69
+ All template functions support a `git_strategy` parameter to control git initialization:
70
+
71
+ - `"child"` (default): Creates new isolated git repository with initial commit and main/develop branches
72
+ - `"parent"`: Uses existing parent git repository (degrades to "child" if not found)
73
+ - `"origin"`: Preserves template's original git history for upstream tracking
74
+ - `None`: Disables git initialization entirely
75
+
76
+ ## Usage
77
+
78
+ ### Python API
79
+
80
+ ```python
81
+ from scitex.template import (
82
+ clone_research,
83
+ clone_pip_project,
84
+ clone_singularity,
85
+ clone_writer_directory,
86
+ )
87
+
88
+ # Create a research project
89
+ clone_research("my_research_project")
90
+
91
+ # Create with specific git strategy
92
+ clone_pip_project("my_package", "~/projects", git_strategy="parent")
93
+
94
+ # Preserve template git history
95
+ clone_singularity("my_container", git_strategy="origin")
96
+
97
+ # No git initialization
98
+ clone_writer_directory("my_paper", "~/papers", git_strategy=None)
99
+ ```
100
+
101
+ ### Command Line
102
+
103
+ ```bash
104
+ # Research project
105
+ python -m scitex clone_research my_research_project
106
+ python -m scitex clone_research my_project ~/projects
107
+
108
+ # Python package
109
+ python -m scitex clone_pip_project my_package
110
+ python -m scitex clone_pip_project my_package ~/packages
111
+
112
+ # Singularity container
113
+ python -m scitex clone_singularity my_container
114
+ python -m scitex clone_singularity my_container ~/containers
115
+
116
+ # Paper directory
117
+ python -m scitex clone_writer_directory my_paper
118
+ python -m scitex clone_writer_directory my_paper ~/papers
119
+ ```
120
+
121
+ ### Get Template Information
122
+
123
+ ```python
124
+ from scitex.template import get_available_templates_info
125
+
126
+ templates = get_available_templates_info()
127
+ for template in templates:
128
+ print(f"{template['name']}: {template['description']}")
129
+ print(f" Use case: {template['use_case']}")
130
+ print(f" GitHub: {template['github_url']}")
131
+ ```
132
+
133
+ ## What Happens When You Create a Project
134
+
135
+ 1. **Clone Template**: Downloads the template repository to a temporary directory
136
+ 2. **Handle Git History**: Based on git_strategy:
137
+ - `"child"`: Removes template's `.git` directory
138
+ - `"origin"`: Preserves template's `.git` directory
139
+ - `"parent"`: Removes template's `.git` directory
140
+ 3. **Copy to Target**: Copies template files to your target directory
141
+ 4. **Customize**: Renames template package/directories to match your project name
142
+ 5. **Update References**: Updates all references to the template name in files
143
+ 6. **Initialize Git**: Based on git_strategy:
144
+ - `"child"`: Creates new git repository with initial commit and `main`/`develop` branches
145
+ - `"parent"`: Uses existing parent repository
146
+ - `"origin"`: Keeps template's git history
147
+ - `None`: Skips git initialization
148
+
149
+ ## Requirements
150
+
151
+ - Git must be installed and accessible in PATH
152
+ - SSH keys configured for GitHub (for templates using SSH URLs)
153
+
154
+ <!-- EOF -->
@@ -0,0 +1,219 @@
1
+ #!/usr/bin/env python3
2
+ # File: /home/ywatanabe/proj/scitex_repo/src/scitex/template/__init__.py
3
+
4
+ """
5
+ Template management for SciTeX projects.
6
+ """
7
+
8
+ from pathlib import Path
9
+
10
+ from scitex.git import (
11
+ create_child_git,
12
+ find_parent_git,
13
+ init_git_repo,
14
+ remove_child_git,
15
+ )
16
+
17
+ from ._code._code_templates import (
18
+ CODE_TEMPLATES,
19
+ get_all_templates,
20
+ get_code_template,
21
+ list_code_templates,
22
+ )
23
+ from ._project._clone_template import clone_template
24
+ from ._project._customize import customize_minimal_template, customize_template
25
+ from ._project._directory_structure import (
26
+ PROJECT_STRUCTURE,
27
+ build_directory_tree,
28
+ )
29
+ from ._project._generate_configs import (
30
+ create_env_template,
31
+ create_paths_config,
32
+ create_project_config,
33
+ create_requirements_file,
34
+ )
35
+ from ._project._generate_readme import create_minimal_readme, create_project_readme
36
+ from ._project._scholar_writer_integration import (
37
+ ensure_integration,
38
+ setup_scholar_writer_integration,
39
+ )
40
+ from ._project.clone_module import clone_module
41
+ from ._project.clone_pip_project import TEMPLATE_REPO_URL as PIP_PROJECT_URL
42
+ from ._project.clone_pip_project import clone_pip_project
43
+ from ._project.clone_research import TEMPLATE_REPO_URL as RESEARCH_URL
44
+ from ._project.clone_research import clone_research
45
+ from ._project.clone_research_minimal import (
46
+ MINIMAL_INCLUDE_DIRS,
47
+ clone_research_minimal,
48
+ )
49
+ from ._project.clone_scitex_minimal import clone_scitex_minimal
50
+ from ._project.clone_singularity import TEMPLATE_REPO_URL as SINGULARITY_URL
51
+ from ._project.clone_singularity import clone_singularity
52
+ from ._project.clone_writer_directory import TEMPLATE_REPO_URL as PAPER_DIRECTORY_URL
53
+ from ._project.clone_writer_directory import clone_writer_directory
54
+
55
+
56
+ def get_template_tree(template_id):
57
+ """Create template in a tempdir and return its ``tree`` output.
58
+
59
+ Actually runs the template's directory-creation logic in a
60
+ temporary directory on the fly, then captures the real ``tree``
61
+ output. This guarantees the displayed tree always matches
62
+ the current template code.
63
+
64
+ Parameters
65
+ ----------
66
+ template_id : str
67
+ Template identifier (e.g. 'minimal', 'research').
68
+
69
+ Returns
70
+ -------
71
+ str
72
+ ``tree`` output string, or empty string if unknown.
73
+ """
74
+ import shutil
75
+ import subprocess
76
+ import tempfile
77
+
78
+ from scitex.scholar.ensure_workspace import SCHOLAR_SUBDIRS
79
+
80
+ tmpdir = tempfile.mkdtemp(prefix="scitex_tree_")
81
+ try:
82
+ project_dir = Path(tmpdir) / "project"
83
+ project_dir.mkdir()
84
+
85
+ if template_id == "minimal":
86
+ # Reproduce scitex_minimal directory scaffold without git clone
87
+ writer_dir = project_dir / "scitex" / "writer"
88
+ for name in MINIMAL_INCLUDE_DIRS:
89
+ (writer_dir / name).mkdir(parents=True, exist_ok=True)
90
+ scholar_dir = project_dir / "scitex" / "scholar"
91
+ for name in SCHOLAR_SUBDIRS:
92
+ (scholar_dir / name).mkdir(parents=True, exist_ok=True)
93
+
94
+ elif template_id == "research":
95
+ build_directory_tree(str(project_dir), PROJECT_STRUCTURE)
96
+
97
+ elif template_id == "app":
98
+ # Reproduce pip-project-template structure
99
+ src_dir = project_dir / "src" / "package_name"
100
+ src_dir.mkdir(parents=True)
101
+ (src_dir / "__init__.py").touch()
102
+ tests_dir = project_dir / "tests"
103
+ tests_dir.mkdir()
104
+ (tests_dir / "__init__.py").touch()
105
+ (tests_dir / "test_main.py").touch()
106
+ (project_dir / "pyproject.toml").touch()
107
+ (project_dir / "README.md").touch()
108
+ (project_dir / "LICENSE").touch()
109
+
110
+ else:
111
+ return ""
112
+
113
+ result = subprocess.run(
114
+ ["tree", "--noreport", "--dirsfirst", str(project_dir)],
115
+ capture_output=True,
116
+ text=True,
117
+ timeout=5,
118
+ )
119
+ if result.returncode == 0:
120
+ # Replace the temp path prefix with "."
121
+ tree_output = result.stdout.strip()
122
+ first_newline = tree_output.find("\n")
123
+ if first_newline != -1:
124
+ return "." + tree_output[first_newline:]
125
+ return "."
126
+ return ""
127
+
128
+ except Exception:
129
+ return ""
130
+ finally:
131
+ shutil.rmtree(tmpdir, ignore_errors=True)
132
+
133
+
134
+ def get_available_templates_info():
135
+ """
136
+ Get information about all available SciTeX project templates.
137
+
138
+ Returns
139
+ -------
140
+ list[dict]
141
+ List of template information dictionaries, each containing:
142
+ - id: Template identifier (used in code)
143
+ - name: Human-readable template name
144
+ - description: Template description
145
+ - github_url: GitHub repository URL
146
+ - use_case: When to use this template
147
+ - tree: Tree-command-style directory listing
148
+
149
+ Example
150
+ -------
151
+ >>> from scitex.template import get_available_templates_info
152
+ >>> templates = get_available_templates_info()
153
+ >>> for template in templates:
154
+ ... print(f"{template['name']}: {template['description']}")
155
+ """
156
+ return [
157
+ {
158
+ "id": "minimal",
159
+ "name": "SciTeX Minimal",
160
+ "description": "Minimal project with writer + scholar workspaces",
161
+ "github_url": RESEARCH_URL,
162
+ "use_case": "Manuscript writing with integrated bibliography management",
163
+ "tree": get_template_tree("minimal"),
164
+ },
165
+ {
166
+ "id": "research",
167
+ "name": "SciTeX Full",
168
+ "description": "Full scientific workflow with data analysis, experiments, and paper writing",
169
+ "github_url": RESEARCH_URL,
170
+ "use_case": "End-to-end scientific research projects",
171
+ "tree": get_template_tree("research"),
172
+ },
173
+ {
174
+ "id": "app",
175
+ "name": "SciTeX App",
176
+ "description": "Pip-installable Python package for building reusable SciTeX apps",
177
+ "github_url": PIP_PROJECT_URL,
178
+ "use_case": "Creating reusable tools and apps for the SciTeX ecosystem",
179
+ "tree": get_template_tree("app"),
180
+ },
181
+ ]
182
+
183
+
184
+ __all__ = [
185
+ "clone_template",
186
+ "clone_module",
187
+ "clone_research",
188
+ "clone_research_minimal",
189
+ "clone_scitex_minimal",
190
+ "MINIMAL_INCLUDE_DIRS",
191
+ "clone_pip_project",
192
+ "clone_singularity",
193
+ "clone_writer_directory",
194
+ "get_available_templates_info",
195
+ "get_code_template",
196
+ "list_code_templates",
197
+ "get_all_templates",
198
+ "CODE_TEMPLATES",
199
+ "init_git_repo",
200
+ "find_parent_git",
201
+ "create_child_git",
202
+ "remove_child_git",
203
+ # Template customization (moved from Django)
204
+ "customize_template",
205
+ "customize_minimal_template",
206
+ "create_project_config",
207
+ "create_paths_config",
208
+ "create_env_template",
209
+ "create_requirements_file",
210
+ "create_minimal_readme",
211
+ "create_project_readme",
212
+ "build_directory_tree",
213
+ "PROJECT_STRUCTURE",
214
+ # Scholar-Writer integration
215
+ "setup_scholar_writer_integration",
216
+ "ensure_integration",
217
+ ]
218
+
219
+ # EOF
File without changes
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env python3
2
+ """Code templates for common SciTeX patterns.
3
+
4
+ Provides ready-to-use code snippets for scripts and modules.
5
+ """
6
+
7
+ from datetime import datetime
8
+ from pathlib import Path
9
+ from typing import Optional
10
+
11
+ # Import templates from subdirectory
12
+ from .templates import CODE_TEMPLATES
13
+
14
+
15
+ def get_code_template(
16
+ template_id: str,
17
+ filepath: Optional[str] = None,
18
+ docstring: Optional[str] = None,
19
+ ) -> str:
20
+ """
21
+ Get a code template by ID.
22
+
23
+ Parameters
24
+ ----------
25
+ template_id : str
26
+ Template identifier (session, session-minimal, session-plot, etc.)
27
+ filepath : str, optional
28
+ File path to include in template header.
29
+ docstring : str, optional
30
+ Custom docstring for the template.
31
+
32
+ Returns
33
+ -------
34
+ str
35
+ Formatted template content.
36
+ """
37
+ if template_id not in CODE_TEMPLATES:
38
+ available = ", ".join(CODE_TEMPLATES.keys())
39
+ raise ValueError(f"Unknown template: '{template_id}'. Available: {available}")
40
+
41
+ template = CODE_TEMPLATES[template_id]
42
+ content = template["content"]
43
+
44
+ # Format placeholders
45
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
46
+ filepath = filepath or template["filename"]
47
+ docstring = docstring or "Description of this script/module"
48
+
49
+ filename = Path(filepath).name
50
+ filename_stem = Path(filepath).stem
51
+
52
+ return content.format(
53
+ timestamp=timestamp,
54
+ filepath=filepath,
55
+ filename=filename,
56
+ filename_stem=filename_stem,
57
+ docstring=docstring,
58
+ )
59
+
60
+
61
+ def list_code_templates():
62
+ """
63
+ List all available code templates.
64
+
65
+ Returns
66
+ -------
67
+ list[dict]
68
+ List of template info dictionaries.
69
+ """
70
+ return [
71
+ {
72
+ "id": tid,
73
+ "name": info["name"],
74
+ "description": info["description"],
75
+ "filename": info["filename"],
76
+ "usage": info.get("usage", ""),
77
+ }
78
+ for tid, info in CODE_TEMPLATES.items()
79
+ ]
80
+
81
+
82
+ def get_all_templates() -> str:
83
+ """
84
+ Get all templates combined into one string.
85
+
86
+ Returns
87
+ -------
88
+ str
89
+ All templates with headers, ordered by priority:
90
+ 1. session - Main workflow template
91
+ 2. io - File I/O patterns
92
+ 3. Others (config, module, etc.)
93
+ """
94
+ # Priority order
95
+ priority_order = [
96
+ # Core templates (priority 1-3)
97
+ "session",
98
+ "io",
99
+ "config",
100
+ # Session variants
101
+ "session-minimal",
102
+ "session-plot",
103
+ "session-stats",
104
+ "module",
105
+ # Module usage templates
106
+ "plt",
107
+ "stats",
108
+ "scholar",
109
+ "audio",
110
+ "capture",
111
+ "diagram",
112
+ "canvas",
113
+ "writer",
114
+ ]
115
+
116
+ sections = []
117
+ sections.append("=" * 70)
118
+ sections.append("SCITEX CODE TEMPLATES")
119
+ sections.append("=" * 70)
120
+
121
+ for tid in priority_order:
122
+ if tid not in CODE_TEMPLATES:
123
+ continue
124
+ info = CODE_TEMPLATES[tid]
125
+ sections.append("")
126
+ sections.append("-" * 70)
127
+ sections.append(f"TEMPLATE: {tid}")
128
+ sections.append(f" {info['name']} - {info['description']}")
129
+ sections.append("-" * 70)
130
+ if info.get("usage"):
131
+ sections.append(info["usage"].strip())
132
+ sections.append("")
133
+ sections.append("```python" if not tid == "config" else "```yaml")
134
+ sections.append(info["content"].strip())
135
+ sections.append("```")
136
+
137
+ return "\n".join(sections)
138
+
139
+
140
+ __all__ = [
141
+ "get_code_template",
142
+ "list_code_templates",
143
+ "get_all_templates",
144
+ "CODE_TEMPLATES",
145
+ ]
146
+
147
+ # EOF
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env python3
2
+ """Code templates registry - loads all template definitions."""
3
+
4
+ # Core templates (priority 1-3)
5
+ from .audio import TEMPLATE as AUDIO
6
+ from .canvas import TEMPLATE as CANVAS
7
+ from .capture import TEMPLATE as CAPTURE
8
+ from .config import TEMPLATE as CONFIG
9
+ from .diagram import TEMPLATE as DIAGRAM
10
+ from .io import TEMPLATE as IO
11
+
12
+ # Module template
13
+ from .module import TEMPLATE as MODULE
14
+
15
+ # Module usage templates (priority 4+)
16
+ from .plt import TEMPLATE as PLT
17
+ from .scholar import TEMPLATE as SCHOLAR
18
+ from .session import TEMPLATE as SESSION
19
+
20
+ # Session variants
21
+ from .session_minimal import TEMPLATE as SESSION_MINIMAL
22
+ from .session_plot import TEMPLATE as SESSION_PLOT
23
+ from .session_stats import TEMPLATE as SESSION_STATS
24
+ from .stats import TEMPLATE as STATS
25
+ from .writer import TEMPLATE as WRITER
26
+
27
+ CODE_TEMPLATES = {
28
+ # Priority 1-3: Core templates
29
+ "session": SESSION,
30
+ "io": IO,
31
+ "config": CONFIG,
32
+ # Session variants
33
+ "session-minimal": SESSION_MINIMAL,
34
+ "session-plot": SESSION_PLOT,
35
+ "session-stats": SESSION_STATS,
36
+ # Module template
37
+ "module": MODULE,
38
+ # Module usage templates
39
+ "plt": PLT,
40
+ "stats": STATS,
41
+ "scholar": SCHOLAR,
42
+ "audio": AUDIO,
43
+ "capture": CAPTURE,
44
+ "diagram": DIAGRAM,
45
+ "canvas": CANVAS,
46
+ "writer": WRITER,
47
+ }
48
+
49
+ __all__ = ["CODE_TEMPLATES"]
50
+
51
+ # EOF