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

CLI: add --local-source option to automatic family install command #103

Closed
unkcpz opened this issue Jul 22, 2021 · 2 comments
Closed

CLI: add --local-source option to automatic family install command #103

unkcpz opened this issue Jul 22, 2021 · 2 comments

Comments

@unkcpz
Copy link
Member

unkcpz commented Jul 22, 2021

After moving to a new city and switched to a new network carrier, I failed in aiida-pseudo install sssp at the unpacking archive step as reported in #59 and #61. Running the command with --dowload-only, the downloaded compressed file is actually broken.

As an archlinux user living in China, it is very common to download broken packages when I install new software from AUR. The workaround would always be downloading dependent packages by hand from the browser(with proxy on) and put them in the specific local folder. The md5 is checked manually before rerun the install command.

I think a convenient way to 'semi-automatic' install sssp(and pseudo-dojo) families can be first download archive and protocol .json files into a folder, and install the family by designating the folder. Then run the install command with:

aiida-pseuda install sssp --local-source /tmp/

Otherwise, installing sssp family manually and then setting protocol for it separately is to tedious even with the #93 and the name should be correctly set to make aiida-quantumespresso tool to detect it.

I paste the code modified, I can make a PR to do it if we agree with this.

def download_sssp(
    configuration: SsspConfiguration,
    filepath_archive: pathlib.Path,
    filepath_metadata: pathlib.Path,
    traceback: bool = False
) -> None:
    """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.
    """
    from aiida_pseudo.groups.family import SsspFamily
    from .utils import attempt
    
    from requests_file import FileAdapter
    
    request_file = requests.Session()
    request_file.mount('file://', FileAdapter())

    url_sssp_base = 'file:///tmp/'
    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')}"

    with attempt('downloading selected pseudopotentials archive... ', include_traceback=traceback):
        response = request_file.get(url_archive)
        response.raise_for_status()
        with open(filepath_archive, 'wb') as handle:
            handle.write(response.content)
            handle.flush()

    with attempt('downloading selected pseudopotentials metadata... ', include_traceback=traceback):
        response = request_file.get(url_metadata)
        response.raise_for_status()
        with open(filepath_metadata, 'wb') as handle:
            handle.write(response.content)
            handle.flush()
@sphuber
Copy link
Contributor

sphuber commented Jul 22, 2021

Thanks @unkcpz . We are aware of this use case and that it is problematic with the current CLI. @mbercx and I have already been discussing the solution that you also seem to describe in PR #94 . Note that the name of the PR is misleading, but in essence we agreed to add a --from-dir flag that is the parallel to --download-only. Please have a look if that would solve your problem. If so, I propose we continue the discussion there and try to merge the PR at some point. I think @mbercx simply got distracted with other more pressing responsibilities but the code is there in principle and just needs some minor touches.

@unkcpz
Copy link
Member Author

unkcpz commented Jul 27, 2021

@sphuber thanks for redirecting. I have run Marnik's branch with --download-only and --from-download and it works good for me. So close this duplicate issue.

@unkcpz unkcpz closed this as completed Jul 27, 2021
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