Skip to content

Commit

Permalink
Merge branch 'master' into issue-70
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkowl authored Aug 7, 2017
2 parents a75a3b8 + 38a7fd1 commit d664fd9
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 129 deletions.
15 changes: 6 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ Install from PyPI::
It is usable by projects written in other languages, provided you give it the version of the project when invoking it.
For Python 2/3 compatible projects, the version can be discovered automatically.

In your project root, add a ``towncrier.ini`` file, with the contents::

[towncrier]
; Your project name
package = mypackage
; Where your project is kept -- current dir by default
package_dir = src/
; The filename that it will write to, relative to the current dir
filename = NEWS.rst
In your project root, add a ``pyproject.toml`` file, with the contents::

[tool.towncrier]
package = "mypackage"
package_dir = "src"
filename = "NEWS.rst"

Then put news fragments (see "News Fragments" below) into a "newsfragments" directory under your package (so, if your project is named "myproject", and it's kept under ``src``, your newsfragments dir would be ``src/myproject/newsfragments/``).

Expand Down
5 changes: 4 additions & 1 deletion src/towncrier/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ def render_fragments(
sections=data, definitions=definitions, underlines=underlines)

for line in res.split(u"\n"):
done.append(textwrap.fill(line, width=79, subsequent_indent=u" "))
done.append(textwrap.fill(
line, width=79, subsequent_indent=u" ",
break_long_words=False, break_on_hyphens=False,
))

return u"\n".join(done).rstrip() + u"\n"
69 changes: 1 addition & 68 deletions src/towncrier/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

from collections import OrderedDict

try:
import configparser
except ImportError:
import ConfigParser as configparser


_start_string = u'.. towncrier release notes start\n'
_title_format = u'{name} {version} ({project_date})'
Expand All @@ -26,62 +21,7 @@
_underlines = ["=", "-", "~"]


def load_config_ini(from_dir):

config = configparser.ConfigParser(
{
'package_dir': '.',
'filename': 'NEWS.rst',
'directory': None,
}
)
config.read(os.path.join(from_dir, "towncrier.ini"))

if 'towncrier' not in config.sections():
raise ValueError("No [towncrier] section.")

if 'package' not in config.options('towncrier'):
raise ValueError(
"The [towncrier] section has no required 'package' key.")

try:
start_string = config.get('towncrier', 'start_string')
except configparser.NoOptionError:
start_string = _start_string

try:
title_format = config.get('towncrier', 'title_format')
except configparser.NoOptionError:
title_format = _title_format

try:
issue_format = config.get('towncrier', 'issue_format')
except configparser.NoOptionError:
issue_format = None

try:
template_fname = config.get('towncrier', 'template')
except configparser.NoOptionError:
template_fname = None

return {
'package': config.get('towncrier', 'package'),
'package_dir': config.get('towncrier', 'package_dir'),
'filename': config.get('towncrier', 'filename'),
'directory': config.get('towncrier', 'directory'),
'sections': {'': ''},
'types': _default_types,
'template': template_fname,
'start_line': start_string,
'title_format': title_format,
'issue_format': issue_format,
# .ini has no good way to represent a list, and pyproject.toml is the
# future anyway, so this feature is pyproject.toml-only.
'underlines': _underlines,
}


def load_config_toml(from_dir):
def load_config(from_dir):
fn = os.path.join(from_dir, "pyproject.toml")
if not os.path.exists(fn):
return None
Expand Down Expand Up @@ -126,10 +66,3 @@ def load_config_toml(from_dir):
'issue_format': config.get('issue_format'),
'underlines': config.get('underlines', _underlines)
}


def load_config(from_dir):
res = load_config_toml(from_dir)
if res is None:
return load_config_ini(from_dir)
return res
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/68.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When rewrapping text, don't break words or at hyphens -- they might be inside a URL
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/71.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`towncrier.ini` config file support has been removed in preference to `pyproject.toml` configuration.
31 changes: 1 addition & 30 deletions src/towncrier/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,7 @@ class TestCli(TestCase):

maxDiff = None

def test_happy_path_ini(self):
runner = CliRunner()

with runner.isolated_filesystem():
with open('towncrier.ini', 'w') as f:
f.write(
'[towncrier]\n'
'package = foo\n'
'package_dir = .\n'
)
os.mkdir('foo')
with open('foo/__init__.py', 'w') as f:
f.write('__version__ = "1.2.3"\n')
os.mkdir('foo/newsfragments')
with open('foo/newsfragments/123.feature', 'w') as f:
f.write('Adds levitation')

result = runner.invoke(_main, ['--draft', '--date', '01-01-2001'])

self.assertEqual(0, result.exit_code)
self.assertEqual(
result.output,
u'Loading template...\nFinding news fragments...\nRendering news '
u'fragments...\nDraft only -- nothing has been written.\nWhat is '
u'seen below is what would be written.\n\nFoo 1.2.3 (01-01-2001)'
u'\n======================\n'
u'\n\nFeatures\n--------\n\n- Adds levitation (#123)\n\n'
)

def test_happy_path_toml(self):
def test_happy_path(self):
runner = CliRunner()

with runner.isolated_filesystem():
Expand Down
59 changes: 59 additions & 0 deletions src/towncrier/test/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,62 @@ def test_issue_format(self):
output = render_fragments(
template, u"xx{issue}", fragments, definitions, ["-", "~"])
self.assertEqual(output, expected_output)

def test_line_wrapping(self):
"""
Output is nicely wrapped, but doesn't break up words (which can mess
up URLs)
"""
self.maxDiff = None

fragments = {
"": {
"1.feature": u"""
I want a girl with a short skirt and a looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong newsfragment.
""", # NOQA
"2.feature": u"https://google.com/q=?" + u"-" * 100,
"3.feature": u"a " * 80,
"4.feature": u"""
w
h
o
o
p
s
"""
},
}

definitions = OrderedDict([
("feature", {"name": "Features", "showcontent": True}),
])

expected_output = (u"""
Features
--------
- I want a girl with a short skirt and a
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
newsfragment. (#1)
-
https://google.com/q=?----------------------------------------------------------------------------------------------------
(#2)
- a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a a (#3)
- w h o o p s (#4)
""")

template = pkg_resources.resource_string(
"towncrier",
"templates/template.rst").decode('utf8')

fragments = split_fragments(fragments, definitions)
output = render_fragments(
template, None, fragments, definitions, ["-", "~"])
self.assertEqual(output, expected_output)
21 changes: 0 additions & 21 deletions src/towncrier/test/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,6 @@
from .._settings import load_config


class IniSettingsTests(TestCase):

def test_base(self):
"""
Test a "base config" -- with just a package name.
"""
temp = self.mktemp()
os.makedirs(temp)

with open(os.path.join(temp, "towncrier.ini"), "w") as f:
f.write("""[towncrier]
package = foobar
""")

config = load_config(temp)
self.assertEqual(config['package'], "foobar")
self.assertEqual(config['package_dir'], ".")
self.assertEqual(config['filename'], "NEWS.rst")
self.assertEqual(config['underlines'], ["=", "-", "~"])


class TomlSettingsTests(TestCase):

def test_base(self):
Expand Down

0 comments on commit d664fd9

Please sign in to comment.