Skip to content

Commit 1888c9e

Browse files
fix: ap sync by avoiding duplicate comments in myst.yml and update pyproject.toml using website_url in afterpython.toml
1 parent 9b85292 commit 1888c9e

File tree

12 files changed

+90
-81
lines changed

12 files changed

+90
-81
lines changed

afterpython/afterpython.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ name = "AfterPython.Org" # used in myst.yml's venue.title
44
url = "https://afterpython.org" # used in myst.yml's venue.url
55

66
[website]
7-
url = "https://ap.afterpython.org"
7+
url = "https://afterpython.afterpython.org"

afterpython/blog/myst.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ project:
1414
# See more authors' fields at: https://mystmd.org/guide/frontmatter#frontmatter-authors
1515
authors:
1616
- stephen_yau
17-
# See more venue's fields at: https://mystmd.org/guide/frontmatter#venue
1817
venue:
1918
title: AfterPython.Org
2019
url: https://afterpython.org
@@ -46,20 +45,19 @@ site:
4645
logo_dark: ../static/logo.svg
4746
analytics_google: '{{ GOOGLE_ANALYTICS_ID }}'
4847
logo_text: afterpython
49-
logo_url: https://ap.afterpython.org
48+
logo_url: https://afterpython.afterpython.org
5049
title: afterpython's Blog
5150
nav:
5251
- title: Docs
53-
url: https://ap.afterpython.org/doc
52+
url: https://afterpython.afterpython.org/doc
5453
- title: Blogs
55-
url: https://ap.afterpython.org/blog
54+
url: https://afterpython.afterpython.org/blog
5655
- title: Tutorials
57-
url: https://ap.afterpython.org/tutorial
56+
url: https://afterpython.afterpython.org/tutorial
5857
- title: Examples
59-
url: https://ap.afterpython.org/example
58+
url: https://afterpython.afterpython.org/example
6059
- title: Guides
61-
url: https://ap.afterpython.org/guide
62-
# See web layout at: https://mystmd.org/guide/website-navigation
60+
url: https://afterpython.afterpython.org/guide
6361
actions:
6462
- title: ⭐ Star
6563
url: https://github.com/AfterPythonOrg/afterpython

afterpython/cli/commands/sync.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import click
44
from pyproject_metadata import StandardMetadata
5+
from tomlkit.toml_document import TOMLDocument
56

67
import afterpython as ap
78
from afterpython.utils import convert_author_name_to_id
@@ -38,7 +39,11 @@ def sync():
3839
"""Sync between pyproject.toml+afterpython.toml and authors.yml+myst.yml files"""
3940
from afterpython.const import CONTENT_TYPES
4041
from afterpython.tools._afterpython import read_afterpython
41-
from afterpython.tools.pyproject import read_metadata
42+
from afterpython.tools.pyproject import (
43+
read_metadata,
44+
read_pyproject,
45+
write_pyproject,
46+
)
4247
from afterpython._io.toml import _from_tomlkit
4348
from afterpython.tools.myst import update_myst_yml
4449

@@ -62,6 +67,13 @@ def sync():
6267

6368
_sync_authors_yml(authors)
6469

70+
# update "homepage", "repository", and "documentation" in pyproject.toml
71+
if website_url:
72+
doc: TOMLDocument = read_pyproject()
73+
doc["project"]["urls"]["homepage"] = website_url
74+
doc["project"]["urls"]["documentation"] = f"{website_url}/doc"
75+
write_pyproject(doc)
76+
6577
# update myst.yml files for each content type (e.g. doc/, blog/, tutorial/, example/, guide/)
6678
# based on the current values in pyproject.toml and afterpython.toml
6779
for content_type in CONTENT_TYPES:

afterpython/doc/myst.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,20 @@ site:
5757
logo: ../static/logo.svg
5858
logo_dark: ../static/logo.svg
5959
logo_text: afterpython
60-
logo_url: https://ap.afterpython.org
60+
logo_url: https://afterpython.afterpython.org
6161
analytics_google: "{{ GOOGLE_ANALYTICS_ID }}"
6262
title: afterpython's Doc
6363
nav:
6464
- title: Docs
65-
url: https://ap.afterpython.org/doc
65+
url: https://afterpython.afterpython.org/doc
6666
- title: Blogs
67-
url: https://ap.afterpython.org/blog
67+
url: https://afterpython.afterpython.org/blog
6868
- title: Tutorials
69-
url: https://ap.afterpython.org/tutorial
69+
url: https://afterpython.afterpython.org/tutorial
7070
- title: Examples
71-
url: https://ap.afterpython.org/example
71+
url: https://afterpython.afterpython.org/example
7272
- title: Guides
73-
url: https://ap.afterpython.org/guide
74-
# See web layout at: https://mystmd.org/guide/website-navigation
73+
url: https://afterpython.afterpython.org/guide
7574
actions:
7675
- title: ⭐ Star
7776
url: https://github.com/AfterPythonOrg/afterpython

afterpython/doc/project_website.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Project Website
55

6-
> The project website for `afterpython` is created using `afterpython` itself. See the [**website**](https://ap.afterpython.org).
6+
> The project website for `afterpython` is created using `afterpython` itself. See the [**website**](https://afterpython.afterpython.org).
77
88
## Definition
99
On [PyPI], you typically see three urls under **Project Links**,

afterpython/doc/references/roadmap.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
This roadmap is tentative and subject to change
55
```
66

7-
- full-text search engine using pagefind
7+
- integrate with `pdoc` for API reference generation
88
- AI chatbot like kapa.ai using WebLLM
9+
- full-text search engine using pagefind
910
- incremental build, only build changed content (for `ap dev`)
1011
- integrate with `git-cliff` for changelog generation
1112
- integrate with `pixi`, supports `conda install`

afterpython/example/myst.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ project:
1414
# See more authors' fields at: https://mystmd.org/guide/frontmatter#frontmatter-authors
1515
authors:
1616
- stephen_yau
17-
# See more venue's fields at: https://mystmd.org/guide/frontmatter#venue
1817
venue:
1918
title: AfterPython.Org
2019
url: https://afterpython.org
@@ -46,20 +45,19 @@ site:
4645
logo_dark: ../static/logo.svg
4746
analytics_google: '{{ GOOGLE_ANALYTICS_ID }}'
4847
logo_text: afterpython
49-
logo_url: https://ap.afterpython.org
48+
logo_url: https://afterpython.afterpython.org
5049
title: afterpython's Example
5150
nav:
5251
- title: Docs
53-
url: https://ap.afterpython.org/doc
52+
url: https://afterpython.afterpython.org/doc
5453
- title: Blogs
55-
url: https://ap.afterpython.org/blog
54+
url: https://afterpython.afterpython.org/blog
5655
- title: Tutorials
57-
url: https://ap.afterpython.org/tutorial
56+
url: https://afterpython.afterpython.org/tutorial
5857
- title: Examples
59-
url: https://ap.afterpython.org/example
58+
url: https://afterpython.afterpython.org/example
6059
- title: Guides
61-
url: https://ap.afterpython.org/guide
62-
# See web layout at: https://mystmd.org/guide/website-navigation
60+
url: https://afterpython.afterpython.org/guide
6361
actions:
6462
- title: ⭐ Star
6563
url: https://github.com/AfterPythonOrg/afterpython

afterpython/guide/myst.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ project:
1414
# See more authors' fields at: https://mystmd.org/guide/frontmatter#frontmatter-authors
1515
authors:
1616
- stephen_yau
17-
# See more venue's fields at: https://mystmd.org/guide/frontmatter#venue
1817
venue:
1918
title: AfterPython.Org
2019
url: https://afterpython.org
@@ -46,20 +45,19 @@ site:
4645
logo_dark: ../static/logo.svg
4746
analytics_google: '{{ GOOGLE_ANALYTICS_ID }}'
4847
logo_text: afterpython
49-
logo_url: https://ap.afterpython.org
48+
logo_url: https://afterpython.afterpython.org
5049
title: afterpython's Guide
5150
nav:
5251
- title: Docs
53-
url: https://ap.afterpython.org/doc
52+
url: https://afterpython.afterpython.org/doc
5453
- title: Blogs
55-
url: https://ap.afterpython.org/blog
54+
url: https://afterpython.afterpython.org/blog
5655
- title: Tutorials
57-
url: https://ap.afterpython.org/tutorial
56+
url: https://afterpython.afterpython.org/tutorial
5857
- title: Examples
59-
url: https://ap.afterpython.org/example
58+
url: https://afterpython.afterpython.org/example
6059
- title: Guides
61-
url: https://ap.afterpython.org/guide
62-
# See web layout at: https://mystmd.org/guide/website-navigation
60+
url: https://afterpython.afterpython.org/guide
6361
actions:
6462
- title: ⭐ Star
6563
url: https://github.com/AfterPythonOrg/afterpython

afterpython/tools/myst.py

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def update_authors_yml(data_update: dict):
4848
write_yaml(file_path, existing_data)
4949

5050

51-
def update_myst_yml(data_update: dict, path: Path):
51+
def update_myst_yml(data_update: dict, path: Path, add_comments: bool = False):
5252
"""Update myst.yml while preserving order and formatting
5353
5454
Args:
@@ -64,36 +64,39 @@ def update_myst_yml(data_update: dict, path: Path):
6464
)
6565

6666
existing_data = read_yaml(file_path) or {}
67-
existing_data = deep_merge(existing_data, data_update)
68-
69-
# set comments for project section for convenience
70-
if "project" in existing_data:
71-
if not existing_data["project"].ca.items.get("id"):
72-
existing_data["project"].yaml_set_comment_before_after_key(
73-
"id",
74-
before="See how to create Table of Contents at: https://mystmd.org/guide/table-of-contents",
75-
)
76-
if not existing_data["project"].ca.items.get("authors"):
77-
existing_data["project"].yaml_set_comment_before_after_key(
78-
"authors",
79-
before="See more authors' fields at: https://mystmd.org/guide/frontmatter#frontmatter-authors",
80-
)
81-
if not existing_data["project"].ca.items.get("venue"):
82-
existing_data["project"].yaml_set_comment_before_after_key(
83-
"venue",
84-
before="See more venue's fields at: https://mystmd.org/guide/frontmatter#venue",
85-
)
86-
if "site" in existing_data:
87-
if not existing_data["site"].ca.items.get("options"):
88-
existing_data["site"].yaml_set_comment_before_after_key(
89-
"options",
90-
before="See options at: https://mystmd.org/guide/website-templates#site-options",
91-
)
92-
if not existing_data["site"].ca.items.get("actions"):
93-
existing_data["site"].yaml_set_comment_before_after_key(
94-
"actions",
95-
before="See web layout at: https://mystmd.org/guide/website-navigation",
96-
)
67+
existing_data = deep_merge(existing_data, data_update, extend_lists=False)
68+
69+
# NOTE: this checking existing_data["key1"].ca.items.get("key2") is buggy
70+
# only add_comments=True during init to avoid adding duplicate comments
71+
if add_comments:
72+
# set comments for project section for convenience
73+
if "project" in existing_data:
74+
if not existing_data["project"].ca.items.get("id"):
75+
existing_data["project"].yaml_set_comment_before_after_key(
76+
"id",
77+
before="See how to create Table of Contents at: https://mystmd.org/guide/table-of-contents",
78+
)
79+
if not existing_data["project"].ca.items.get("authors"):
80+
existing_data["project"].yaml_set_comment_before_after_key(
81+
"authors",
82+
before="See more authors' fields at: https://mystmd.org/guide/frontmatter#frontmatter-authors",
83+
)
84+
if not existing_data["project"].ca.items.get("venue"):
85+
existing_data["project"].yaml_set_comment_before_after_key(
86+
"venue",
87+
before="See more venue's fields at: https://mystmd.org/guide/frontmatter#venue",
88+
)
89+
if "site" in existing_data:
90+
if not existing_data["site"].ca.items.get("options"):
91+
existing_data["site"].yaml_set_comment_before_after_key(
92+
"options",
93+
before="See options at: https://mystmd.org/guide/website-templates#site-options",
94+
)
95+
if not existing_data["site"].ca.items.get("actions"):
96+
existing_data["site"].yaml_set_comment_before_after_key(
97+
"actions",
98+
before="See web layout at: https://mystmd.org/guide/website-navigation",
99+
)
97100

98101
write_yaml(file_path, existing_data)
99102

@@ -116,7 +119,7 @@ def _write_welcome_file(content_type: tContentType):
116119
117120
## Resources
118121
119-
- [AfterPython's Project Website](https://ap.afterpython.org)
122+
- [AfterPython's Project Website](https://afterpython.afterpython.org)
120123
- [MyST Markdown Guide](https://mystmd.org)
121124
122125
Start building your amazing project! 🚀
@@ -159,6 +162,6 @@ def init_myst():
159162
},
160163
},
161164
}
162-
update_myst_yml(myst_yml_defaults, path)
165+
update_myst_yml(myst_yml_defaults, path, add_comments=True)
163166
_write_welcome_file(content_type)
164167
subprocess.run(["ap", "sync"])

afterpython/tutorial/myst.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ project:
1414
# See more authors' fields at: https://mystmd.org/guide/frontmatter#frontmatter-authors
1515
authors:
1616
- stephen_yau
17-
# See more venue's fields at: https://mystmd.org/guide/frontmatter#venue
1817
venue:
1918
title: AfterPython.Org
2019
url: https://afterpython.org
@@ -46,20 +45,19 @@ site:
4645
logo_dark: ../static/logo.svg
4746
analytics_google: '{{ GOOGLE_ANALYTICS_ID }}'
4847
logo_text: afterpython
49-
logo_url: https://ap.afterpython.org
48+
logo_url: https://afterpython.afterpython.org
5049
title: afterpython's Tutorial
5150
nav:
5251
- title: Docs
53-
url: https://ap.afterpython.org/doc
52+
url: https://afterpython.afterpython.org/doc
5453
- title: Blogs
55-
url: https://ap.afterpython.org/blog
54+
url: https://afterpython.afterpython.org/blog
5655
- title: Tutorials
57-
url: https://ap.afterpython.org/tutorial
56+
url: https://afterpython.afterpython.org/tutorial
5857
- title: Examples
59-
url: https://ap.afterpython.org/example
58+
url: https://afterpython.afterpython.org/example
6059
- title: Guides
61-
url: https://ap.afterpython.org/guide
62-
# See web layout at: https://mystmd.org/guide/website-navigation
60+
url: https://afterpython.afterpython.org/guide
6361
actions:
6462
- title: ⭐ Star
6563
url: https://github.com/AfterPythonOrg/afterpython

0 commit comments

Comments
 (0)