-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/improve configuration #75
Conversation
Codecov Report
@@ Coverage Diff @@
## main #75 +/- ##
==========================================
- Coverage 70.90% 67.81% -3.09%
==========================================
Files 33 35 +2
Lines 1619 2082 +463
Branches 199 286 +87
==========================================
+ Hits 1148 1412 +264
- Misses 439 610 +171
- Partials 32 60 +28
Continue to review full report at Codecov.
|
fe7a268
to
0b511e3
Compare
This pr is now feature frozen, a full system to be able to change settings while the bot is running will be added later, the rudimentary system provided here is good enough for now. |
b2bb705
to
b5bd77a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to have some documentation on how to work with the config as a developer (adding, removing, meta), otherwise it works pretty well. I haven't tested out this via discord as I off it for a while. Secondly, I am not really familiar with attr
(I should give it a shot, probably after exams).
pyproject.toml
Outdated
environs = "~=9.3.3" | ||
marshmallow = "~=3.13.0" | ||
python-dotenv = "^0.19.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have two deps which do the samething?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
environs
is being used here in order to set the logging level, #118 will make this unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still stands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: onerandomusername <genericusername414+git@gmail.com>
Signed-off-by: onerandomusername <genericusername414+git@gmail.com>
Signed-off-by: onerandomusername <genericusername414+git@gmail.com>
…oken from being changed Signed-off-by: onerandomusername <genericusername414+git@gmail.com>
when converting to a marshmallow schema, desert does not use class defined Meta classes Signed-off-by: onerandomusername <genericusername414+git@gmail.com>
Signed-off-by: onerandomusername <genericusername414+git@gmail.com>
Signed-off-by: onerandomusername <genericusername414+git@gmail.com>
Signed-off-by: onerandomusername <genericusername414+git@gmail.com>
Signed-off-by: onerandomusername <genericusername414+git@gmail.com>
Signed-off-by: onerandomusername <genericusername414+git@gmail.com>
if any modmail configuration file is edited, a pre-commit hook will run to check that the autogenerated files are up-to-date Signed-off-by: onerandomusername <genericusername414+git@gmail.com>
4e38df2
to
62056c7
Compare
tests: mark xfail the test for default config caching
62056c7
to
bfe641c
Compare
c17131b
to
f015b56
Compare
f015b56
to
03fd57f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
half reviewed, gtg so can't finish
|
||
|
||
_log_optional_deps = logging.getLogger("modmail.optional_dependencies") | ||
_silence = " You can silence these alerts by ignoring the `modmail.optional_dependencies` logger" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring optional_dependencies
where? Be a bit more concise, also am not sure if this is really highlighted since the user's won't be diving deep into the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not even sure this logger is necessary, tbh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only people who would silence this are developers, and I wonder if its even necessary. I might yank the warning entirely.
try: | ||
import dotenv | ||
except ModuleNotFoundError: # pragma: nocover | ||
_log_optional_deps.notice("dotenv was unable to be imported." + _silence) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f-string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not worth it since silence is always at the end.
Per this comment, I may be removing that warning anyways.
|
||
@functools.lru_cache | ||
def _get_config_directory() -> pathlib.Path: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its also worth checking if the user supplied a --config
arg in sys.argv
. This would in cases when you are working on multiple scenarios and don't need to constantly keep changing the config while having the others in background.
Using --config
you won't need to change them and can directly pass the config in.
Not really the write place, it would better fit in USER_CONFIG_FILES
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might add it in a seperate pr, I don't want to add this here since it would involve adding a cli to the bot's entrypoint.
While I'm aware that's not hard, I don't want to reach much further out of the scope of this pr.
modmail/config.py
Outdated
] | ||
|
||
|
||
class BetterPartialEmojiConverter(discord.ext.commands.converter.EmojiConverter): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could probably be moved to a file called patches.py
since it likely to be used elsewhere in the code.
kw = {} | ||
kw["default"] = field.default if field.default is not marshmallow.missing else None | ||
kw["name"] = field.name | ||
kw["type"] = field.type | ||
|
||
kw["metadata"] = field.metadata | ||
kw["field"] = field | ||
|
||
kw["frozen"] = field.on_setattr is attr.setters.frozen or frozen | ||
|
||
metadata_table: config.ConfigMetadata = field.metadata[config.METADATA_TABLE] | ||
kw[config.METADATA_TABLE] = metadata_table | ||
kw["description"] = metadata_table.description | ||
kw["canonical_name"] = metadata_table.canonical_name | ||
kw["extended_description"] = metadata_table.extended_description | ||
kw["hidden"] = metadata_table.hidden | ||
|
||
kw["discord_converter"] = metadata_table.discord_converter | ||
kw["discord_converter_attribute"] = metadata_table.discord_converter_attribute | ||
|
||
if nested is not None: | ||
kw["nested"] = nested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be more readable if we form the dict at once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, I felt like this was more readable.
I meant to add documentation to each key here in the form of comments, which I guess i didn't do.
await responses.send_positive_response(ctx, response) | ||
|
||
@config_group.command(name="get", aliases=("show",)) | ||
async def get_config(self, ctx: Context, option: KeyConverter) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get
shouldn't work if the value is hidden, like in the case of bot.token
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix when renovating the configuration manager in a new pr.
@@ -35,7 +33,7 @@ def __init__(self: discord.Embed, description: str = None, **kwargs): # noqa: N | |||
if ("description" in kwargs or description is not None) and "content" in kwargs: | |||
raise TypeError("Description and content are aliases for the same field, but both were provided.") | |||
|
|||
colour = kwargs.pop("color", kwargs.pop("colour", DEFAULT_COLOR)) | |||
colour = kwargs.pop("color", kwargs.pop("colour", config().user.colours.base_embed_color)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bot.config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bot is not available in this context.
@@ -34,8 +34,9 @@ def determine_bot_mode() -> int: | |||
The configuration system uses true/false values, so we need to turn them into an integer for bitwise. | |||
""" | |||
bot_mode = 0 | |||
_config = config() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bot.config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bot is not available in this context.
pyproject.toml
Outdated
environs = "~=9.3.3" | ||
marshmallow = "~=3.13.0" | ||
python-dotenv = "^0.19.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still stands
restructuring, using 'startswith', other updates
Closes #22