Skip to content

Refactor BMConfigParser as a module variable #1927

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

Merged
merged 1 commit into from
Feb 16, 2022

Conversation

shekhar-cis
Copy link
Contributor

@shekhar-cis shekhar-cis commented Jan 28, 2022

Refactor BMConfigParser

  • now as a module variable instead of singleton
  • can run unit tests
  • can be used in mock more easily

@shekhar-cis shekhar-cis force-pushed the refactor/bmconfigparser branch 7 times, most recently from 8863e48 to de05577 Compare February 1, 2022 15:04
@shekhar-cis shekhar-cis force-pushed the refactor/bmconfigparser branch 4 times, most recently from 6b1e897 to 04f4271 Compare February 2, 2022 16:05
@shekhar-cis shekhar-cis force-pushed the refactor/bmconfigparser branch 3 times, most recently from c649d1d to db39e6e Compare February 3, 2022 14:57
@@ -270,3 +169,6 @@ def validate_bitmessagesettings_maxoutboundconnections(value):
if value < 0 or value > 8:
return False
return True


config = BMConfigParser()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Another place with side effects is bad

Copy link
Member

Choose a reason for hiding this comment

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

What alternative design do you propose? I think a module variable is an improvement singleton and I don't know other approaches.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For me this approach seems worse than the singleton antipattern. Create the instance of BMConfigParser() upon program start and use it everywhere passing as argument to functions or accessing it through a slot of another object.

These changes also create potential conflicts all across the codebase. And current test coverage is definitely not enough for such big changes.

Copy link
Member

Choose a reason for hiding this comment

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

but where to put it then? state.py?

Copy link
Member

Choose a reason for hiding this comment

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

So you basically recommend dependency injection. Which is ok, I'm just not sure that can be done easily now because of legacy structures. Using a module variable is halfway there, we can do unit tests on isolated objects, and can be refactored into dependency injection later.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it was all about the tests, you could just separate BMConfigParser from singleton object.

Copy link
Member

Choose a reason for hiding this comment

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

It's not just tests though, there are some additions that prevent misbehaviour, like a clean reset, consolidation of default values and threads waiting for initialization. I'm not super happy that the commit is kind of big, just the old code is difficult to modify in small chunks. The commit makes the code easier to change in the future.

@shekhar-cis shekhar-cis force-pushed the refactor/bmconfigparser branch 5 times, most recently from 3a45e34 to d80c1ad Compare February 8, 2022 07:35
@shekhar-cis shekhar-cis force-pushed the refactor/bmconfigparser branch 2 times, most recently from 5ca7411 to 7a5d606 Compare February 8, 2022 15:10
@shekhar-cis shekhar-cis force-pushed the refactor/bmconfigparser branch 2 times, most recently from d92ee8c to b0477f3 Compare February 14, 2022 10:07
@shekhar-cis shekhar-cis force-pushed the refactor/bmconfigparser branch 3 times, most recently from d6fed4c to fc5cce6 Compare February 14, 2022 10:56
@PeterSurda PeterSurda changed the title Removed get() and fixed read() Refactor BMConfigParser as a module variable Feb 15, 2022
@shekhar-cis shekhar-cis force-pushed the refactor/bmconfigparser branch 2 times, most recently from 3139af4 to 3d14120 Compare February 15, 2022 08:55
@PeterSurda
Copy link
Member

@g1itch I'm ready to merge this, any objections other than dependency injection? That can be done later and easier now with this refactoring.

@shekhar-cis shekhar-cis force-pushed the refactor/bmconfigparser branch from 3d14120 to a577399 Compare February 15, 2022 11:43
@g1itch
Copy link
Collaborator

g1itch commented Feb 15, 2022

@g1itch I'm ready to merge this, any objections other than dependency injection? That can be done later and easier now with this refactoring.

No. Maybe I should accept the death of #1389.

@PeterSurda
Copy link
Member

No. Maybe I should accept the death of #1389.

There's work being done on the mock backend and more flexible buildbot jobs. Once they are available, UI tests can be executed not only for kivy but also for Qt. Then #1389 can be tested more reliably and merged.

@PeterSurda PeterSurda merged commit a577399 into Bitmessage:v0.6 Feb 16, 2022
@g1itch
Copy link
Collaborator

g1itch commented Feb 16, 2022

It looks like SettingsDialog.net_restart_needed in the bitmessageqt is ignored in the appimage built with this changeset.

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.

3 participants