Skip to content

Conversation

@marcospri
Copy link
Contributor

Remove function registry pattern and return all links explicitly

Remove function registry pattern and return all links explicitly
if not self.annotations:
return None
return links.incontext_link(request, self.annotations[0])
return incontext_link(request, self.annotations[0])
Copy link
Contributor Author

@marcospri marcospri Apr 8, 2025

Choose a reason for hiding this comment

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

We often use these functions directly, keep it as functions but moved them to the service namespace.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could maybe just change code paths like this to use the service methods: request.find_service(name="links").incontext_link(annotation).

from urllib.parse import unquote, urljoin, urlparse


def pretty_link(url):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved these to the service.

"@context": self.CONTEXT_URL,
"type": "Annotation",
"id": self._links_service.get(self.annotation, "jsonld_id"),
"id": self._links_service.jsonld_id(self.annotation),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Call the right service method directly here.

"target": annotation.target,
"document": DocumentJSONPresenter(annotation.document).asdict(),
"links": self._links_service.get_all(annotation),
"links": {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

List every type of link here.


LINK_GENERATORS_KEY = "h.links.link_generators"

def json_link(request, annotation) -> str:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Functions from h.links

return LinksService(base_url=base_url, registry=request.registry)


def add_annotation_link_generator(config, name, generator, hidden=False): # noqa: FBT002
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove the registry

PAGE_SIZE = 200


def pretty_link(url):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was in h.links but only used here, 🤷 I could a function in the service like the others but it's a bit different in the intent.

self.base_url = base_url
self.registry = registry

# It would be absolutely fair if at this point you asked yourself any
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This request object and the comment below is the only reason to keep this a service, not just functions.

I don't want to go on a huge refactoring path, IMO keeping the service and the functions in the same module is a bit clearer.

Copy link
Contributor

@seanh seanh left a comment

Choose a reason for hiding this comment

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

Yeah this seems like an improvement -- more similar to our usual services pattern, and the "link registry" thing seems unnecessary

if not self.annotations:
return None
return links.incontext_link(request, self.annotations[0])
return incontext_link(request, self.annotations[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

We could maybe just change code paths like this to use the service methods: request.find_service(name="links").incontext_link(annotation).

@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2025

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale Used by https://github.com/probot/stale to label stale issues and pull requests before closing them label May 9, 2025
@github-actions github-actions bot closed this May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Used by https://github.com/probot/stale to label stale issues and pull requests before closing them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants