-
Notifications
You must be signed in to change notification settings - Fork 9
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
👌 IMPROVE: links to materials cloud SSSP archive #104
Changes from all commits
3e6918e
e4620fc
42c13c9
20c36dc
5e668db
0a0b58a
665206d
8568074
3aad69d
fa62917
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import pathlib | ||
import shutil | ||
import tempfile | ||
import yaml | ||
|
||
import click | ||
import requests | ||
|
@@ -97,20 +98,37 @@ def download_sssp( | |
filepath_archive: pathlib.Path, | ||
filepath_metadata: pathlib.Path, | ||
traceback: bool = False | ||
) -> None: | ||
) -> str: | ||
"""Download the pseudopotential archive and metadata for an SSSP configuration to a path on disk. | ||
|
||
:param configuration: the SSSP configuration to download. | ||
:param filepath_archive: absolute filepath to write the pseudopotential archive to. | ||
:param filepath_metadata: absolute filepath to write the metadata file to. | ||
:param traceback: boolean, if true, print the traceback when an exception occurs. | ||
:return: Latest patch version of the requested minor version | ||
""" | ||
from aiida_pseudo.groups.family import SsspFamily | ||
from .utils import attempt | ||
|
||
url_sssp_base = 'https://legacy-archive.materialscloud.org/file/2018.0001/v4/' | ||
url_archive = f"{url_sssp_base}/{SsspFamily.format_configuration_filename(configuration, 'tar.gz')}" | ||
url_metadata = f"{url_sssp_base}/{SsspFamily.format_configuration_filename(configuration, 'json')}" | ||
url_template = 'https://archive.materialscloud.org/record/file?filename={filename}&parent_id=19' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the changes. Everything looks good to me now, except I still have a question about this magic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good question indeed! I think it doesn't change, but let's ask @vgranata to be sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parent_id is persistent within versions of the same record, meaning that it does not change if a new version of a record is created. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK Thanks @vgranata that should be fine. Then we can almost merge this @mbercx . Only thing is that we should probably add the patch version to the description of the group. Otherwise it will only be possible to know what patch version a certain family is by looking at the md5 of the tarball that was downloaded, which is contained in the description. I think it would make sense to store the patch at the very least in the description of the family. And then the tests should be fixed of course, because they are failing |
||
|
||
# Download the dictionary mapping of the minor versions to the latest corresponding patch versions. Since patch | ||
# releases of the SSSP only contain bug fixes, there is no reason to have the user install an outdated patch | ||
# version. So, the latest patch version of the minor version that is specified by the user is always installed. | ||
with attempt('downloading patch versions information... ', include_traceback=traceback): | ||
response = requests.get(url_template.format(filename='versions.yaml')) | ||
response.raise_for_status() | ||
# The `version_mapping` is a dictionary that maps each minor version (key) to the latest patch version (value) | ||
version_mapping = yaml.load(response.content, Loader=yaml.SafeLoader) | ||
patch_version = version_mapping[configuration.version] | ||
|
||
echo.echo_info(f'Latest patch version found: {patch_version}') | ||
|
||
archive_filename = SsspFamily.format_configuration_filename(configuration, 'tar.gz', patch_version) | ||
metadata_filename = SsspFamily.format_configuration_filename(configuration, 'json', patch_version) | ||
|
||
url_archive = url_template.format(filename=archive_filename) | ||
url_metadata = url_template.format(filename=metadata_filename) | ||
|
||
with attempt('downloading selected pseudopotentials archive... ', include_traceback=traceback): | ||
response = requests.get(url_archive) | ||
|
@@ -126,6 +144,8 @@ def download_sssp( | |
handle.write(response.content) | ||
handle.flush() | ||
|
||
return patch_version | ||
|
||
|
||
def download_pseudo_dojo( | ||
configuration: SsspConfiguration, | ||
|
@@ -185,7 +205,6 @@ def cmd_install_sssp(version, functional, protocol, download_only, traceback): | |
|
||
configuration = SsspConfiguration(version, functional, protocol) | ||
label = SsspFamily.format_configuration_label(configuration) | ||
description = f'SSSP v{version} {functional} {protocol} installed with aiida-pseudo v{__version__}' | ||
|
||
if configuration not in SsspFamily.valid_configurations: | ||
echo.echo_critical(f'{version} {functional} {protocol} is not a valid SSSP configuration') | ||
|
@@ -199,8 +218,9 @@ def cmd_install_sssp(version, functional, protocol, download_only, traceback): | |
filepath_archive = dirpath / 'archive.tar.gz' | ||
filepath_metadata = dirpath / 'metadata.json' | ||
|
||
download_sssp(configuration, filepath_archive, filepath_metadata, traceback) | ||
patch_version = download_sssp(configuration, filepath_archive, filepath_metadata, traceback) | ||
|
||
description = f'SSSP v{patch_version} {functional} {protocol} installed with aiida-pseudo v{__version__}' | ||
description += f'\nArchive pseudos md5: {md5_file(filepath_archive)}' | ||
description += f'\nPseudo metadata md5: {md5_file(filepath_metadata)}' | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now just need to update the return type of this function as well and than this is good to merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Righto! Missed that one, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More a sign that we should probably at some point at
mypy
to the pre-commit. On the one hand I like added typing, but on the other handmypy
has been given so much trouble that sometimes it annoys me to no end. :\rock: me :hardplace: