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 4 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: 25 additions & 0 deletions pyaerocom/scripts/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from enum import Enum
from pathlib import Path
from shutil import copy2
from typing import Optional

import typer
Expand Down Expand Up @@ -106,5 +107,29 @@
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"
if not Path.exists(mypyaerocom):
Path.mkdir(mypyaerocom)

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

View check run for this annotation

Codecov / codecov/patch

pyaerocom/scripts/cli.py#L116

Added line #L116 was not covered by tests
jgriesfeller marked this conversation as resolved.
Show resolved Hide resolved

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

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
if ini_out_path.exists():
print(f"Error: {ini_out_path} already exists. Please delete by hand if you really want to overwrite that with the default from pyaerocom.")

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

View check run for this annotation

Codecov / codecov/patch

pyaerocom/scripts/cli.py#L124

Added line #L124 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 130 in pyaerocom/scripts/cli.py

View check run for this annotation

Codecov / codecov/patch

pyaerocom/scripts/cli.py#L129-L130

Added lines #L129 - L130 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