Skip to content

Commit

Permalink
Merge pull request twisted#73 from hawkowl/71-noini
Browse files Browse the repository at this point in the history
[twisted#71] No INI
  • Loading branch information
hawkowl authored Aug 7, 2017
2 parents ac8fbdc + 78ea06a commit 38a7fd1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 128 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
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/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
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 38a7fd1

Please sign in to comment.