Skip to content

Commit af3bd95

Browse files
authored
Merge pull request #10 from s-sajid-ali/cleanup_and_ci
refactor & CI with GithubActions
2 parents 1f334c9 + 821c966 commit af3bd95

23 files changed

+480
-251
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Set update schedule for GitHub Actions
2+
3+
version: 2
4+
updates:
5+
6+
- package-ecosystem: "github-actions"
7+
directory: "/"
8+
schedule:
9+
# Check for updates to GitHub Actions every week
10+
interval: "weekly"
11+

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Python package
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: ["3.10", "3.11", "3.12"]
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- name: Install dependencies
20+
run: python -m pip install .[test]
21+
- name: Test with pytest
22+
run: pytest
23+

.gitignore

Lines changed: 160 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,169 @@
1-
# setuptools
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
211
build/
12+
develop-eggs/
313
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
424
*.egg-info/
5-
__pycache__
6-
*.pyc
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
728

829
# conda
930
conda_recipe/linux-64/
1031
conda_recipe/linux-ppc64le/
1132
conda_recipe/osx-64/
1233
conda_recipe/win-64/
34+
35+
# PyInstaller
36+
# Usually these files are written by a python script from a template
37+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
38+
*.manifest
39+
*.spec
40+
41+
# Installer logs
42+
pip-log.txt
43+
pip-delete-this-directory.txt
44+
45+
# Unit test / coverage reports
46+
htmlcov/
47+
.tox/
48+
.nox/
49+
.coverage
50+
.coverage.*
51+
.cache
52+
nosetests.xml
53+
coverage.xml
54+
*.cover
55+
*.py,cover
56+
.hypothesis/
57+
.pytest_cache/
58+
cover/
59+
60+
# Translations
61+
*.mo
62+
*.pot
63+
64+
# Django stuff:
65+
*.log
66+
local_settings.py
67+
db.sqlite3
68+
db.sqlite3-journal
69+
70+
# Flask stuff:
71+
instance/
72+
.webassets-cache
73+
74+
# Scrapy stuff:
75+
.scrapy
76+
77+
# Sphinx documentation
78+
docs/_build/
79+
80+
# PyBuilder
81+
.pybuilder/
82+
target/
83+
84+
# Jupyter Notebook
85+
.ipynb_checkpoints
86+
87+
# IPython
88+
profile_default/
89+
ipython_config.py
90+
91+
# pyenv
92+
# For a library or package, you might want to ignore these files since the code is
93+
# intended to run in multiple environments; otherwise, check them in:
94+
# .python-version
95+
96+
# pipenv
97+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
98+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
99+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
100+
# install all needed dependencies.
101+
#Pipfile.lock
102+
103+
# poetry
104+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105+
# This is especially recommended for binary packages to ensure reproducibility, and is more
106+
# commonly ignored for libraries.
107+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108+
#poetry.lock
109+
110+
# pdm
111+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112+
#pdm.lock
113+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114+
# in version control.
115+
# https://pdm.fming.dev/#use-with-ide
116+
.pdm.toml
117+
118+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
119+
__pypackages__/
120+
121+
# Celery stuff
122+
celerybeat-schedule
123+
celerybeat.pid
124+
125+
# SageMath parsed files
126+
*.sage.py
127+
128+
# Environments
129+
.env
130+
.venv
131+
env/
132+
venv/
133+
ENV/
134+
env.bak/
135+
venv.bak/
136+
137+
# Spyder project settings
138+
.spyderproject
139+
.spyproject
140+
141+
# Rope project settings
142+
.ropeproject
143+
144+
# mkdocs documentation
145+
/site
146+
147+
# mypy
148+
.mypy_cache/
149+
.dmypy.json
150+
dmypy.json
151+
152+
# ruff Python linter
153+
.ruff_cache/
154+
155+
# Pyre type checker
156+
.pyre/
157+
158+
# pytype static type analyzer
159+
.pytype/
160+
161+
# Cython debug symbols
162+
cython_debug/
163+
164+
# PyCharm
165+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
166+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
167+
# and can be added to the global gitignore or merged into this file. For a more nuclear
168+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
169+
#.idea/

README.md

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# openPMD Updater
22

3-
[![Build Status `master`](https://img.shields.io/travis/openPMD/openPMD-updater/master.svg?label=master)](https://travis-ci.com/openPMD/openPMD-updater/branches)
3+
[![CI:ubuntu](https://github.com/openPMD/openPMD-updater/actions/workflows/ci.yml/badge.svg)](https://github.com/openPMD/openPMD-updater/actions/workflows/ci.yml)
44
![Supported Python Versions](https://img.shields.io/pypi/pyversions/openPMD-updater.svg)
55
[![License](https://img.shields.io/badge/license-ISC-blue.svg)](https://opensource.org/licenses/ISC)
66

@@ -43,10 +43,10 @@ git clone https://github.com/openPMD/openPMD-updater.git
4343
cd openPMD-updater
4444

4545
# install dependencies
46-
pip install -r requirements.txt
46+
pip install .
4747

48-
# optional: append --user
49-
python setup.py install
48+
# with optional dependencies for testing
49+
pip install .[test]
5050
```
5151

5252
## Usage
@@ -77,26 +77,16 @@ updater.update(target_version="2.0.0", in_place=True)
7777

7878
### Testing
7979

80+
Additional packages need to be installed for the tests. To install them do:
8081
```bash
81-
export PYTHONPATH=$(pwd):$PYTHONPATH
82+
pip install .[test]
83+
```
8284

85+
Then one can run the tests as follows:
86+
```bash
8387
# all
84-
nosetests
88+
pytest
8589

8690
# specific
87-
nosetests tests/test_backend_h5.py
88-
89-
# manual
90-
python tests/test_backend_h5.py
91-
```
92-
93-
*note*: this changes your `example_files/1_1_0/structure.h5` files in-place.
94-
`git checkout` it for a reset or do a comparison:
95-
96-
```bash
97-
h5diff -c example_files/1_1_0/structure.h5.bak example_files/1_1_0/structure.h5
98-
attribute: <openPMD of </>> and <openPMD of </>>
99-
35 differences found
100-
Not comparable: <openPMDextension> is of class H5T_INTEGER and <openPMDextension> is of class H5T_STRING
101-
# ...
91+
pytest tests/test_backend_h5.py
10292
```

example_files/1_1_0/structure.h5

-92.7 KB
Binary file not shown.

openpmd_updater/Updater.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
Authors: Axel Huebl
66
License: ISC
77
"""
8+
89
import packaging.version
9-
from openpmd_updater.backends.HDF5 import HDF5
10-
from openpmd_updater.transforms.v2_0_0 import \
11-
DataOrder, GridUnit, ParticleBoundary, ExtensionString, Version
10+
from .backends.HDF5 import HDF5
11+
from .transforms.v2_0_0 import (
12+
DataOrder,
13+
GridUnit,
14+
ParticleBoundary,
15+
ExtensionString,
16+
Version,
17+
)
1218

1319

1420
class Updater(object):
@@ -18,22 +24,22 @@ class Updater(object):
1824
(see: openpmd_updater.backend.IBackend) for a given file and applies a set
1925
of transformations (see: openpmd_updater.transforms.ITransform) on it.
2026
"""
27+
2128
def __init__(self, filename, verbose=False):
22-
"""Open a file with suiteable file format backend.
23-
"""
29+
"""Open a file with suiteable file format backend."""
2430
# supported file format backends
2531
self.backends = [HDF5]
2632

2733
# dict of updates with each a list of transforms
2834
# keys: "to_version" of targeted openPMD standard version
2935
# values: ordered list of transforms
3036
self.updates = {
31-
"2.0.0" : [
37+
"2.0.0": [
3238
DataOrder.DataOrder, # must be before move of particleBoundary
3339
GridUnit.GridUnit,
3440
ParticleBoundary.ParticleBoundary,
3541
ExtensionString.ExtensionString,
36-
Version.Version # must be last
42+
Version.Version, # must be last
3743
]
3844
}
3945

@@ -44,13 +50,14 @@ def __init__(self, filename, verbose=False):
4450

4551
for b in self.backends:
4652
if self.verbose:
47-
print("[Updater] Trying file format {0}".format(type(b)))
53+
print("[Updater] Trying file format {0}".format(b.__name__))
4854
if b.can_handle(filename):
4955
self.fb = b(filename)
5056
break
5157
if self.fb is None:
52-
raise RuntimeError("No matching file format backend found for "
53-
"{0}!".format(filename))
58+
raise RuntimeError(
59+
"No matching file format backend found for " "{0}!".format(filename)
60+
)
5461

5562
def update(self, new_version="2.0.0", in_place=True):
5663
"""Perform update to new version of the openPMD standard"""
@@ -60,8 +67,15 @@ def update(self, new_version="2.0.0", in_place=True):
6067
# check if new version is known by the updater
6168
update_valid = False
6269
if new_version not in self.updates.keys():
63-
raise RuntimeError("Only updates to openPMD standard(s) '{0}' are "
64-
"supported!".format(" ".join(self.updates.keys())))
70+
raise RuntimeError(
71+
"Only updates to openPMD standard(s) '{0}' are " "supported!".format(
72+
" ".join(self.updates.keys())
73+
)
74+
)
75+
76+
if file_version == packaging.version.parse(new_version):
77+
print("[Updater] File is at already at the requested version!")
78+
return
6579

6680
# select proper update depending on initial version
6781
# note: multiple updates over intermediate openPMD standard releases are possible
@@ -70,18 +84,23 @@ def update(self, new_version="2.0.0", in_place=True):
7084
if file_version <= packaging.version.parse("1.1.0"):
7185
update_valid = True
7286
if self.verbose:
73-
print("[Updater] Performing update from {0} to "
74-
"{1}".format(file_version, new_version))
87+
print(
88+
"[Updater] Performing update from {0} to " "{1}".format(
89+
file_version, new_version
90+
)
91+
)
7592
for t in self.updates[new_version]:
7693
self.fb.cd(None)
7794
next_transform = t(self.fb)
7895
if self.verbose:
7996
name, desc = t.name
80-
print("[Updater] Transform {0}: "
81-
"{1}".format(name, desc))
97+
print("[Updater] Transform {0}: " "{1}".format(name, desc))
8298
next_transform.transform(in_place)
8399
file_version = packaging.version.parse(new_version)
84100

85101
if not update_valid:
86-
raise RuntimeError("Unsupported openPMD standard '{0}' in file "
87-
"'{1}':".format(file_version, self.filename))
102+
raise RuntimeError(
103+
"Unsupported openPMD standard '{0}' in file " "'{1}':".format(
104+
file_version, self.filename
105+
)
106+
)

openpmd_updater/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"⏫ Update openPMD files to newer versions of the openPMD standard"
2+
3+
from .Updater import *
4+
from .backends import *
5+
from .transforms import *

0 commit comments

Comments
 (0)