aboutsummaryrefslogtreecommitdiffstats
path: root/setup.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan.limberg@icloud.com>2017-12-06 23:18:29 -0500
committerGitHub <noreply@github.com>2017-12-06 23:18:29 -0500
commitb62ddeda02fadcd09def9354eb2ef46a7562a106 (patch)
tree37149361ca1eeb8c24942835b2f933105fa920ed /setup.py
parentde5c696f94e8dde242c29d4be50b7bbf3c17fedb (diff)
downloadmarkdown-b62ddeda02fadcd09def9354eb2ef46a7562a106.tar.gz
markdown-b62ddeda02fadcd09def9354eb2ef46a7562a106.tar.bz2
markdown-b62ddeda02fadcd09def9354eb2ef46a7562a106.zip
Switch docs to MKDocs (#602)
Fixes #601. Merged in 6f87b32 from the md3 branch and did a lot of cleanup. Changes include: * Removed old docs build tool, templates, etc. * Added MkDocs config file, etc. * filename.txt => filename.md * pythonhost.org/Markdown => Python-Markdown.github.io * Markdown lint and other cleanup. * Automate pages deployment in makefile with `mkdocs gh-deploy` Assumes a git remote is set up named "pages". Do git remote add pages https://github.com/Python-Markdown/Python-Markdown.github.io.git ... before running `make deploy` the first time.
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py158
1 files changed, 4 insertions, 154 deletions
diff --git a/setup.py b/setup.py
index 3821c6c..fba5172 100755
--- a/setup.py
+++ b/setup.py
@@ -5,10 +5,6 @@ import sys
import os
from distutils.core import setup
from distutils.command.install_scripts import install_scripts
-from distutils.command.build import build
-from distutils.core import Command
-from distutils.util import change_root, newer
-import codecs
import imp
@@ -68,150 +64,6 @@ class md_install_scripts(install_scripts):
print('ERROR: Unable to create %s: %s' % (bat_path, err))
-class build_docs(Command):
-
- """ Build markdown documentation into html."""
-
- description = '"build" documentation (convert markdown text to html)'
-
- user_options = [
- ('build-base=', 'd', 'directory to "build" to'),
- ('force', 'f', 'forcibly build everything (ignore file timestamps)'),
- ]
-
- boolean_options = ['force']
-
- def initialize_options(self):
- self.build_base = None
- self.force = None
- self.docs = None
- self.sitemap = ''
-
- def finalize_options(self):
- self.set_undefined_options(
- 'build',
- ('build_base', 'build_base'),
- ('force', 'force')
- )
- self.docs = self._get_docs()
-
- def _get_docs(self):
- for root, dirs, files in os.walk('docs'):
- for file in files:
- if not file.startswith('_'):
- path = os.path.join(root, file)
- yield path
-
- def _get_context(self, src, path):
- """ Build and return context to pass to template. """
- # set defaults
- c = {
- 'title': '',
- 'prev_url': '',
- 'prev_title': '',
- 'next_url': '',
- 'next_title': '',
- 'crumb': '',
- 'version': version,
- }
- c['body'] = self.md.convert(src)
- c['toc'] = self.md.toc
- for k, v in self.md.Meta.items():
- c[k] = ' '.join(v)
- self.md.reset()
- # Manipulate path
- path = path[len(os.path.join(self.build_base, 'docs/')):]
- dir, file = os.path.split(path)
- name, ext = os.path.splitext(file)
- parts = [x for x in dir.split(os.sep) if x]
- c['source'] = '%s.txt' % name
- c['base'] = '../' * len(parts)
- # Build page title
- if name.lower() != 'index' or parts:
- c['page_title'] = '%s &#8212; Python Markdown' % c['title']
- else:
- c['page_title'] = 'Python Markdown'
- # Build crumb trail
- crumbs = []
- ctemp = '<li><a href="%s">%s</a> &raquo;</li>'
- for n, part in enumerate(parts):
- href = ('../' * n) + 'index.html'
- label = part.replace('_', ' ').capitalize()
- crumbs.append(ctemp % (href, label))
- if c['title'] and name.lower() != 'index':
- crumbs.append(ctemp % (file, c['title']))
- c['crumb'] = '\n'.join(crumbs)
- return c
-
- def run(self):
- # Before importing markdown, tweak sys.path to import from the
- # build directory (2to3 might have run on the library).
- bld_cmd = self.get_finalized_command("build")
- sys.path.insert(0, bld_cmd.build_lib)
- try:
- import markdown
- except ImportError:
- print('skipping build_docs: Markdown "import" failed!')
- else:
- with codecs.open('docs/_template.html', encoding='utf-8') as f:
- template = f.read()
- self.md = markdown.Markdown(
- extensions=[
- 'extra',
- 'toc(permalink=true)',
- 'meta',
- 'admonition',
- 'smarty'
- ]
- )
- for infile in self.docs:
- outfile, ext = os.path.splitext(infile)
- if ext == '.txt':
- # Copy src to .txt file
- srcfile = outfile + '.txt'
- srcfile = change_root(self.build_base, srcfile)
- self.mkpath(os.path.split(srcfile)[0])
- self.copy_file(infile, srcfile)
- # Render html file
- outfile += '.html'
- outfile = change_root(self.build_base, outfile)
- self.mkpath(os.path.split(outfile)[0])
- if self.force or newer(infile, outfile):
- if self.verbose:
- print('Converting %s -> %s' % (infile, outfile))
- if not self.dry_run:
- with codecs.open(infile, encoding='utf-8') as f:
- src = f.read()
- out = template % self._get_context(src, outfile)
- doc = open(outfile, 'wb')
- doc.write(out.encode('utf-8'))
- doc.close()
- else:
- outfile = change_root(self.build_base, infile)
- self.mkpath(os.path.split(outfile)[0])
- self.copy_file(infile, outfile)
-
-
-class md_build(build):
-
- """ Run "build_docs" command from "build" command. """
-
- user_options = build.user_options + [
- ('no-build-docs', None, 'do not build documentation'),
- ]
-
- boolean_options = build.boolean_options + ['build-docs']
-
- def initialize_options(self):
- build.initialize_options(self)
- self.no_build_docs = False
-
- def has_docs(self):
- return not self.no_build_docs
-
- sub_commands = build.sub_commands + [('build_docs', has_docs)]
-
-
long_description = '''
This is a Python implementation of John Gruber's Markdown_.
It is almost completely compliant with the reference implementation,
@@ -220,8 +72,8 @@ on what exactly is supported and what is not. Additional features are
supported by the `Available Extensions`_.
.. _Markdown: http://daringfireball.net/projects/markdown/
-.. _Features: https://pythonhosted.org/Markdown/index.html#Features
-.. _`Available Extensions`: https://pythonhosted.org/Markdown/extensions/index.html
+.. _Features: https://Python-Markdown.github.io#Features
+.. _`Available Extensions`: https://Python-Markdown.github.io/extensions/
Support
=======
@@ -236,7 +88,7 @@ You may ask for help and discuss various other issues on the
setup(
name='Markdown',
version=version,
- url='https://pythonhosted.org/Markdown/',
+ url='https://Python-Markdown.github.io/',
download_url='http://pypi.python.org/packages/source/M/Markdown/Markdown-%s.tar.gz' % version,
description='Python implementation of Markdown.',
long_description=long_description,
@@ -248,9 +100,7 @@ setup(
packages=['markdown', 'markdown.extensions'],
scripts=['bin/%s' % SCRIPT_NAME],
cmdclass={
- 'install_scripts': md_install_scripts,
- 'build_docs': build_docs,
- 'build': md_build
+ 'install_scripts': md_install_scripts
},
classifiers=[
'Development Status :: %s' % DEVSTATUS,