Skip to content

Commit d178fb9

Browse files
Merge pull request #14 from ACCESS-NRI/pyproject_and_readme_cleanup
Several improvements (pyproject cleanup, updated Readme, etc)
2 parents 4c7acfd + b19835e commit d178fb9

File tree

3 files changed

+133
-9
lines changed

3 files changed

+133
-9
lines changed

README.md

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,104 @@
11
# access-parsers
22

3-
*A Python package of various functions to read and write configuration files for the models developed at [ACCESS](https://github.com/ACCESS-NRI).*
4-
53
![CI](https://github.com/ACCESS-NRI/access-parsers/actions/workflows/ci.yml/badge.svg) [![codecov](https://codecov.io/github/ACCESS-NRI/access-parsers/graph/badge.svg?token=KtmrCtSyMv)](https://codecov.io/github/ACCESS-NRI/access-parsers) [![License](https://img.shields.io/badge/license-Apache%202.0-blue?style=flat-square)](https://opensource.org/license/apache-2-0) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
4+
5+
## About
6+
7+
A Python package providing various parsers to read and write various types of files used in the models developed at [ACCESS-NRI](https://github.com/ACCESS-NRI).
8+
9+
## Key Features
10+
11+
- Parsers for configuration files used across ACCESS-NRI models
12+
- Support for round-trip parsing, preserving comments and formatting
13+
- Simple API
14+
15+
## Documentation
16+
17+
Coming soon.
18+
19+
## Installation
20+
21+
### Using pip
22+
23+
You can install the latest release directly from PyPI:
24+
'''shell
25+
pip install access-parsers
26+
'''
27+
28+
### From source
29+
30+
If you prefer to install from source:
31+
'''shell
32+
git clone https://github.com/ACCESS-NRI/access-parsers.git
33+
cd access-parsers
34+
pip install .
35+
'''
36+
37+
## Usage
38+
39+
Here is a simple example of how to parse a text and modify its contents.
40+
41+
To parse some text, one just needs to call the `parse` function of the appropriate parser:
42+
'''python
43+
from access.parsers import FortranNMLParser
44+
45+
text = '''&data_nml
46+
parameterA = 1
47+
parameterB = 'abc'
48+
/'''
49+
50+
config = FortranNMLParser().parse(text)
51+
print(config)
52+
'''
53+
'''python
54+
&data_nml
55+
parameterA = 1
56+
parameterB = 'abc'
57+
/
58+
'''
59+
60+
The parsed content can then be modified just like any Python dict:
61+
'''python
62+
config["data_nml"]["parameterA"] = 2
63+
print(config)
64+
'''
65+
'''python
66+
&data_nml
67+
parameterA = 2
68+
parameterB = 'abc'
69+
/
70+
'''
71+
72+
## Development installation
73+
74+
If you intend to contribute or modify the package, it is recommended to work inside a virtual environment.
75+
76+
1. Create and activate a virtual environment
77+
'''shell
78+
# Create a virtual environment
79+
python3 -m venv .venv
80+
81+
# Activate the virtual environment
82+
source .venv/bin/activate
83+
'''
84+
85+
2. Install in editable mode with development and test dependencies
86+
'''shell
87+
pip install -e ".[devel,test]"
88+
'''
89+
This will install the package in editable mode, meaning changes to the source code are reflected immediately without reinstallation. Development dependencies such as testing tools will also be installed.
90+
91+
3. Run the test suite
92+
'''shell
93+
pytest
94+
'''
95+
96+
## Contributing
97+
98+
Contributions are welcome! Please open an issue or submit a pull request if you’d like to add features, fix bugs, or improve documentation.
99+
100+
For significant contributions, we recommend discussing proposed changes in an issue before opening a pull request.
101+
102+
## License
103+
104+
This project is licensed under the Apache 2.0 License.

pyproject.toml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,9 @@ dependencies = [
1919
]
2020

2121
[build-system]
22-
requires = ["setuptools", "setuptools_scm[toml]"]
22+
requires = ["setuptools>=80", "setuptools_scm[toml]>=8"]
2323
build-backend = "setuptools.build_meta"
2424

25-
26-
[tool.setuptools_scm]
27-
write_to = "src/access/parsers/_version.py"
28-
29-
3025
[project.optional-dependencies]
3126
devel = [
3227
"flake8",
@@ -43,7 +38,7 @@ addopts = ["--cov=access.parsers", "--cov-report=term", "--cov-report=html", "--
4338
testpaths = ["tests"]
4439

4540
[tool.coverage.run]
46-
omit = ["src/access/parsers/__init__.py", "src/access/parsers/_version.py"]
41+
omit = ["src/access/parsers/__init__.py"]
4742

4843
[tool.black]
4944
line-length = 120

src/access/parsers/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
access-parsers package.
3+
"""
4+
5+
__version__ = "0.1.0"
6+
from importlib.metadata import version, PackageNotFoundError
7+
8+
try:
9+
__version__ = version("access-parsers")
10+
except PackageNotFoundError:
11+
# package is not installed
12+
pass
13+
14+
from .config import ConfigParser
15+
from .fortran_nml import FortranNMLParser
16+
from .mom6_input import MOM6InputParser
17+
from .yaml_config import YAMLParser
18+
from .nuopc_config import NUOPCParser
19+
from .profiling import ProfilingParser
20+
from .fms_profiling import FMSProfilingParser
21+
22+
__all__ = [
23+
"ConfigParser",
24+
"FortranNMLParser",
25+
"MOM6InputParser",
26+
"YAMLParser",
27+
"NUOPCParser",
28+
"ProfilingParser",
29+
"FMSProfilingParser",
30+
]

0 commit comments

Comments
 (0)