Skip to content

Replace get_keyring_service by KEYRING_SERVICE class variable#1209

Merged
ryneeverett merged 4 commits into
GothenburgBitFactory:developfrom
Lotram:first-pytest-migration
Jun 4, 2026
Merged

Replace get_keyring_service by KEYRING_SERVICE class variable#1209
ryneeverett merged 4 commits into
GothenburgBitFactory:developfrom
Lotram:first-pytest-migration

Conversation

@Lotram

@Lotram Lotram commented May 6, 2026

Copy link
Copy Markdown
Collaborator

First commit

Fix a test in test_service.py : since this commit the test check each abstract method is defined only once, which does not really make sense. I changed it back to check the number of calls, while adding an allowlist for some abstract methods we do want to call from concrete methods.

An alternative could be to simply remove this test, since we already have an exception

Second commit

Replace Service.get_keyring_service by a ServiceConfig.KEYRING_SERVICE string

@ryneeverett ryneeverett left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Regarding the first commit -- oops! Thanks for catching this.

It isn't clear to me that an exception is justified for get_keyring_service though. Perhaps this would be a good time to eliminate the method in favor of a class property string on which Service.get_secret calls .format(config)?

@Lotram

Lotram commented May 11, 2026

Copy link
Copy Markdown
Collaborator Author

I'm ok with removing get_keyring_service, but it wouldn't work right away with KanboardService and PhabricatorService:

    def get_keyring_service(config: KanboardConfig) -> str:
        parsed = urlparse(config.url)
        return f"kanboard://{config.username}@{parsed.netloc}"

One solution would be to use a computed_field for the host, in both KanboardConfigandPhabricatorConfig`

Another solution would be to make get_keyring_service a method of the ServiceConfig subclasses, instead of the Service ones ? IMO it makes sense to attach this to the config. Users could want to customize this in their config, if we ever want to support this.

@ryneeverett

Copy link
Copy Markdown
Collaborator

The computed_field solution seems good. Making this a string rather than a method is the main thing I'd like to see.

I'd be ok with that string moving to ServiceConfig, but I wouldn't want to see the get_keyring_service method moved to ServiceConfig. As you probably realize, it shouldn't be configurable at this point since there is no apparent demand for that.

@Lotram Lotram force-pushed the first-pytest-migration branch from a86a58a to d459e7a Compare June 1, 2026 11:51
@Lotram Lotram changed the title First pytest migration Replace get_keyring_service by KEYRING_SERVICE class variable Jun 1, 2026

@ryneeverett ryneeverett left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a breaking change to the service API so we need to bump the version to 2.0 (LATEST_API_VERSION, API_VERSION of each service, header of api.rst). I'd also like to see backwards compatibility:

    @property
    def keyring_service(self) -> str:
        service = get_service(self.service).API_VERSION
        if service.API_VERSION < 2:
            return service.get_keyring_service(self)
        return self.KEYRING_SERVICE.format(**self.model_dump())

Comment thread bugwarrior/config/schema.py Outdated
Comment thread bugwarrior/services/pagure.py Outdated
@ryneeverett

Copy link
Copy Markdown
Collaborator

One more thing I forgot in addition to the rebase -- please add a Changelog section to the bottom of api.rst and mention the removal of get_keyring_service and addition of KEYRING_SERVICE.

Lotram added 3 commits June 3, 2026 13:43
That test was simply testing each abstract method is
defined only once.
Reverted to check the number of calls for each abstract method
while adding an allowlist,
for abstract methods we can call from concrete ones
@Lotram Lotram force-pushed the first-pytest-migration branch from ecaadcb to 28d38ac Compare June 3, 2026 11:51
Fix import of get_service after rebase
@Lotram Lotram force-pushed the first-pytest-migration branch from 28d38ac to 464b675 Compare June 3, 2026 11:56
@ryneeverett ryneeverett merged commit 3844120 into GothenburgBitFactory:develop Jun 4, 2026
7 of 8 checks passed
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