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 pya init command #1402

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ pyaerocom searches in ``~/MyPyaerocom`` for a file named ``paths.ini`` and uses
one in ``data/`` in the pyaerocom installation directory (or at
<https://github.com/metno/pyaerocom/blob/main-dev/pyaerocom/data/paths.ini>).

To change paths, just copy the default file to ``~/MyPyaerocom`` and change paths to your needs.
To change paths, just run the command ``pya init`` and change paths to your needs with your favorite editor.
25 changes: 24 additions & 1 deletion pyaerocom/scripts/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json
from enum import Enum
from pathlib import Path
from shutil import copy2
from typing import Optional

import typer

from pyaerocom import __package__, __version__, change_verbosity, const, download_minimal_dataset
from pyaerocom.aeroval import EvalSetup, ExperimentProcessor
from pyaerocom.io.cachehandler_ungridded import list_cache_files
Expand Down Expand Up @@ -106,5 +106,28 @@
download_minimal_dataset(extract_dir_override=extract_dir)


@main.command()
def init():
"""init ~/MyPyaerocom directory and copy the default paths.ini there"""

mypyaerocom = Path.home() / "MyPyaerocom"
mypyaerocom.mkdir(exist_ok=True)

# copy default paths.ini if it doesn't exit
ini_in_path = Path(__file__).parents[1].joinpath("data/paths.ini")
ini_out_path = mypyaerocom / "paths.ini"
if not ini_in_path.exists():
print(f"Error: {ini_in_path} does not exist. Something is wrong with your pyaerocom installation!")

Check warning on line 120 in pyaerocom/scripts/cli.py

View check run for this annotation

Codecov / codecov/patch

pyaerocom/scripts/cli.py#L120

Added line #L120 was not covered by tests
if ini_out_path.exists():
print(f"Error: {ini_out_path} already exists. Please delete it by hand if you really want to overwrite that with the default from pyaerocom.")

Check warning on line 122 in pyaerocom/scripts/cli.py

View check run for this annotation

Codecov / codecov/patch

pyaerocom/scripts/cli.py#L122

Added line #L122 was not covered by tests
else:
try:
copy2(ini_in_path, mypyaerocom)
print(f"{ini_out_path} successfully created")
except Exception as e:
print(f"Error: file {ini_out_path} could not created. The error message was "

Check warning on line 128 in pyaerocom/scripts/cli.py

View check run for this annotation

Codecov / codecov/patch

pyaerocom/scripts/cli.py#L127-L128

Added lines #L127 - L128 were not covered by tests
f"{e}.")


if __name__ == "__main__":
main()
5 changes: 5 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def test_ppiaccess():
assert result.exit_code == 0


def test_init():
result = runner.invoke(main, ["init"])
assert result.exit_code == 0


@pytest.fixture()
def config_json(monkeypatch, tmp_path: Path, eval_config: dict) -> Path:
def do_not_run(self, model_name=None, obs_name=None, var_list=None, update_interface=True):
Expand Down
Loading