Fix encoding issue in the init subcommand (fix #50).
This commit is contained in:
@@ -49,15 +49,17 @@ from .settings import read_settings
|
||||
_DEFAULT_CONFIG_FILE = 'sigal.conf.py'
|
||||
|
||||
|
||||
def init():
|
||||
@arg('path', nargs='?', help='Path of the sample config file')
|
||||
def init(path):
|
||||
"""Copy a sample config file in the current directory."""
|
||||
|
||||
from pkg_resources import resource_string
|
||||
path = path or 'sigal.conf.py'
|
||||
conf = resource_string(__name__, 'templates/sigal.conf.py')
|
||||
|
||||
with io.open('sigal.conf.py', 'w', 'utf-8') as f:
|
||||
f.write(conf)
|
||||
print("Sample config file created: sigal.conf.py")
|
||||
with io.open(path, 'w', encoding='utf-8') as f:
|
||||
f.write(conf.decode('utf8'))
|
||||
print("Sample config file created: {}".format(path))
|
||||
|
||||
|
||||
@arg('source', nargs='?', help='Input directory')
|
||||
|
||||
10
tests/test_cli.py
Normal file
10
tests/test_cli.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
from sigal import init
|
||||
|
||||
|
||||
def test_init(tmpdir):
|
||||
config_file = str(tmpdir.join('sigal.conf.py'))
|
||||
init(path=config_file)
|
||||
assert os.path.isfile(config_file)
|
||||
Reference in New Issue
Block a user