Skip to content

Commit 975b216

Browse files
committed
Removed six dependency.
1 parent 61a0088 commit 975b216

28 files changed

+99
-55
lines changed

docs/about/release-notes.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ You can determine your currently installed version using `mkdocs --version`:
1515

1616
## Version 0.14.0 (2015-??-??)
1717

18+
* Remove dependancy on the six library. (#583)
1819
* Add `--quiet` and `--verbose` options to all subcommands.
1920
* Add short options (`-a`) to most command line options.
2021

mkdocs/build.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# coding: utf-8
22

3+
from __future__ import unicode_literals
34
from datetime import datetime
45
import io
56
import logging
@@ -8,7 +9,6 @@
89
from jinja2.exceptions import TemplateNotFound
910
import jinja2
1011
import json
11-
import six
1212

1313
from mkdocs import nav, search, utils
1414
from mkdocs.relative_path_ext import RelativePathExtension
@@ -109,7 +109,7 @@ def get_page_context(page, content, toc, meta, config):
109109
base = config['site_url']
110110
if not base.endswith('/'):
111111
base += '/'
112-
canonical_url = six.moves.urllib.parse.urljoin(
112+
canonical_url = utils.urljoin(
113113
base, page.abs_url.lstrip('/'))
114114
else:
115115
canonical_url = None

mkdocs/cli.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4+
from __future__ import unicode_literals
45
import logging
56
import click
67

mkdocs/config/base.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
from __future__ import unicode_literals
12
import logging
23
import os
3-
4-
import six
54
import yaml
65

76
from mkdocs import exceptions
7+
from mkdocs import utils
88

99

1010
log = logging.getLogger('mkdocs.config')
@@ -14,7 +14,7 @@ class ValidationError(Exception):
1414
"""Raised during the validation process of the config on errors."""
1515

1616

17-
class Config(six.moves.UserDict):
17+
class Config(utils.UserDict):
1818
"""
1919
MkDocs Configuration dict
2020
@@ -106,7 +106,7 @@ def _open_config_file(config_file):
106106
log.debug("Loading configuration file: %s", config_file)
107107

108108
# If it is a string, we can assume it is a path and attempt to open it.
109-
if isinstance(config_file, six.string_types):
109+
if isinstance(config_file, utils.string_types):
110110
if os.path.exists(config_file):
111111
config_file = open(config_file, 'rb')
112112
else:

mkdocs/config/config_options.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
from __future__ import unicode_literals
12
import os
23

3-
import six
4-
54
from mkdocs import utils, legacy
65
from mkdocs.config.base import Config, ValidationError
76

@@ -164,7 +163,7 @@ class URL(OptionallyRequired):
164163
def run_validation(self, value):
165164

166165
try:
167-
parsed_url = six.moves.urllib.parse.urlparse(value)
166+
parsed_url = utils.urlparse(value)
168167
except (AttributeError, TypeError):
169168
raise ValidationError("Unable to parse the URL.")
170169

@@ -186,7 +185,7 @@ class RepoURL(URL):
186185
def post_validation(self, config, key_name):
187186

188187
if config['repo_url'] is not None and config.get('repo_name') is None:
189-
repo_host = six.moves.urllib.parse.urlparse(
188+
repo_host = utils.urlparse(
190189
config['repo_url']).netloc.lower()
191190
if repo_host == 'github.com':
192191
config['repo_name'] = 'GitHub'
@@ -204,7 +203,7 @@ class Dir(Type):
204203
"""
205204

206205
def __init__(self, exists=False, **kwargs):
207-
super(Dir, self).__init__(type_=six.string_types, **kwargs)
206+
super(Dir, self).__init__(type_=utils.string_types, **kwargs)
208207
self.exists = exists
209208

210209
def run_validation(self, value):
@@ -369,15 +368,15 @@ def run_validation(self, value):
369368
# TODO: Remove in 1.0
370369
config_types = set(type(l) for l in value)
371370

372-
if config_types.issubset(set([six.text_type, dict, str])):
371+
if config_types.issubset(set([utils.text_type, dict, str])):
373372
return value
374373

375-
if config_types.issubset(set([six.text_type, list, str])):
374+
if config_types.issubset(set([utils.text_type, list, str])):
376375
return legacy.pages_compat_shim(value)
377376

378377
raise ValidationError("Invalid pages config. {0} {1}".format(
379378
config_types,
380-
set([six.text_type, dict, ])
379+
set([utils.text_type, dict, ])
381380
))
382381

383382
def post_validation(self, config, key_name):
@@ -463,7 +462,7 @@ def run_validation(self, value):
463462
raise ValidationError('Invalid config options for Markdown '
464463
"Extension '{0}'.".format(ext))
465464
self.configdata[ext] = cfg
466-
elif isinstance(item, six.string_types):
465+
elif isinstance(item, utils.string_types):
467466
extensions.append(item)
468467
else:
469468
raise ValidationError('Invalid Markdown Extensions configuration')

mkdocs/config/defaults.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import unicode_literals
22

3-
import six
4-
53
from mkdocs import utils
64
from mkdocs.config import config_options
75

@@ -16,10 +14,10 @@
1614
DEFAULT_SCHEMA = (
1715

1816
# Reserved for internal use, stores the mkdocs.yml config file.
19-
('config_file_path', config_options.Type(six.string_types)),
17+
('config_file_path', config_options.Type(utils.string_types)),
2018

2119
# The title to use for the documentation
22-
('site_name', config_options.Type(six.string_types, required=True)),
20+
('site_name', config_options.Type(utils.string_types, required=True)),
2321

2422
# Defines the structure of the navigation and which markdown files are
2523
# included in the build.
@@ -30,12 +28,12 @@
3028

3129
# A description for the documentation project that will be added to the
3230
# HTML meta tags.
33-
('site_description', config_options.Type(six.string_types)),
31+
('site_description', config_options.Type(utils.string_types)),
3432
# The name of the author to add to the HTML meta tags
35-
('site_author', config_options.Type(six.string_types)),
33+
('site_author', config_options.Type(utils.string_types)),
3634

3735
# The path to the favicon for a site
38-
('site_favicon', config_options.Type(six.string_types)),
36+
('site_favicon', config_options.Type(utils.string_types)),
3937

4038
# The MkDocs theme for the documentation.
4139
('theme', config_options.Theme(default='mkdocs')),
@@ -51,15 +49,15 @@
5149
('theme_dir', config_options.ThemeDir(exists=True)),
5250

5351
# A copyright notice to add to the footer of documentation.
54-
('copyright', config_options.Type(six.string_types)),
52+
('copyright', config_options.Type(utils.string_types)),
5553

5654
# set of values for Google analytics containing the account IO and domain,
5755
# this should look like, ['UA-27795084-5', 'mkdocs.org']
5856
('google_analytics', config_options.Type(list, length=2)),
5957

6058
# The address on which to serve the live reloading docs server.
6159
('dev_addr', config_options.Type(
62-
six.string_types, default='127.0.0.1:8000')),
60+
utils.string_types, default='127.0.0.1:8000')),
6361

6462
# If `True`, use `<page_name>/index.hmtl` style files with hyperlinks to
6563
# the directory.If `False`, use `<page_name>.html style file with
@@ -75,7 +73,7 @@
7573
# A name to use for the link to the project source repo.
7674
# Default, If repo_url is unset then None, otherwise
7775
# "GitHub" or "Bitbucket" for known url or Hostname for unknown urls.
78-
('repo_name', config_options.Type(six.string_types)),
76+
('repo_name', config_options.Type(utils.string_types)),
7977

8078
# Specify which css or javascript files from the docs directory should be
8179
# additionally included in the site. Default, List of all .css and .js
@@ -108,7 +106,7 @@
108106

109107
# the remote branch to commit to when using gh-deploy
110108
('remote_branch', config_options.Type(
111-
six.string_types, default='gh-pages')),
109+
utils.string_types, default='gh-pages')),
112110

113111
# extra is a mapping/dictionary of data that is passed to the template.
114112
# This allows template authors to require extra configuration that not

mkdocs/exceptions.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import unicode_literals
12
from click import ClickException
23

34

mkdocs/gh_deploy.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import unicode_literals
12
import logging
23
import subprocess
34
import os

mkdocs/legacy.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
from __future__ import unicode_literals
12
import logging
23

3-
import six
4-
4+
from mkdocs import utils
55
from mkdocs.exceptions import ConfigurationError
66

77
log = logging.getLogger(__name__)
@@ -53,7 +53,7 @@ def pages_compat_shim(original_pages):
5353

5454
for config_line in original_pages:
5555

56-
if isinstance(config_line, six.string_types):
56+
if isinstance(config_line, utils.string_types):
5757
config_line = [config_line, ]
5858

5959
if len(config_line) not in (1, 2, 3):

mkdocs/nav.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
This consists of building a set of interlinked page and header objects.
77
"""
88

9+
from __future__ import unicode_literals
910
import datetime
1011
import logging
1112
import os
1213

13-
import six
14-
1514
from mkdocs import utils, exceptions
1615

1716
log = logging.getLogger(__name__)
@@ -213,7 +212,7 @@ def _path_to_page(path, title, url_context, use_directory_urls):
213212

214213
def _follow(config_line, url_context, use_dir_urls, header=None, title=None):
215214

216-
if isinstance(config_line, six.string_types):
215+
if isinstance(config_line, utils.string_types):
217216
path = os.path.normpath(config_line)
218217
page = _path_to_page(path, title, url_context, use_dir_urls)
219218

@@ -239,7 +238,7 @@ def _follow(config_line, url_context, use_dir_urls, header=None, title=None):
239238

240239
next_cat_or_title, subpages_or_path = next(iter(config_line.items()))
241240

242-
if isinstance(subpages_or_path, six.string_types):
241+
if isinstance(subpages_or_path, utils.string_types):
243242
path = subpages_or_path
244243
for sub in _follow(path, url_context, use_dir_urls, header=header, title=next_cat_or_title):
245244
yield sub

mkdocs/relative_path_ext.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
tutorial/intro.md | tutorial/intro/ | ../../img/initial-layout.png |
3636
3737
"""
38+
from __future__ import unicode_literals
3839
import logging
3940

4041
from markdown.extensions import Extension
4142
from markdown.treeprocessors import Treeprocessor
42-
import six
4343

4444
from mkdocs import utils
4545
from mkdocs.exceptions import MarkdownNotFound
@@ -56,7 +56,7 @@ def _iter(node):
5656
def path_to_url(url, nav, strict):
5757

5858
scheme, netloc, path, params, query, fragment = (
59-
six.moves.urllib.parse.urlparse(url))
59+
utils.urlparse(url))
6060

6161
if scheme or netloc or not path:
6262
# Ignore URLs unless they are a relative link to a markdown file.
@@ -89,7 +89,7 @@ def path_to_url(url, nav, strict):
8989

9090
# Convert the .md hyperlink to a relative hyperlink to the HTML page.
9191
fragments = (scheme, netloc, path, params, query, fragment)
92-
url = six.moves.urllib.parse.urlunparse(fragments)
92+
url = utils.urlunparse(fragments)
9393
return url
9494

9595

mkdocs/search.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
from __future__ import unicode_literals
22

33
import json
4-
import six
4+
from mkdocs import utils
5+
6+
try: # pragma: no cover
7+
from html.parser import HTMLParser # noqa
8+
except ImportError: # pragma: no cover
9+
from HTMLParser import HTMLParser # noqa
510

611

712
class SearchIndex(object):
@@ -32,7 +37,7 @@ def _add_entry(self, title, text, loc):
3237
"""
3338
self._entries.append({
3439
'title': title,
35-
'text': six.text_type(text.strip().encode('utf-8'), encoding='utf-8'),
40+
'text': utils.text_type(text.strip().encode('utf-8'), encoding='utf-8'),
3641
'location': loc
3742
})
3843

@@ -93,7 +98,7 @@ def strip_tags(self, html):
9398
return s.get_data()
9499

95100

96-
class HTMLStripper(six.moves.html_parser.HTMLParser):
101+
class HTMLStripper(HTMLParser):
97102
"""
98103
A simple HTML parser that stores all of the data within tags
99104
but ignores the tags themselves and thus strips them from the
@@ -103,7 +108,7 @@ class HTMLStripper(six.moves.html_parser.HTMLParser):
103108
def __init__(self, *args, **kwargs):
104109
# HTMLParser is a old-style class in Python 2, so
105110
# super() wont work here.
106-
six.moves.html_parser.HTMLParser.__init__(self, *args, **kwargs)
111+
HTMLParser.__init__(self, *args, **kwargs)
107112

108113
self.data = []
109114

@@ -136,7 +141,7 @@ def __eq__(self, other):
136141
])
137142

138143

139-
class ContentParser(six.moves.html_parser.HTMLParser):
144+
class ContentParser(HTMLParser):
140145
"""
141146
Given a block of HTML, group the content under the preceding
142147
H1 or H2 tags which can then be used for creating an index
@@ -147,7 +152,7 @@ def __init__(self, *args, **kwargs):
147152

148153
# HTMLParser is a old-style class in Python 2, so
149154
# super() wont work here.
150-
six.moves.html_parser.HTMLParser.__init__(self, *args, **kwargs)
155+
HTMLParser.__init__(self, *args, **kwargs)
151156

152157
self.data = []
153158
self.section = None

mkdocs/serve.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import unicode_literals
12
import logging
23
import shutil
34
import tempfile

mkdocs/tests/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import unicode_literals
12
import textwrap
23
import markdown
34

mkdocs/tests/build_tests.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4+
from __future__ import unicode_literals
45
import os
56
import shutil
67
import tempfile
78
import unittest
8-
9-
from six.moves import zip
109
import mock
1110

11+
try:
12+
from itertools import izip as zip
13+
except ImportError:
14+
# In Py3 use builtin zip function
15+
pass
16+
17+
1218
from mkdocs import build, nav, config
1319
from mkdocs.exceptions import MarkdownNotFound
1420
from mkdocs.tests.base import dedent

mkdocs/tests/cli_tests.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4+
from __future__ import unicode_literals
45
import unittest
56
import mock
67

0 commit comments

Comments
 (0)