Skip to content
Draft
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
12 changes: 10 additions & 2 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@ jobs:

- name: Format Python code
if: always()
run: uv run ruff format --check .
run: uv run ruff format --check . --preview

- name: Run Python tests
if: always()
run: uv run pytest tests
run: uv run pytest -v tests

- name: Run Python doctests
if: always()
run: uv run pytest -v --doctest-modules

- name: Check Python type hints
if: always()
run: uv run mypy source/ tests/

- name: Minimise uv cache
run: uv cache prune --ci
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
__pycache__/
*.py[cod]
*$py.class
.pytest_cache/
.mypy_cache/

# C extensions
*.so
Expand Down Expand Up @@ -40,6 +42,7 @@ venv/
.env/
.venv/
env/
opt/

# Distribution artifacts
build/
Expand Down
15 changes: 13 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ name = "rose_picker"
description = "Converts Rose metadata file into JSON format."
readme = "README.rst"
license = {text = "GPLv3"}
requires-python = ">=3.11"
requires-python = "==3.12.5"
dynamic = ["version"]

[project.scripts]
rose_picker = "rose_picker.entry:cli"

[project.optional-dependencies]
dev = [
"flake8",
"mypy",
"pytest",
"ruff",
Expand All @@ -31,3 +30,15 @@ version = {attr = "rose_picker.VERSION"}

[tool.setuptools.packages.find]
where = ["source"]

[tool.ruff]
line-length = 88
[tool.ruff.lint]
select = ["E", "F", "W", "B", "I", "UP", "D4"]
ignore = ["I001", "UP031"]
[tool.ruff.lint.per-file-ignores]
"source/rose_picker/rose/*" = ["B", "D", "UP"]
[tool.ruff.format]
quote-style = "double"
indent-style = "space"

36 changes: 18 additions & 18 deletions source/rose_picker/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
import os.path
from pathlib import Path
import re
from typing import Dict, List, Sequence
from typing import Any
from collections.abc import Sequence

import rose_picker.rose # type: ignore
from rose_picker.rose.config import ConfigSyntaxError # type: ignore
from rose_picker.rose.config_tree import ( # type: ignore
ConfigTree,
import rose_picker.rose
from rose_picker.rose.config import ConfigSyntaxError
from rose_picker.rose.config_tree import (
ConfigTreeLoader,
)

_NAMELISTS_REGEX = re.compile(r"^\s*namelist\s*:\s*(\w*)\s*(?:=\s*(\S+))?")
_NML_REGEX = re.compile(r"^\s*namelist\s*:\s*(\w*)\s*(?:=\s*(\S+))?")


class RosePickerException(Exception):
Expand All @@ -45,7 +45,7 @@ class RosePickerException(Exception):
pass # pylint: disable=unnecessary-pass


def _load_configuration(filename: Path, include_dirs: Sequence[Path]) -> ConfigTree:
def _load_configuration(filename: Path, include_dirs: Sequence[Path]) -> Any:
"""
Load and expand the configuration file.
"""
Expand All @@ -68,31 +68,31 @@ def _load_configuration(filename: Path, include_dirs: Sequence[Path]) -> ConfigT
) from config_syntax


def _list_configuration(config_node: ConfigTree) -> List[str]:
def _list_configuration(config_node: Any) -> list[str]:
"""
Get keys list of all the namelists/members in the configuration file.
"""
node_keys = list(filter(_NAMELISTS_REGEX.match, config_node.get_value().keys()))
node_keys = [key for key in config_node.get_value().keys() if _NML_REGEX.match(key)]
node_keys.sort()
return node_keys


def _extract_namelists(
config_node: ConfigTree,
config_node: Any,
namelist_keys: Sequence[str],
member_keys: Sequence[str],
listnames: List[str],
namelist_config: Dict[str, Dict[str, Dict[str, Dict[str, str]]]],
listnames: list[str],
namelist_config: dict[str, dict[str, dict[str, dict[str, str]]]],
):
# pylint: disable-msg=too-many-locals

"""
Extracts namelist properties from meta-data.
Extract namelist properties from meta-data.
"""
node_keys = _list_configuration(config_node)

for key in node_keys:
match = _NAMELISTS_REGEX.match(key)
match = _NML_REGEX.match(key)
if match is None:
raise Exception(f"Failed to find key in string: {key}")
node = match.group(0)
Expand Down Expand Up @@ -167,8 +167,8 @@ def main(meta_filename: Path, include_dirs: Sequence[Path], output_dir: Path):
"values",
]

listnames: List[str] = []
namelist_config: Dict[str, Dict[str, Dict[str, Dict[str, str]]]] = (
listnames: list[str] = []
namelist_config: dict[str, dict[str, dict[str, dict[str, str]]]] = (
collections.OrderedDict()
)
_extract_namelists(
Expand All @@ -179,11 +179,11 @@ def main(meta_filename: Path, include_dirs: Sequence[Path], output_dir: Path):

# Output as .json file
nml_config_filename = f"{basename[0]}.json"
with open(f"{output_dir}/{nml_config_filename}", "wt", encoding="utf-8") as output:
with open(f"{output_dir}/{nml_config_filename}", "w", encoding="utf-8") as output:
json.dump(namelist_config, output, indent=4, ensure_ascii=True)

# Write out namelists in configuration
with open(f"{output_dir}/config_namelists.txt", "wt", encoding="utf-8") as output:
with open(f"{output_dir}/config_namelists.txt", "w", encoding="utf-8") as output:
for listname in listnames:
output.write(f"{listname}\n")

Expand Down
90 changes: 59 additions & 31 deletions source/rose_picker/rose/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,74 @@ Report bugs and request enhancement by opening an issue on
bug, add a recipe for repeating it. If requesting an enhancement,
describe the use case in detail.

## New Contributors

Please read the [CLA](#contributor-licence-agreement-and-certificate-of-origin).

Please add your name to the
[Code Contributors](#code-contributors) section of this file as part of your
first Pull Request (for each Cylc repository you contribute to).

## Contribute Code

All contributions to Rose are made via pull requests against the *master*
branch of [metomi/rose](https://github.com/metomi/rose). New contributors
should add their details to the [Code Contributors](#code-contributors)
section of this file as part of their first request. The developer who
reviews each pull request is responsible for checking that the
contributor's name is listed in this file before merging the pull request
into *master*.
We use [semver](https://semver.org/) to separate riskier changes (e.g. new features
& code refactors) from bugfixes to provide more stable releases for production environments.

**Enhancements** are made on the `master` branch and released in the next minor version
(e.g. 2.1, 2.2, 2.3).

**Bugfixes** and minor usability enhancements are made on bugfix branches and
released as the next maintenance version (e.g. 2.0.1, 2.0.2, 2.0.3). E.G. if the issue is on a `2.0` milestone, branch off of `2.0.x` to
develop your bugfix, then raise the pull request against the `2.0.x` branch. We will later merge the `2.0.x` branch into `master`.

We use [towncrier](https://towncrier.readthedocs.io/en/stable/index.html) for
generating the changelog. Changelog entries are added by running
```
towncrier create <PR-number>.<break|feat|fix>.md --content "Short description"
```

## Code Contributors

The following people have contributed to this code under the terms of
the Contributor Licence Agreement and Certificate of Origin detailed
below:

* Sadie Bartholomew (Met Office, UK)
* Andrew Clark (Met Office, UK)
* Kerry Day (Met Office, UK)
* Martin Dix (CSIRO, Australia)
* Ben Fitzpatrick (Met Office, UK)
* Craig MacLachlan (Met Office, UK)
* Joseph Mancell (Met Office, UK)
* Dave Matthews (Met Office, UK)
* Hilary Oliver (National Institute of Water and Atmospheric Research, New Zealand)
* Annette Osprey (NCAS Computational Modelling Services, UK)
* Stephen Oxley (Met Office, UK)
* Matt Pryor (Met Office, UK)
* Oliver Sanders (Met Office, UK)
* Jon Seddon (Met Office, UK)
* Harry Shepherd (Met Office, UK)
* Matt Shin (Met Office, UK)
* Tomasz Trzeciak (Met Office, UK)
* Stuart Whitehouse (Met Office, UK)
* Steve Wardle (Met Office, UK)
* Scott Wales (ARC Centre of Excellence for Climate Systems Science, Australia)
* Thomas Coleman (Bureau of Meteorology, Australia)
* Bruno P. Kinoshita (National Institute of Water and Atmospheric Research, New Zealand)
* Tim Pillinger (Met Office, UK)
* Mel Hall (Met Office, UK)
<!-- start-shortlog -->
- Sadie Bartholomew (Met Office, UK)
- Andrew Clark (Met Office, UK)
- Kerry Day (Met Office, UK)
- Martin Dix (CSIRO, Australia)
- Ben Fitzpatrick (Met Office, UK)
- Craig MacLachlan (Met Office, UK)
- Joseph Mancell (Met Office, UK)
- Dave Matthews (Met Office, UK)
- Hilary Oliver (National Institute of Water and Atmospheric Research, New Zealand)
- Annette Osprey (NCAS Computational Modelling Services, UK)
- Stephen Oxley (Met Office, UK)
- Matt Pryor (Met Office, UK)
- Oliver Sanders (Met Office, UK)
- Jon Seddon (Met Office, UK)
- Harry Shepherd (Met Office, UK)
- Matt Shin (Met Office, UK)
- Tomasz Trzeciak (Met Office, UK)
- Stuart Whitehouse (Met Office, UK)
- Steve Wardle (Met Office, UK)
- Scott Wales (ARC Centre of Excellence for Climate Systems Science, Australia)
- Thomas Coleman (Bureau of Meteorology, Australia)
- Declan Valters (Met Office, UK)
- Paul Cresswell (Met Office, UK)
- Bruno P. Kinoshita (National Institute of Water and Atmospheric Research, New Zealand)
- Tim Pillinger (Met Office, UK)
- Mel Hall (Met Office, UK)
- Ronnie Dutta (Met Office, UK)
- Roddy Sharp (Met Office, UK)
- Mark Dawson (Met Office, UK)
- Joe Marsh Rossney (UK Centre for Ecology & Hydrology)
- Dimitrios Theodorakis (Met Office, UK)
- Joseph Abram (Met Office, UK)
- James Frost (Met Office, UK)
- Christopher Bennett (Met Office, UK)
<!-- end-shortlog -->

(All contributors are identifiable with email addresses in the version control
logs or otherwise.)
Expand Down
23 changes: 13 additions & 10 deletions source/rose_picker/rose/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
# Rose

[![Build Status](https://travis-ci.org/metomi/rose.svg?branch=master)](https://travis-ci.org/metomi/rose)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/ad021a33e7a64b398f792305dd901795)](https://www.codacy.com/app/metomi/rose?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=metomi/rose&amp;utm_campaign=Badge_Grade)
[![test](https://github.com/metomi/rose/actions/workflows/test.yml/badge.svg)](https://github.com/metomi/rose/actions/workflows/test.yml)
[![DOI](https://zenodo.org/badge/6223866.svg)](https://zenodo.org/badge/latestdoi/6223866)
[![codecov](https://codecov.io/gh/metomi/rose/branch/master/graph/badge.svg)](https://codecov.io/gh/metomi/rose)

Rose: a framework for managing and running meteorological suites.

### Python 2 or Python 3 ?

Currently in the source code repository:
- **master branch:** Python 3, **no GUI** - **Rose-2/Cylc-8 Work In Progress**
- **2019.01.x branch:** Python 2, PyGTK GUI - **Rose-1/Cylc-7 Maintenance**
#### Rose 2019

The first official Rose-2/Cylc-8 release (with a new web UI) is not expected
until late 2019. Until then we recommend the latest rose-2019.01.x/cylc-7.8.x
release for production use.
- Python 2
- PyGTK GUI
- `2019.01.x` branch in the source code

#### Rose 2

- Python 3
- PyGObject GUI
- Web-based GUIs will follow in later Rose 2 releases
- `master` branch in the source code

[Installation](http://metomi.github.io/rose/doc/html/installation.html) |
[User Guide](http://metomi.github.io/rose/) |
[How to Contribute](https://github.com/metomi/rose/blob/master/CONTRIBUTING.md)

## Copyright and Terms of Use

Copyright (C) 2012-2019 British Crown (Met Office) &amp; Contributors
Copyright (C) 2012-<span actions:bind='current-year'>2026</span> British Crown (Met Office) &amp; Contributors

Rose is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
25 changes: 8 additions & 17 deletions source/rose_picker/rose/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (C) 2012-2019 British Crown (Met Office) & Contributors.
#
# Copyright (C) British Crown (Met Office) & Contributors.
# This file is part of Rose, a framework for meteorological suites.
#
# Rose is free software: you can redistribute it and/or modify
Expand All @@ -28,7 +24,12 @@
CONFIG_DELIMITER = "="

# Filenames and directory names
CONFIG_NAMES = ["rose-app.conf", "rose-meta.conf", "rose-suite.conf", "rose-suite.info"]
CONFIG_NAMES = [
"rose-app.conf",
"rose-meta.conf",
"rose-suite.conf",
"rose-suite.info",
]
GLOB_CONFIG_FILE = "rose*.conf"
META_CONFIG_NAME = "rose-meta.conf"
CONFIG_META_DIR = "meta"
Expand Down Expand Up @@ -69,16 +70,6 @@
"file:",
"poll",
]
TOP_CONFIG_DEFAULT_META_IDS = [
"file:",
"jinja2:suite.rc",
"=meta",
"=opts",
"=root-dir",
"=root-dir{share}",
"=root-dir{share/cycle}",
"=root-dir{work}",
]
CONFIG_SETTING_INDEX_DEFAULT = "1"


Expand Down Expand Up @@ -153,4 +144,4 @@
# Paths in the Rose distribution.
FILEPATH_README = "README.md"

__version__ = "2.0a1"
__version__ = "2.7.0"
9 changes: 3 additions & 6 deletions source/rose_picker/rose/c3.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (C) 2012-2019 British Crown (Met Office) & Contributors.
#
#!/usr/bin/env python3
# Copyright (C) British Crown (Met Office) & Contributors.
# This file is part of Rose, a framework for meteorological suites.
#
# Rose is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -104,7 +101,7 @@ def mro(target_name, get_base_names, *args, **kwargs):
return results[target_name]


class _Test(object):
class _Test:
"""Self tests. Print results in TAP format.

Ordering obtained from http://www.python.org/download/releases/2.3/mro/.
Expand Down
Loading
Loading