-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Check missing key/value pairs in pyproject.toml
- Loading branch information
1 parent
265daa5
commit 190aa6c
Showing
4 changed files
with
102 additions
and
35 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
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,38 @@ | ||
import collections | ||
|
||
|
||
def get_subclasses(cls): | ||
"""Recursively get subclasses of a parent class.""" | ||
subclasses = [] | ||
for subclass in cls.__subclasses__(): | ||
subclasses.append(subclass) | ||
subclasses += get_subclasses(subclass) | ||
return subclasses | ||
|
||
|
||
def flatten(d, parent_key="", sep="."): | ||
items = [] | ||
for k, v in d.items(): | ||
new_key = parent_key + sep + k if parent_key else k | ||
if isinstance(v, collections.MutableMapping): | ||
items.extend(flatten(v, new_key, sep=sep).items()) | ||
else: | ||
items.append((new_key, v)) | ||
return dict(items) | ||
|
||
|
||
def unflatten(d, sep="."): | ||
items = dict() | ||
for k, v in d.items(): | ||
keys = k.split(sep) | ||
sub_items = items | ||
for ki in keys[:-1]: | ||
try: | ||
sub_items = sub_items[ki] | ||
except KeyError: | ||
sub_items[ki] = dict() | ||
sub_items = sub_items[ki] | ||
|
||
sub_items[keys[-1]] = v | ||
|
||
return items |
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