Skip to content
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

Separate config parsing from rest of the code #383

Closed
wants to merge 13 commits into from

Conversation

Azrenbeth
Copy link
Contributor

@Azrenbeth Azrenbeth commented Sep 3, 2021

Seperates the config parsing from the rest of the code

Parse the config before doing anything else, similar to Synapse

  • Better seperates out the different config sections
  • Removes calls to confusing ConfigParser.get() from the rest of the code
  • Allows for easy migration to different config format in the future (e.g. YAML like Synapse's)

All of the parsing should be exactly the same as it was before, but just done earlier

Sydent.get_branded_template() no longer has a deprecated_template_name argument

  • All calls to this method now check the deprecated option first
  • Needed to change all calls to this anyway but I'm unsure if this was correct approach

Can be reviewed commit to commit

@Azrenbeth Azrenbeth force-pushed the azren/seperate_config_from_code branch from e311cff to e0bfd19 Compare September 6, 2021 08:46
@Azrenbeth Azrenbeth marked this pull request as ready for review September 6, 2021 08:48
@Azrenbeth Azrenbeth requested a review from a team September 6, 2021 08:49
@richvdh richvdh self-assigned this Sep 6, 2021
@richvdh richvdh changed the title Seperate config parsing from rest of the code Separate config parsing from rest of the code Sep 6, 2021
@richvdh
Copy link
Member

richvdh commented Sep 6, 2021

@Azrenbeth: generally it's best to use the imperative for commit comments: "Update .gitignore" rather than "updates ...". See https://chris.beams.io/posts/git-commit/#imperative for more info.

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I very much applaud your efforts here - the general direction seems to make a lot of sense.

However, as I explain below (#383 (comment)), it's really tricky to review as it stands. I've made a bunch of comments on things that stand out, but because so much is changing at once, it's going to take me forever to reconcile it all. Please could you have another go at it - maybe even split it up into more PRs, but certainly rearrange the commits so that we can review each one independently.

.gitignore Outdated Show resolved Hide resolved
sydent/config/server.py Outdated Show resolved Hide resolved

logger = logging.getLogger(__name__)

CONFIG_DEFAULTS = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so: you've said "Can be reviewed commit to commit" - but that only works when each commit actually stands alone, or almost alone, in its own right. In this case (ac78368) you've added a new lump of code which isn't used anywhere, so that doesn't seem to make sense. As a reviewer when I look at this commit on its own, should I assume this is all new code, and review it accordingly? And then: the individual config classes (CryptoConfig and friends) don't exist yet, so I can't really review anything touching that.

So the long and short of it is that I don't think this can be reviewed commit to commit.

Splitting up big changes so that they can be reviewed easily can be challenging, and generally takes a bit of thinking about. What you're aiming for is a change that is simple enough that anyone can look at it for a couple of minutes - even if they haven't been following the progress of change in the project or even in the branch - and say "sure, this is obviously correct". That approach helps anyone else looking at the changes (including yourself when you come back to it in a few weeks' time), but is also a useful way for you as the author to be sure that the changes you are making are correct (and will also help track down where any problems cropped up).

The implication is that I could take any of the commits on your branch, and the code would all work properly: I could fire up a working application, or run all the tests and lint and expect them to pass. You don't necessarily need to actually run them all, but it's a useful guideline to consider.

So it's generally not as simple as "add a load of new code in one commit, then switch to it in later commits". Rather, you need to look for individual bits of functionality you can move around.

As an example, in this case, you might start in your first commit by creating an empty SydentConfig class and passing it into the Sydent constructor alongside the existing config dictionary. Then you can gradually move bits of the configuration parsing into the new SydentConfig, so your second commit could create simple like DatabaseConfig, and update SqliteDatabase to use DatabaseConfig instead of the dictionary. And so on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for taking time to look at this.

So it's generally not as simple as "add a load of new code in one commit, then switch to it in later commits". Rather, you need to look for individual bits of functionality you can move around.

I see your point about making changes that work standalone and I will have another go at this where I move individual bits of functionality in peices. I can see how that would be much easier to review!

The implication is that I could take any of the commits on your branch, and the code would all work properly: I could fire up a working application, or run all the tests and lint and expect them to pass. You don't necessarily need to actually run them all, but it's a useful guideline to consider.

Thank you, that's really clear advice!

I'm sorry for taking unneccessary amounts of your time up, and I will try to make my next attempt very clear!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Azrenbeth please don't apologise. This is great work, and it's not at all obvious how best to structure these things. You're doing great!

sydent/config/_base.py Outdated Show resolved Hide resolved
sydent/config/server.py Outdated Show resolved Hide resolved
changelog.d/383.misc Outdated Show resolved Hide resolved
sydent/sydent.py Show resolved Hide resolved
sydent/config/server.py Outdated Show resolved Hide resolved
sydent/config/server.py Outdated Show resolved Hide resolved
sydent/config/server.py Outdated Show resolved Hide resolved
@Azrenbeth Azrenbeth marked this pull request as draft September 7, 2021 09:13
@Azrenbeth Azrenbeth closed this Sep 7, 2021
@Azrenbeth
Copy link
Contributor Author

Replaced by #385

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants