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 a static CONTRIBUTING.md template #27

Merged
merged 6 commits into from
Sep 18, 2021
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 docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,5 @@
"pandas": ("https://pandas.pydata.org/pandas-docs/stable", None),
"scipy": ("https://docs.scipy.org/doc/scipy/", None),
"pyscaffold": ("https://pyscaffold.org/en/stable", None),
"rst_to_myst": ("https://rst-to-myst.readthedocs.io/en/stable", None),
}
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ python_requires = >=3.6
# TODO: Remove conditional dependencies according to `python_requires` above
install_requires =
importlib-metadata; python_version<"3.8"
pyscaffold>=4.0.1,<5.0a0
pyscaffold>=4.1rc1,<5.0a0
wheel>=0.31
myst-parser[linkify]
# rst-to-myst[sphinx]>=0.3.2 # see issue #25


[options.packages.find]
Expand Down
55 changes: 36 additions & 19 deletions src/pyscaffoldext/markdown/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

DOC_REQUIREMENTS = ["myst-parser[linkify]"]


template = partial(get_template, relative_to=templates)


Expand Down Expand Up @@ -121,37 +122,53 @@ def replace_files(struct: Structure, opts: ScaffoldOpts) -> ActionParams:
"""Replace all rst files to proper md and activate Sphinx md.
See :obj:`pyscaffold.actions.Action`
"""
# Define new files
NO_OVERWRITE = no_overwrite()
files: Structure = {
"README.md": (template("readme"), NO_OVERWRITE),
"AUTHORS.md": (template("authors"), NO_OVERWRITE),
"CHANGELOG.md": (template("changelog"), NO_OVERWRITE),
"CONTRIBUTING.md": (template("contributing"), NO_OVERWRITE),
"docs": {
"index.md": (template("index"), NO_OVERWRITE),
"readme.md": (default_myst_include("README.md"), NO_OVERWRITE),
"license.md": (template("license"), NO_OVERWRITE),
"authors.md": (default_myst_include("AUTHORS.md"), NO_OVERWRITE),
"changelog.md": (default_myst_include("CHANGELOG.md"), NO_OVERWRITE),
"contributing.md": (default_myst_include("CONTRIBUTING.md"), NO_OVERWRITE),
},
}

# TODO: Automatically convert RST to MD
#
# >>> content, file_op = reify_leaf(struct.get("CONTRIBUTING.rst"), opts)
# >>> md_content = rst_to_myst(content or "", **RST2MYST_OPTS).text
# >>> files["CONTRIBUTING.md"] = (md_content, file_op)
#
# Currently there is a problem in rst-to-myst, preventing automatic conversion:
# https://github.com/executablebooks/rst-to-myst/issues/33#issuecomment-922264030

# Modify pre-existing files
content, file_op = reify_leaf(struct["setup.cfg"], opts)
files["setup.cfg"] = (add_long_desc(content), file_op)

content, file_op = reify_leaf(struct["docs"]["conf.py"], opts)
files["docs"]["conf.py"] = (add_myst(content), file_op)

# Remove all unnecessary .rst files from struct
unnecessary = [
"README.rst",
"AUTHORS.rst",
"CHANGELOG.rst",
"CONTRIBUTING.rst",
"docs/index.rst",
"docs/readme.rst",
"docs/license.rst",
"docs/authors.rst",
"docs/changelog.rst",
"docs/contributing.rst",
]
struct = reduce(reject, unnecessary, struct)
content, file_op = reify_leaf(struct["setup.cfg"], opts)
struct["setup.cfg"] = (add_long_desc(content), file_op)

content, file_op = reify_leaf(struct["docs"]["conf.py"], opts)

# Define replacement files/links
files: Structure = {
"README.md": (template("readme"), no_overwrite()),
"AUTHORS.md": (template("authors"), no_overwrite()),
"CHANGELOG.md": (template("changelog"), no_overwrite()),
"docs": {
"conf.py": (add_myst(content), file_op),
"index.md": (template("index"), no_overwrite()),
"readme.md": (default_myst_include("README.md"), no_overwrite()),
"license.md": (template("license"), no_overwrite()),
"authors.md": (default_myst_include("AUTHORS.md"), no_overwrite()),
"changelog.md": (default_myst_include("CHANGELOG.md"), no_overwrite()),
},
}

return merge(struct, files), opts

Expand Down
Loading