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

🔧 MAINTAIN: Move from setuptools to flit #553

Merged
merged 5 commits into from
Apr 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 21 additions & 24 deletions .github/workflows/docutils_setup.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
#!/usr/bin/env python3
"""Script to convert package setup to myst-docutils."""
import configparser
import io
import sys

import tomlkit


def modify_toml(content: str) -> str:
"""Modify `pyproject.toml`."""
doc = tomlkit.parse(content)

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")
doc["project"]["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)
dependencies = []
sphinx_extra = []
for dep in doc["project"]["dependencies"]:
if dep.startswith("docutils") or dep.startswith("sphinx"):
sphinx_extra.append(dep)
else:
install_requires.append(line)
cfg.set("options", "install_requires", "\n".join(install_requires))
cfg.set("options.extras_require", "sphinx", "\n".join(sphinx_extra))
dependencies.append(dep)
doc["project"]["dependencies"] = dependencies
doc["project"]["optional-dependencies"]["sphinx"] = sphinx_extra

stream = io.StringIO()
cfg.write(stream)
return stream.getvalue()
return tomlkit.dumps(doc)


def modify_readme(content: str) -> str:
Expand All @@ -45,12 +42,12 @@ def modify_readme(content: str) -> str:


if __name__ == "__main__":
setup_path = sys.argv[1]
project_path = sys.argv[1]
readme_path = sys.argv[2]
with open(setup_path, "r") as f:
with open(project_path, "r") as f:
content = f.read()
content = modify_setup_cfg(content)
with open(setup_path, "w") as f:
content = modify_toml(content)
with open(project_path, "w") as f:
f.write(content)
with open(readme_path, "r") as f:
content = f.read()
Expand Down
41 changes: 22 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: "3.8"
- name: Install setup
run: |
python -m pip install --upgrade pip
pip install tomlkit
- name: Modify setup
run: python .github/workflows/docutils_setup.py setup.cfg README.md
run: python .github/workflows/docutils_setup.py pyproject.toml README.md
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install pytest~=6.2 pytest-param-files~=0.3.3 docutils==${{ matrix.docutils-version }}
- name: ensure sphinx is not installed
Expand Down Expand Up @@ -114,15 +117,15 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: "3.8"
- name: Build package
- name: install flit
run: |
pip install build
python -m build
- name: Publish
uses: pypa/gh-action-pypi-publish@v1.3.1
with:
user: __token__
password: ${{ secrets.PYPI_KEY }}
pip install flit~=3.4
- name: Build and publish
run: |
flit publish
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.PYPI_KEY }}

publish-docutils:

Expand All @@ -137,14 +140,14 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: "3.8"
- name: install flit and tomlkit
run: |
pip install flit~=3.4 tomlkit
- name: Modify setup
run: python .github/workflows/docutils_setup.py setup.cfg README.md
- name: Build package
run: python .github/workflows/docutils_setup.py pyproject.toml README.md
- name: Build and publish
run: |
pip install build
python -m build
- name: Publish
uses: pypa/gh-action-pypi-publish@v1.3.1
with:
user: __token__
password: ${{ secrets.PYPI_KEY_DOCUTILS }}
flit publish
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.PYPI_KEY }}
16 changes: 1 addition & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/mgedmin/check-manifest
rev: "0.48"
hooks:
- id: check-manifest
args: [--no-build-isolation]
additional_dependencies: [setuptools>=46.4.0]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
Expand All @@ -49,7 +42,7 @@ repos:
rev: v0.942
hooks:
- id: mypy
args: [--config-file=setup.cfg]
args: [--config-file=pyproject.toml]
additional_dependencies:
- sphinx~=3.3
- markdown-it-py>=1.0.0,<3.0.0
Expand All @@ -58,10 +51,3 @@ repos:
(?x)^(
myst_parser/.*py|
)$

# this is not used for now,
# since it converts myst-parser to myst_parser and removes comments
# - repo: https://github.com/asottile/setup-cfg-fmt
# rev: v1.17.0
# hooks:
# - id: setup-cfg-fmt
16 changes: 0 additions & 16 deletions MANIFEST.in

This file was deleted.

1 change: 1 addition & 0 deletions myst_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""An extended commonmark compliant parser, with bridges to docutils & sphinx."""
from typing import TYPE_CHECKING

__version__ = "0.17.0"
Expand Down
101 changes: 99 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,107 @@
[build-system]
requires = ["setuptools>=46.4.0", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["flit_core >=3.4,<4"]
build-backend = "flit_core.buildapi"

[project]
name = "myst-parser"
dynamic = ["version", "description"]
authors = [{name = "Chris Sewell", email = "chrisj_sewell@hotmail.com"}]
readme = "README.md"
license = {file = "LICENSE"}
classifiers = [
"Development Status :: 4 - Beta",
"Framework :: Sphinx :: Extension",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Text Processing :: Markup",
]
keywords = [
"markdown",
"lexer",
"parser",
"development",
"docutils",
"sphinx",
]
requires-python = ">=3.7"
dependencies = [
"docutils>=0.15,<0.18",
"jinja2", # required for substitutions, but let sphinx choose version
"markdown-it-py>=1.0.0,<3.0.0",
"mdit-py-plugins~=0.3.0",
"pyyaml",
"sphinx>=3.1,<5",
"typing-extensions",
]

[project.urls]
Homepage = "https://github.com/executablebooks/MyST-Parser"
Documentation = "https://myst-parser.readthedocs.io"

[project.optional-dependencies]
code_style = ["pre-commit~=2.12"]
# for use with "linkify" extension
linkify = ["linkify-it-py~=1.0"]
# Note: This is only required for internal use
rtd = [
"ipython",
"sphinx-book-theme",
"sphinx-panels",
"sphinxcontrib-bibtex~=2.4",
"sphinxext-rediraffe~=0.2.7",
"sphinxcontrib.mermaid~=0.7.1",
"sphinxext-opengraph~=0.6.3",
]
testing = [
"beautifulsoup4",
"coverage",
"docutils~=0.17.0", # this version changes some HTML tags
"pytest>=6,<7",
"pytest-cov",
"pytest-regressions",
"pytest-param-files~=0.3.4",
]

[project.scripts]
myst-anchors = "myst_parser.cli:print_anchors"
myst-docutils-html = "myst_parser.docutils_:cli_html"
myst-docutils-html5 = "myst_parser.docutils_:cli_html5"
myst-docutils-latex = "myst_parser.docutils_:cli_latex"
myst-docutils-xml = "myst_parser.docutils_:cli_xml"
myst-docutils-pseudoxml = "myst_parser.docutils_:cli_pseudoxml"

[tool.flit.module]
name = "myst_parser"

[tool.flit.sdist]
exclude = [
"docs/",
"tests/",
]

[tool.isort]
profile = "black"
known_first_party = ["myst_parser", "tests"]
known_third_party = ["docutils", "markdown_it", "sphinx"]
# Group first party and local folder imports together
no_lines_before = "LOCALFOLDER"

[tool.mypy]
show_error_codes = true
check_untyped_defs = true
strict_equality = true
no_implicit_optional = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = ["docutils.*", "yaml.*"]
ignore_missing_imports = true
99 changes: 0 additions & 99 deletions setup.cfg

This file was deleted.