-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔧 MAINTAIN: Add publishing job for
myst-docutils
(#456)
This commit adds a workflow for releasing an additional package `myst-docutils`, which does not include install requirements on docutils or sphinx. This will allow the docutils package to utilise it as a dependency, with no cyclic dependencies. The package is created by dynamically modifying the `setup.cfg` and `README.md` before the build. The build is also tested against a range of docutils versions, to ensure it does not fail due to the missing sphinx dependency.
- Loading branch information
1 parent
560f641
commit 894e8a9
Showing
2 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python3 | ||
"""Script to convert package setup to myst-docutils.""" | ||
import configparser | ||
import io | ||
import sys | ||
|
||
|
||
def modify_setup_cfg(content: str) -> str: | ||
"""Modify setup.cfg.""" | ||
cfg = configparser.ConfigParser() | ||
cfg.read_string(content) | ||
# change name of package | ||
cfg.set("metadata", "name", "myst-docutils") | ||
# move dependency on docutils and sphinx to extra | ||
install_requires = [] | ||
sphinx_extra = [""] | ||
for line in cfg.get("options", "install_requires").splitlines(): | ||
if line.startswith("docutils"): | ||
sphinx_extra.append(line) | ||
elif line.startswith("sphinx"): | ||
sphinx_extra.append(line) | ||
else: | ||
install_requires.append(line) | ||
cfg.set("options", "install_requires", "\n".join(install_requires)) | ||
cfg.set("options.extras_require", "sphinx", "\n".join(sphinx_extra)) | ||
|
||
stream = io.StringIO() | ||
cfg.write(stream) | ||
return stream.getvalue() | ||
|
||
|
||
def modify_readme(content: str) -> str: | ||
"""Modify README.md.""" | ||
content = content.replace( | ||
"# MyST-Parser", | ||
"# MyST-Parser\n\nNote: myst-docutils is identical to myst-parser, " | ||
"but without installation requirements on sphinx", | ||
) | ||
content = content.replace("myst-parser", "myst-docutils") | ||
content = content.replace("myst-docutils.readthedocs", "myst-parser.readthedocs") | ||
content = content.replace( | ||
"readthedocs.org/projects/myst-docutils", "readthedocs.org/projects/myst-parser" | ||
) | ||
return content | ||
|
||
|
||
if __name__ == "__main__": | ||
setup_path = sys.argv[1] | ||
readme_path = sys.argv[2] | ||
with open(setup_path, "r") as f: | ||
content = f.read() | ||
content = modify_setup_cfg(content) | ||
with open(setup_path, "w") as f: | ||
f.write(content) | ||
with open(readme_path, "r") as f: | ||
content = f.read() | ||
content = modify_readme(content) | ||
with open(readme_path, "w") as f: | ||
f.write(content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters