Skip to content

Commit

Permalink
Fixes MANIFEST file. Removes unneeded settings dict.
Browse files Browse the repository at this point in the history
  • Loading branch information
lisroach committed May 4, 2021
1 parent 55dc6dd commit 23670b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include README.rst LICENSE CODE_OF_CONDUCT.md CONTRIBUTING.md requirements.txt requirements-dev.txt fixit/py.typed config.schema.json
include README.rst LICENSE CODE_OF_CONDUCT.md CONTRIBUTING.md requirements.txt requirements-dev.txt fixit/py.typed fixit/common/config.schema.json
39 changes: 11 additions & 28 deletions fixit/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,49 +71,32 @@
)


LIST_SETTINGS = ["formatter", "block_list_patterns", "block_list_rules", "packages"]
PATH_SETTINGS = ["repo_root", "fixture_dir"]
NESTED_SETTINGS = ["rule_config"]
DEFAULT_FORMATTER = ["black", "-"]


def get_validated_settings(
file_content: Dict[str, Any], current_dir: Path
) -> Dict[str, Any]:
try:
# __package__ should never be none (config.py should not be run directly)
# But use .get() to make pyre happy
pkg = globals().get("__package__")
assert pkg, "No package was found, config types not validated."
config = pkg_resources.read_text(pkg, LINT_CONFIG_SCHEMA_NAME)
# Validates the types and presence of the keys
schema = json.loads(config)
validate(instance=file_content, schema=schema)
except (AssertionError, FileNotFoundError):
pass

settings = {}
for list_setting_name in LIST_SETTINGS:
if list_setting_name in file_content:
settings[list_setting_name] = file_content[list_setting_name]
# __package__ should never be none (config.py should not be run directly)
# But use .get() to make pyre happy
pkg = globals().get("__package__")
assert pkg, "No package was found, config types not validated."
config = pkg_resources.read_text(pkg, LINT_CONFIG_SCHEMA_NAME)
# Validates the types and presence of the keys
schema = json.loads(config)
validate(instance=file_content, schema=schema)

for path_setting_name in PATH_SETTINGS:
if path_setting_name in file_content:
setting_value = file_content[path_setting_name]
abspath: Path = (current_dir / setting_value).resolve()
else:
abspath: Path = current_dir
# Set path setting to absolute path.
settings[path_setting_name] = str(abspath)

for nested_setting_name in NESTED_SETTINGS:
if nested_setting_name in file_content:
nested_setting = file_content[nested_setting_name]
settings[nested_setting_name] = {}
# Verify that each setting is also a mapping
for k, v in nested_setting.items():
settings[nested_setting_name].update({k: v})
file_content[path_setting_name] = str(abspath)

return settings
return file_content


@lru_cache()
Expand Down

0 comments on commit 23670b2

Please sign in to comment.