Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support XDG_CONFIG_HOME * Fix a KeyError
- Loading branch information
Showing
12 changed files
with
122 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
PyYAML ~= 3.11 | ||
ansicolor ~= 0.2.4 | ||
chardet >= 2.3.0 | ||
typing >= 3.6.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
let s:inline_python = 'python << EOF' | ||
exec s:inline_python | ||
import os | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cmdargs: | ||
verbose: true | ||
severity: warning | ||
error-limit: 10 | ||
|
||
|
||
policies: | ||
ProhibitSomethingEvil: | ||
# Some comments | ||
enabled: false | ||
|
||
ProhibitSomethingDengerous: | ||
enabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import unittest | ||
from vint.utils.array import flatten, flat_map | ||
|
||
|
||
class TestUtilsArray(unittest.TestCase): | ||
def test_flatten_empty(self): | ||
result = flatten([]) | ||
self.assertEqual(result, []) | ||
|
||
def test_flatten_not_empty(self): | ||
result = flatten([[0], [1, 2]]) | ||
self.assertEqual(result, [0, 1, 2]) | ||
|
||
def test_flat_map(self): | ||
result = flat_map(lambda x: [x, x * 2], [0, 1, 2]) | ||
self.assertEqual(result, [0, 0, 1, 2, 2, 4]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CONFIG_FILENAMES = [ | ||
'.vintrc.yaml', | ||
'.vintrc.yml', | ||
'.vintrc', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
from typing import Dict | ||
from pathlib import Path | ||
from vint.utils.array import flat_map | ||
from vint.asset import get_asset_path | ||
from vint.linting.config.config_filenames import CONFIG_FILENAMES | ||
from vint.linting.config.config_file_source import ConfigFileSource | ||
|
||
GLOBAL_CONFIG_FILENAME = '.vintrc.yaml' | ||
VOID_CONFIG_PATH = get_asset_path('void_config.yaml') | ||
|
||
|
||
class ConfigGlobalSource(ConfigFileSource): | ||
def get_file_path(self, env): | ||
global_config_path = Path(env['home_path'], GLOBAL_CONFIG_FILENAME) | ||
global_config_paths = ConfigGlobalSource._get_filenames_candidates(env) | ||
|
||
for global_config_path in global_config_paths: | ||
if global_config_path.is_file(): | ||
return global_config_path | ||
|
||
return VOID_CONFIG_PATH | ||
|
||
@classmethod | ||
def _get_filenames_candidates(cls, env): | ||
# type: (Dict[str, str]) -> [Path] | ||
global_config_dir_candidates = [ | ||
env['xdg_config_home'], | ||
env['home_path'], | ||
] | ||
|
||
return flat_map( | ||
lambda directory: ConfigGlobalSource._get_filenames_candidates_from_dir(directory), | ||
global_config_dir_candidates | ||
) | ||
|
||
@classmethod | ||
def _get_filenames_candidates_from_dir(cls, config_dir): | ||
# type: (str) -> [Path] | ||
return [Path(config_dir, filename) for filename in CONFIG_FILENAMES] | ||
|
||
if global_config_path.is_file(): | ||
return global_config_path | ||
else: | ||
return VOID_CONFIG_PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from typing import TypeVar, List, Callable | ||
from functools import reduce | ||
from operator import add | ||
|
||
T = TypeVar('T') | ||
S = TypeVar('S') | ||
|
||
|
||
def flatten(l): | ||
# type: (List[List[T]]) -> List[T] | ||
return reduce(add, l, []) | ||
|
||
|
||
def flat_map(f, l): | ||
# type: (Callable[[S], List[T]], List[S]) -> List[T] | ||
return flatten([f(x) for x in l]) |