Skip to content

Commit

Permalink
project template & layout
Browse files Browse the repository at this point in the history
  • Loading branch information
fmatter committed Oct 12, 2023
1 parent 0d1c95f commit 4da898b
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 50 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
* `extra` directory for user material

### Fixed
* project template

## [0.1.0] - 2023-10-12

### Added
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ mkdocstrings = "^0.23.0"
markdown-include = "^0.8.1"
pytest = "^7.4.2"
keepachangelog = "^1.0.0"
invoke = "^2.2.0"

[build-system]
requires = ["poetry-core"]
Expand Down
10 changes: 5 additions & 5 deletions src/pylingdocs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pylingdocs.cldf import create_cldf, generate_autocomplete
from pylingdocs.config import CONTENT_FOLDER, STRUCTURE_FILE, config
from pylingdocs.helpers import _get_relative_file, _load_cldf_dataset, load_content
from pylingdocs.helpers import _get_relative_file, load_cldf_dataset, load_content
from pylingdocs.helpers import new as create_new
from pylingdocs.helpers import write_readme
from pylingdocs.output import check_abbrevs, check_ids, clean_output
Expand Down Expand Up @@ -82,7 +82,7 @@ def build(source, targets, cldf, output_dir, release):
config.load_from_dir(source)
if not cldf:
cldf = config["paths"]["cldf"]
ds = _load_cldf_dataset(cldf)
ds = load_cldf_dataset(cldf)
contents = load_content(
source_dir=source / CONTENT_FOLDER,
structure_file=_get_relative_file(
Expand Down Expand Up @@ -128,7 +128,7 @@ def preview(source, target, cldf, output_dir, refresh):
target = target or config["output"]["preview"]
if cldf is None:
cldf = config["paths"]["cldf"]
ds = _load_cldf_dataset(cldf)
ds = load_cldf_dataset(cldf)
metadata = load(source / "metadata.yaml") or {}
run_preview(
dataset=ds,
Expand All @@ -146,7 +146,7 @@ def check(source, cldf, output_dir):
del output_dir
if cldf is None:
cldf = config["paths"]["cldf"]
ds = _load_cldf_dataset(cldf)
ds = load_cldf_dataset(cldf)
contents = load_content(
source_dir=source / CONTENT_FOLDER,
structure_file=_get_relative_file(
Expand All @@ -168,7 +168,7 @@ def check(source, cldf, output_dir):
def cldf(source, cldf, output_dir, add):
config.load_from_dir(source)
cldf = cldf or config["paths"]["cldf"]
ds = _load_cldf_dataset(cldf)
ds = load_cldf_dataset(cldf)
contents = load_content(
source_dir=source / CONTENT_FOLDER,
structure_file=_get_relative_file(
Expand Down
2 changes: 1 addition & 1 deletion src/pylingdocs/data/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lfts: # LFTS: Different kinds of entities whose schematic inline representation
paths: # Locations:
cldf: cldf/metadata.json # CLDF dataset location: The path to the CLDF metadata file.
output: output # Output folder: The folder to which output is written.
add_bib: pld/sources.bib # Additional references: Path to a bibfile with references not contained in the dataset.
add_bib: extra/sources.bib # Additional references: Path to a bibfile with references not contained in the dataset.
latex: # LaTeX: LaTeX-specific settings.
article: article # Article template: The default template for the article layout.
book: book # Book template: The default template for the book layout.
Expand Down
14 changes: 6 additions & 8 deletions src/pylingdocs/data/project_template/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
{
"name": "new-pld-document",
"cldf": "cldf/metadata.json",
"title": "My awesome title",
"abstract": "Insert your abstract here",
"title": "Untitled document",
"abstract": "",
"license": ["CC-BY-SA-4.0", "CC-BY-4.0", "CC0-1.0", "No license"],
"keywords": "keyword1,keyword2",
"document_type": ["article", "book", "unpublished"],
"latex_template": ["article", "handout", "book"],
"layout": ["article", "book", "slides"],
"files": "file1,file2",
"use_sublime_text": ["Yes", "No"],
"author_family_name": "author1-family",
"author_given_name": "author1-given",
"repository": "",
"family_name": "Last name",
"given_name": "First name",
"email": "",
"orcid": "",
"affiliation": "",
"repository": "",
"url": ""
}
33 changes: 21 additions & 12 deletions src/pylingdocs/data/project_template/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from writio import dump

from pylingdocs.cldf import generate_autocomplete
from pylingdocs.helpers import _load_cldf_dataset
from pylingdocs.helpers import load_cldf_dataset
from writio import load, dump
from pylingdocs.config import CONTENT_FOLDER

PROJECT_DIR = Path.cwd().resolve()

Expand All @@ -16,7 +18,7 @@ def remove_file(filename):

def create_file(file):
filename = file + ".md"
filepath = PROJECT_DIR / "content" / filename
filepath = PROJECT_DIR / CONTENT_FOLDER / filename
dump(
f"# {file.capitalize()} [label]({file})\n\nInsert your content here (find this file at {filepath.resolve()})",
filepath,
Expand All @@ -30,15 +32,22 @@ def create_file(file):
create_file(file)

# add .. to path if relative to pylingdocs project
config = ConfigParser()
config.read(PROJECT_DIR / "pylingdocs.cfg")
path = "{{ cookiecutter.cldf }}"
if not path.startswith("/"):
path = Path("..") / path
config.set("paths", "cldf", str(path))
with open(PROJECT_DIR / "pylingdocs.cfg", "w", encoding="utf-8") as configfile:
config.write(configfile)


def relativize(path):
if not str(path).startswith("/"):
return Path("..") / path
return Path(path)


config = load(PROJECT_DIR / "config.yaml")
path = relativize("{{ cookiecutter.cldf }}")
config["paths"]["cldf"] = str(path)
dump(config, PROJECT_DIR / "config.yaml")

if "Yes" == "{{ cookiecutter.use_sublime_text }}":
ds = _load_cldf_dataset(path)
generate_autocomplete(ds, PROJECT_DIR)
while not path.is_file():
path = Path(input("Please enter a path to a metadata file: ").strip(" "))
else:
ds = load_cldf_dataset(path)
generate_autocomplete(ds, PROJECT_DIR)
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# {{cookiecutter.name}}

Welcome to your new pylingdocs project!
This file will be overwritten when running `pylingdocs build`.
Welcome to your new pylingdocs project!
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
paths:
cldf: {{ cookiecutter.cldf }}
input:
sublime: {{ cookiecutter.use_sublime_text }}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ id: {{cookiecutter.name}}
version: 0.0.1.draft
title: {{cookiecutter.title}}
authors:
- family-names: {{ cookiecutter.author_family_name }}
given-names: {{ cookiecutter.author_given_name }}{%if cookiecutter.orcid != ""%}
- family-names: {{ cookiecutter.family_name }}
given-names: {{ cookiecutter.given_name }}{%if cookiecutter.orcid != ""%}
orcid: {{cookiecutter.orcid}}{% endif %}{%if cookiecutter.email != ""%}
email: {{cookiecutter.email}}{% endif %}{%if cookiecutter.affiliation != ""%}
affiliation: {{cookiecutter.affiliation}}{% endif %}{%if cookiecutter.repository != ""%}
repository: {{cookiecutter.repository}}{% endif %}{%if cookiecutter.url != ""%}
url: {{cookiecutter.url}}{% endif %}
abstract: {{cookiecutter.abstract}}
keywords:
{% for kw in cookiecutter.keywords.split(",") %}- {{ kw }}
{% endfor %}license: CC-BY-SA-4.0
type: {{ cookiecutter.document_type }}
license: CC-BY-SA-4.0
type: {{ cookiecutter.layout }}

This file was deleted.

4 changes: 2 additions & 2 deletions src/pylingdocs/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,8 @@ def replace_commands(cls, content, **kwargs):
builders = {x.name: x for x in [PlainText, GitHub, Latex, HTML, CLLD, MkDocs]}


if Path("pld/formats.py").is_file():
sys.path.insert(1, "pld")
if Path(f"{PLD_DIR}/formats.py").is_file():
sys.path.insert(1, str(PLD_DIR))
from formats import formats

for fmt in formats:
Expand Down
8 changes: 5 additions & 3 deletions src/pylingdocs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def split_ref(s):
return bibkey, pages


def _load_cldf_dataset(cldf_path):
def load_cldf_dataset(cldf_path):
try:
ds = Dataset.from_metadata(cldf_path)
temp_path = Path(tempfile.gettempdir()) / "cldf"
Expand Down Expand Up @@ -423,7 +423,9 @@ def get_structure(structure_file, prefix_mode=None):
counters = {1: 0, 2: 0, 3: 0, 4: 0}
files = load(structure_file)
if not files:
log.error("Please create a structure.yaml file in your docs folder.")
log.error(
f"Please create a {STRUCTURE_FILE} file in your {CONTENT_FOLDER} folder."
)
sys.exit()
contents = {}
prefix_choices = ["alpha", "numerical"]
Expand Down Expand Up @@ -470,7 +472,7 @@ def write_content_file(
contents = get_structure(prefix_mode=prefix_mode, structure_file=structure_file)
if file_id not in contents:
log.error(
f"File with handle {file_id} not found, please check your structure.yaml file and your content files"
f"File with handle {file_id} not found, please check your {CONTENT_FOLDER}/{STRUCTURE_FILE} file and your content files"
)
raise ValueError
w_path = Path(source_dir) / contents[file_id]["filename"]
Expand Down
8 changes: 4 additions & 4 deletions src/pylingdocs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pycldf
from clldutils import jsonlib

from pylingdocs.config import DATA_DIR
from pylingdocs.config import DATA_DIR, PLD_DIR

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -68,7 +68,7 @@ def autocomplete_string(self, entry):
f"{self.shortcut}:{entry[label]}",
f"[{self.shortcut}]({entry['ID']})",
)
log.warning(f"Unable to generate preview string for {entry['ID']}")
log.warning(f"Unable to generate preview string for {self.name} {entry['ID']}")
return entry["ID"]


Expand Down Expand Up @@ -163,8 +163,8 @@ class Form(Base_ORM):
Form(),
]

if Path("pld/models.py").is_file():
sys.path.insert(1, "pld")
if Path(f"{PLD_DIR}/models.py").is_file():
sys.path.insert(1, str(PLD_DIR))
from models import models as custom_models

for mm in custom_models:
Expand Down
11 changes: 9 additions & 2 deletions src/pylingdocs/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
from jinja2 import DictLoader
from writio import load

from pylingdocs.config import DATA_DIR, MANEX_DIR, MD_LINK_PATTERN, TABLE_DIR, config
from pylingdocs.config import (
DATA_DIR,
MANEX_DIR,
MD_LINK_PATTERN,
TABLE_DIR,
config,
PLD_DIR,
)
from pylingdocs.helpers import (
comma_and_list,
func_dict,
Expand Down Expand Up @@ -38,7 +45,7 @@ def _load_templates(builder):
pld_util = load(DATA_DIR / "util.j2")

# for output_format, f_templates in templates.items():
util_path = Path(f"pld/model_templates/{builder.name}_util.md")
util_path = Path(f"{PLD_DIR}/model_templates/{builder.name}_util.md")
if not util_path.is_file():
util_path = DATA_DIR / "model_templates" / f"{builder.name}_util.md"
for loader in ["text", "data"]:
Expand Down

0 comments on commit 4da898b

Please sign in to comment.