Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
super(WithTempDirMixin, self).setUp()
self.tmp = Path(mkdtemp())
def path(filename):
return DIR.joinpath(Path(filename).name + '.pkl')
"""Configuration management for lingpy.
Various aspects of lingpy can be configured and customized by the user. This is done with
configuration files in the user's config dir.
.. seealso:: https://pypi.python.org/pypi/appdirs/
"""
from __future__ import unicode_literals, print_function, absolute_import, division
import io
from appdirs import user_config_dir
from six import PY3
from six.moves.configparser import RawConfigParser
from clldutils.path import Path
DIR = Path(user_config_dir('lingpy'))
class Config(RawConfigParser):
def __init__(self, name, default=None, **kw):
"""Initialization.
:param name: Basename for the config file (suffix .ini will be appended).
:param default: Default content of the config file.
"""
self.name = name
self.default = default
config_dir = Path(kw.pop('config_dir', None) or DIR)
RawConfigParser.__init__(self, kw, allow_no_value=True)
if self.default:
if PY3:
fp = io.StringIO(self.default)
def mkdir(lang, triggers, parent=None):
# turn "Unclassified xxx" into an extra dir!
if lang.jsondata.get('hname', '').startswith('Unclassified'):
parent = mkdir(UnclassifiedGroup(lang.jsondata['hname']), triggers, parent=parent)
parent = parent or Path('.')
fname = '%s.%s' % (slug(lang.name), lang.id)
d = parent.joinpath(fname)
d.mkdir(exist_ok=True)
subgroup = lang.level == LanguoidLevel.family
md = INI(interpolation=None)
for section, options in [
('core', [
('name', lang.name),
('glottocode', lang.id),
('hid', getattr(lang, 'hid', None)),
('level', lang.level.value),
('iso639-3', getattr(lang, 'iso_code', None)),
('latitude', getattr(lang, 'latitude', None)),
('longitude', getattr(lang, 'longitude', None)),
('macroareas', None if subgroup else [ma.name for ma in lang.macroareas]),