Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b758d4e7e | ||
|
|
b5b436a3a4 | ||
|
|
0fceca2354 | ||
|
|
9403f1f3ec |
@@ -1,6 +1,16 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
1.24.2 (2020-07-16)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
- Add ``locale`` config option and make ``key-ordering`` locale-aware
|
||||||
|
|
||||||
|
1.24.1 (2020-07-15)
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
- Revert ``locale`` config option from version 1.24.0 because of a bug
|
||||||
|
|
||||||
1.24.0 (2020-07-15)
|
1.24.0 (2020-07-15)
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
|||||||
@@ -197,10 +197,10 @@ It is possible to set the ``locale`` option globally. This is passed to Python's
|
|||||||
`locale.setlocale
|
`locale.setlocale
|
||||||
<https://docs.python.org/3/library/locale.html#locale.setlocale>`_,
|
<https://docs.python.org/3/library/locale.html#locale.setlocale>`_,
|
||||||
so an empty string ``""`` will use the system default locale, while e.g.
|
so an empty string ``""`` will use the system default locale, while e.g.
|
||||||
``"en_US.UTF-8"`` will use that. If unset, the default is ``"C.UTF-8"``.
|
``"en_US.UTF-8"`` will use that.
|
||||||
|
|
||||||
Currently this only affects the ``key-ordering`` rule. The default will order
|
Currently this only affects the ``key-ordering`` rule. The default will order
|
||||||
by Unicode code point number, while other locales will sort case and accents
|
by Unicode code point number, while locales will sort case and accents
|
||||||
properly as well.
|
properly as well.
|
||||||
|
|
||||||
.. code-block:: yaml
|
.. code-block:: yaml
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class KeyOrderingTestCase(RuleTestCase):
|
|||||||
']\n', conf)
|
']\n', conf)
|
||||||
|
|
||||||
def test_locale_case(self):
|
def test_locale_case(self):
|
||||||
self.addCleanup(locale.setlocale, locale.LC_ALL, 'C.UTF-8')
|
self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None))
|
||||||
try:
|
try:
|
||||||
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
||||||
except locale.Error:
|
except locale.Error:
|
||||||
@@ -133,7 +133,7 @@ class KeyOrderingTestCase(RuleTestCase):
|
|||||||
problem=(4, 1))
|
problem=(4, 1))
|
||||||
|
|
||||||
def test_locale_accents(self):
|
def test_locale_accents(self):
|
||||||
self.addCleanup(locale.setlocale, locale.LC_ALL, 'C.UTF-8')
|
self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None))
|
||||||
try:
|
try:
|
||||||
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
||||||
except locale.Error:
|
except locale.Error:
|
||||||
|
|||||||
@@ -331,11 +331,14 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
self.assertEqual(ctx.returncode, 1)
|
self.assertEqual(ctx.returncode, 1)
|
||||||
|
|
||||||
def test_run_with_locale(self):
|
def test_run_with_locale(self):
|
||||||
self.addCleanup(locale.setlocale, locale.LC_ALL, 'C.UTF-8')
|
# check for availability of locale, otherwise skip the test
|
||||||
|
# reset to default before running the test,
|
||||||
|
# as the first two runs don't use setlocale()
|
||||||
try:
|
try:
|
||||||
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
||||||
except locale.Error:
|
except locale.Error:
|
||||||
self.skipTest('locale en_US.UTF-8 not available')
|
self.skipTest('locale en_US.UTF-8 not available')
|
||||||
|
locale.setlocale(locale.LC_ALL, (None, None))
|
||||||
|
|
||||||
# C + en.yaml should fail
|
# C + en.yaml should fail
|
||||||
with RunContext(self) as ctx:
|
with RunContext(self) as ctx:
|
||||||
@@ -343,6 +346,16 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
os.path.join(self.wd, 'en.yaml')))
|
os.path.join(self.wd, 'en.yaml')))
|
||||||
self.assertEqual(ctx.returncode, 1)
|
self.assertEqual(ctx.returncode, 1)
|
||||||
|
|
||||||
|
# C + c.yaml should pass
|
||||||
|
with RunContext(self) as ctx:
|
||||||
|
cli.run(('-d', 'rules: { key-ordering: enable }',
|
||||||
|
os.path.join(self.wd, 'c.yaml')))
|
||||||
|
self.assertEqual(ctx.returncode, 0)
|
||||||
|
|
||||||
|
# the next two runs use setlocale() inside,
|
||||||
|
# so we need to clean up afterwards
|
||||||
|
self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None))
|
||||||
|
|
||||||
# en_US + en.yaml should pass
|
# en_US + en.yaml should pass
|
||||||
with RunContext(self) as ctx:
|
with RunContext(self) as ctx:
|
||||||
cli.run(('-d', 'locale: en_US.UTF-8\n'
|
cli.run(('-d', 'locale: en_US.UTF-8\n'
|
||||||
@@ -357,12 +370,6 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
os.path.join(self.wd, 'c.yaml')))
|
os.path.join(self.wd, 'c.yaml')))
|
||||||
self.assertEqual(ctx.returncode, 1)
|
self.assertEqual(ctx.returncode, 1)
|
||||||
|
|
||||||
# C + c.yaml should pass
|
|
||||||
with RunContext(self) as ctx:
|
|
||||||
cli.run(('-d', 'rules: { key-ordering: enable }',
|
|
||||||
os.path.join(self.wd, 'c.yaml')))
|
|
||||||
self.assertEqual(ctx.returncode, 0)
|
|
||||||
|
|
||||||
def test_run_version(self):
|
def test_run_version(self):
|
||||||
with RunContext(self) as ctx:
|
with RunContext(self) as ctx:
|
||||||
cli.run(('--version', ))
|
cli.run(('--version', ))
|
||||||
@@ -421,6 +428,14 @@ class CommandLineTestCase(unittest.TestCase):
|
|||||||
def test_run_non_ascii_file(self):
|
def test_run_non_ascii_file(self):
|
||||||
path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8')
|
path = os.path.join(self.wd, 'non-ascii', 'éçäγλνπ¥', 'utf-8')
|
||||||
|
|
||||||
|
# Make sure the default localization conditions on this "system"
|
||||||
|
# support UTF-8 encoding.
|
||||||
|
try:
|
||||||
|
locale.setlocale(locale.LC_ALL, (None, 'UTF-8'))
|
||||||
|
except locale.Error:
|
||||||
|
self.skipTest('no UTF-8 locale available')
|
||||||
|
self.addCleanup(locale.setlocale, locale.LC_ALL, (None, None))
|
||||||
|
|
||||||
with RunContext(self) as ctx:
|
with RunContext(self) as ctx:
|
||||||
cli.run(('-f', 'parsable', path))
|
cli.run(('-f', 'parsable', path))
|
||||||
self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))
|
self.assertEqual((ctx.returncode, ctx.stdout, ctx.stderr), (0, '', ''))
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ indentation, etc."""
|
|||||||
|
|
||||||
|
|
||||||
APP_NAME = 'yamllint'
|
APP_NAME = 'yamllint'
|
||||||
APP_VERSION = '1.24.0'
|
APP_VERSION = '1.24.2'
|
||||||
APP_DESCRIPTION = __doc__
|
APP_DESCRIPTION = __doc__
|
||||||
|
|
||||||
__author__ = u'Adrien Vergé'
|
__author__ = u'Adrien Vergé'
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ def run(argv=None):
|
|||||||
print(e, file=sys.stderr)
|
print(e, file=sys.stderr)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
if conf.locale is not None:
|
||||||
locale.setlocale(locale.LC_ALL, conf.locale)
|
locale.setlocale(locale.LC_ALL, conf.locale)
|
||||||
|
|
||||||
max_level = 0
|
max_level = 0
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class YamlLintConfig(object):
|
|||||||
self.yaml_files = pathspec.PathSpec.from_lines(
|
self.yaml_files = pathspec.PathSpec.from_lines(
|
||||||
'gitwildmatch', ['*.yaml', '*.yml', '.yamllint'])
|
'gitwildmatch', ['*.yaml', '*.yml', '.yamllint'])
|
||||||
|
|
||||||
self.locale = 'C.UTF-8'
|
self.locale = None
|
||||||
|
|
||||||
if file is not None:
|
if file is not None:
|
||||||
with open(file) as f:
|
with open(file) as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user