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

Add method to get the latest version of a extension #41

Open
yolile opened this issue Jun 26, 2024 · 8 comments
Open

Add method to get the latest version of a extension #41

yolile opened this issue Jun 26, 2024 · 8 comments

Comments

@yolile
Copy link
Member

yolile commented Jun 26, 2024

Similar to ExtensionRegistry.get() method but for the latest version, not the first one (or add a parameter to this method)

@yolile yolile changed the title Add method to get the lastest version of a extension Add method to get the latest version of a extension Jun 26, 2024
@jpmckinney
Copy link
Member

What's the context for this need?

@yolile
Copy link
Member Author

yolile commented Jun 26, 2024

I'm using the library to get the list of all the latest versions of core extensions to include them in the mapping template. But I'm using __iter__() for now, so this issue is not a priority.

@jpmckinney
Copy link
Member

Do you want the latest tagged version (if the extension has tags) or just the latest version? Because the latest version is always the one without a date (until we start having both 1.1 and 1.2 extensions in the registry).

@yolile
Copy link
Member Author

yolile commented Jun 26, 2024

Well, I want the ones that should be in the field-level mapping template, so I guess the latest tagged version (e.g. not the one in the master branch)

@jpmckinney
Copy link
Member

For now you can just hardcode these to use v1.1.5. Rest use the one with no date.

bids
enquiries
location
lots
milestone_documents
participation_fee
process_title

@yolile
Copy link
Member Author

yolile commented Jun 26, 2024

I'm doing

    base_url = 'https://raw.githubusercontent.com/open-contracting/extension_registry/main'
    registry = ExtensionRegistry(f'{base_url}/extension_versions.csv',
                                 f'{base_url}/extensions.csv')

    core_extensions = set([registry.get(id=extension.id,
                                        version=max([version.version for version in registry.__iter__()])).base_url
                           for extension in registry.filter(core=True)])

With this as the result:

{'https://raw.githubusercontent.com/open-contracting-extensions/ocds_location_extension/v1.1.5/', 
'https://raw.githubusercontent.com/open-contracting-extensions/ocds_process_title_extension/v1.1.5/', 
'https://raw.githubusercontent.com/open-contracting-extensions/ocds_milestone_documents_extension/v1.1.5/', 
'https://raw.githubusercontent.com/open-contracting-extensions/ocds_lots_extension/v1.1.5/', 
'https://raw.githubusercontent.com/open-contracting-extensions/ocds_enquiry_extension/v1.1.5/', 
'https://raw.githubusercontent.com/open-contracting-extensions/ocds_bid_extension/v1.1.5/', 
'https://raw.githubusercontent.com/open-contracting-extensions/ocds_participationFee_extension/v1.1.5/'}

@jpmckinney
Copy link
Member

jpmckinney commented Jun 26, 2024

That works, though max(['1.1.5', '1.1.11']) is 1.1.5 instead of 1.1.11. Probably not a problem for us, but to be correct would need to be something like max(tuple(map(int, version.split('.'))) for version in ['1.1.5', '1.1.11'])

Also, calling iter multiple times is slow. Can cache it with extension_versions = list(registry) , then iterate over that.

@jpmckinney
Copy link
Member

jpmckinney commented Jun 26, 2024

Oh, probably more correct to change to for version in registry.filter(id=version.id) that way you're not picking the max among all extensions (which would only need to be calculated once, if that were the intention).

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

No branches or pull requests

2 participants