<commit_before>from __future__ import with_statement
# -*- coding: utf-8 -*-
#
# Cartridge documentation build configuration file, created by
# sphinx-quickstart on Wed Mar 10 07:20:42 2010.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
docs_path = os.path.abspath(os.path.dirname(__file__))
mezzanine_path = os.path.join(docs_path, "..")
sys.path.insert(0, mezzanine_path)
os.environ["DJANGO_SETTINGS_MODULE"] = "mezzanine.project_template.settings"
import mezzanine

# Generate the documentation for mezzanine.settings
import mezzanine.settings
settings_comment = []
settings_docs = [".. THIS DOCUMENT IS AUTO GENERATED VIA conf.py"]
with open(mezzanine.settings.__file__.rstrip("c"), "r") as f:
    for line in f:
        if line.startswith("#"):
            settings_comment.append(line.lstrip("#").strip())
        elif line.startswith("setting("):
            settings_name = line.split('setting("', 1)[1].split('"', 1)[0]
            settings_default = getattr(mezzanine.settings, settings_name)
            if isinstance(settings_default, basestring):
                settings_default = '"%s"' % settings_default
            settings_default = "``%s``" % str(settings_default)
            settings_name = "``MEZZANINE_%s``" % settings_name
            settings_docs.extend(["", settings_name, "-" * len(settings_name)])
            settings_docs.extend(["", "Default: %s" % settings_default, ""])
            settings_docs.extend(settings_comment)
            settings_comment = []
        elif not line.strip():
            settings_comment = []
with open(os.path.join(docs_path, "settings.rst"), "w") as f:
    f.write("\n".join(settings_docs))

# Generate the CHANGELOG file.

from datetime import datetime
from mercurial import ui, hg
from django.utils.datastructures import SortedDict

repo = hg.repository(ui.ui(), mezzanine_path)
version_file = "mezzanine/__init__.py"
version_var = "__version__"
changelog_filename = "CHANGELOG"
changelog_file = os.path.join(mezzanine_path, changelog_filename)
versions = SortedDict()

for changeset in reversed(list(repo.changelog)):
    # Check if the file with the version number is in this changeset and if 
    # it is, pull it out and assign it as a variable.
    context = repo.changectx(changeset)
    if len(context.parents()) > 1:
        # Ignore merges.
        continue
    files = context.files()
    new_version = False
    if version_file in files:
        for line in context[version_file].data().split("\n"):
            if line.startswith(version_var):
                exec line
                version_info = {"changes": set(), "date": 
                    datetime.fromtimestamp(context.date()[0]
                    ).strftime("%b %d, %Y")}
                versions[globals()[version_var]] = version_info
                new_version = True
    if (new_version or changelog_filename in files) and len(files) == 1:
        # Ignore changeset that bumped version.
        continue
    # Ensure we have a current version and if so, add this changeset's 
    # description to it.
    try:
        version = globals()[version_var]
    except KeyError:
        continue
    else:
        entry = "%s - %s" % (context.description(), context.user().split()[0])
        versions[version]["changes"].update((entry,))

# Write out the changelog.
with open(changelog_file, "w") as f:
    for version, version_info in versions.items():
        version_header = "Version %s (%s)" % (version, version_info["date"])
        f.write("%s\n" % version_header)
        f.write("%s\n" % ("-" * len(version_header)))
        f.write("\n")
        if version_info["changes"]:
            for change in version_info["changes"]:
                f.write("  * %s\n" % change)
        else:
            f.write("  * No changes listed.\n")
        f.write("\n")

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.append(os.path.abspath('.'))

# -- General configuration -----------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ["sphinx.ext.autodoc"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']<commit_msg>Make changelog generator in Sphinx conf list changesets within a version in chronological order.<commit_after>from __future__ import with_statement
# -*- coding: utf-8 -*-
#
# Cartridge documentation build configuration file, created by
# sphinx-quickstart on Wed Mar 10 07:20:42 2010.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
docs_path = os.path.abspath(os.path.dirname(__file__))
mezzanine_path = os.path.join(docs_path, "..")
sys.path.insert(0, mezzanine_path)
os.environ["DJANGO_SETTINGS_MODULE"] = "mezzanine.project_template.settings"
import mezzanine

# Generate the documentation for mezzanine.settings
import mezzanine.settings
settings_comment = []
settings_docs = [".. THIS DOCUMENT IS AUTO GENERATED VIA conf.py"]
with open(mezzanine.settings.__file__.rstrip("c"), "r") as f:
    for line in f:
        if line.startswith("#"):
            settings_comment.append(line.lstrip("#").strip())
        elif line.startswith("setting("):
            settings_name = line.split('setting("', 1)[1].split('"', 1)[0]
            settings_default = getattr(mezzanine.settings, settings_name)
            if isinstance(settings_default, basestring):
                settings_default = '"%s"' % settings_default
            settings_default = "``%s``" % str(settings_default)
            settings_name = "``MEZZANINE_%s``" % settings_name
            settings_docs.extend(["", settings_name, "-" * len(settings_name)])
            settings_docs.extend(["", "Default: %s" % settings_default, ""])
            settings_docs.extend(settings_comment)
            settings_comment = []
        elif not line.strip():
            settings_comment = []
with open(os.path.join(docs_path, "settings.rst"), "w") as f:
    f.write("\n".join(settings_docs))

# Generate the CHANGELOG file.

from datetime import datetime
from mercurial import ui, hg
from django.utils.datastructures import SortedDict

repo = hg.repository(ui.ui(), mezzanine_path)
version_file = "mezzanine/__init__.py"
version_var = "__version__"
changelog_filename = "CHANGELOG"
changelog_file = os.path.join(mezzanine_path, changelog_filename)
versions = SortedDict()

for changeset in reversed(list(repo.changelog)):
    # Check if the file with the version number is in this changeset and if 
    # it is, pull it out and assign it as a variable.
    context = repo.changectx(changeset)
    files = context.files()
    new_version = False
    if version_file in files:
        for line in context[version_file].data().split("\n"):
            if line.startswith(version_var):
                exec line
                version_info = {"changes": [], "date": 
                    datetime.fromtimestamp(context.date()[0]
                    ).strftime("%b %d, %Y")}
                versions[globals()[version_var]] = version_info
                new_version = len(files) == 1
    # Ignore changesets that are merges, bumped the version or regenerated
    # the changelog itself
    merge = len(context.parents()) > 1
    changelog_update = changelog_filename in files and len(files) == 1
    if merge or new_version or changelog_update:
        continue
    # Ensure we have a current version and if so, add this changeset's 
    # description to it.
    try:
        version = globals()[version_var]
    except KeyError:
        continue
    else:
        description = context.description().rstrip(".")
        user = context.user().split()[0]
        entry = "%s - %s" % (description, user)
        if entry not in versions[version]["changes"]:
            versions[version]["changes"].insert(0, entry)

# Write out the changelog.
with open(changelog_file, "w") as f:
    for version, version_info in versions.items():
        version_header = "Version %s (%s)" % (version, version_info["date"])
        f.write("%s\n" % version_header)
        f.write("%s\n" % ("-" * len(version_header)))
        f.write("\n")
        if version_info["changes"]:
            for change in version_info["changes"]:
                f.write("  * %s\n" % change)
        else:
            f.write("  * No changes listed.\n")
        f.write("\n")

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.append(os.path.abspath('.'))

# -- General configuration -----------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ["sphinx.ext.autodoc"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
{'fraction_non_alphanumeric': 0.12855377008652658, 'fraction_numerical': 0.004738360115368768, 'mean_word_length': 2.9987644151565074, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5746035', 'n_tokens_mistral': 2891, 'n_tokens_neox': 2801, 'n_words': 829}