Skip to content

Commit 70419ea

Browse files
committed
Merge branch 'stage-0.1' into release
2 parents cf02c39 + 1b7774a commit 70419ea

30 files changed

+2435
-217
lines changed

.codecov.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Codecov configuration to make it a bit less noisy
2+
coverage:
3+
status:
4+
patch: false
5+
project:
6+
default:
7+
threshold: 50%
8+
comment:
9+
layout: "header"
10+
require_changes: false
11+
branches: null
12+
behavior: default
13+
flags: null
14+
paths: null

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
on: [push, pull_request]
3+
4+
env:
5+
HSD_PYTHON_VERSION: '0.1'
6+
7+
jobs:
8+
test:
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
16+
- uses: actions/setup-python@v1
17+
with:
18+
python-version: '3.x'
19+
20+
- name: Install requirements (PIP)
21+
run: pip3 install pytest sphinx numpy build
22+
23+
- name: Setup up root directory
24+
run: echo "PACKAGE_ROOT=${PWD}/src" >> $GITHUB_ENV
25+
26+
- name: Build and install package
27+
run: |
28+
python -m build
29+
pip install dist/hsd_python*.whl
30+
python -c "import hsd; assert hsd.__version__ == '${HSD_PYTHON_VERSION}'"
31+
32+
- name: Run test pytest
33+
run: python3 -m pytest
34+
35+
- name: Run doctest
36+
run: cd docs; make doctest

.lgtm.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Configure LGTM for this package
2+
3+
extraction:
4+
python: # Configure Python
5+
python_setup: # Configure the setup
6+
version: 3 # Specify Version 3
7+
path_classifiers:
8+
library:
9+
- src/versioneer.py # Set Versioneer.py to an external "library" (3rd party code)
10+
- devtools/*
11+
generated:
12+
- src/hsd/_version.py

.travis.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
language: python
2+
3+
# Run jobs on container-based infrastructure, can be overridden per job
4+
5+
matrix:
6+
include:
7+
# Extra includes for OSX since python language is not available by default on OSX
8+
- os: osx
9+
language: generic
10+
env: PYTHON_VER=3.6
11+
- os: osx
12+
language: generic
13+
env: PYTHON_VER=3.7
14+
15+
16+
# Pip can use Travis build-in Python
17+
- os: linux
18+
python: 3.6
19+
- os: linux
20+
dist: xenial # Travis Trusty image does not have Python 3.7, Xenial does
21+
python: 3.7
22+
23+
24+
before_install:
25+
# Additional info about the build
26+
- uname -a
27+
- df -h
28+
- ulimit -a
29+
30+
# Install the Python environment
31+
- source devtools/travis-ci/before_install.sh
32+
- python -V
33+
34+
install:
35+
36+
# Install the package locally
37+
- pip install -U pytest pytest-cov codecov
38+
- pip install -e src/
39+
40+
41+
script:
42+
- pytest -v --cov=hsd test/
43+
44+
notifications:
45+
email: false
46+
47+
after_success:
48+
- codecov

CHANGELOG.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
==========
2+
Change Log
3+
==========
4+
5+
6+
0.1
7+
===
8+
9+
Added
10+
-----
11+
12+
* Basic functionality to manipulate HSD-data in Python.
13+
14+
* Pip installation

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2020 Bálint Aradi, Universität Bremen
1+
Copyright (c) 2011-2021 DFTB+ developers group
22

33
All rights reserved.
44

README.rst

Lines changed: 90 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
1-
************************************
2-
HSD — Human-friendly Structured Data
3-
************************************
1+
**********************************************
2+
HSD — Make your structured data human friendly
3+
**********************************************
44

5-
This Python package contains utilities to write (and soon also to read) files in
6-
the Human-friendly Structured Data (HSD) format.
5+
Utilities to read and write files in the Human-friendly Structured Data (HSD)
6+
format.
77

8-
It is licensed under the *BSD 2-clause license*.
8+
The HSD-format is very similar to both JSON and YAML, but tries to minimize the
9+
effort for **humans** to read and write it. It ommits special characters as much
10+
as possible (in contrast to JSON) and is not indentation dependent (in contrast
11+
to YAML). It was developed originally as the input format for the scientific
12+
simulation tool (`DFTB+ <https://github.com/dftbplus/dftbplus>`_), but is
13+
of general purpose. Data stored in HSD can be easily mapped to a subset of JSON
14+
or XML and vica versa.
915

16+
Detailed `documentation <https://hsd-python.readthedocs.io/>`_ can be found on
17+
`Read the Docs <https://hsd-python.readthedocs.io/>`_.
1018

11-
The HSD format
12-
==============
1319

14-
The HSD-format is very similar to both JSON and XML, but tries to minimize the
15-
effort for humans to read and write it. It ommits special characters as much as
16-
possible but (in contrast to YAML for example) is not indentation dependent.
20+
Installation
21+
============
22+
23+
The package can be installed via conda-forge::
24+
25+
conda install --channel "conda-forge" hsd-python
26+
27+
Alternatively, the package can be downloaded and installed via pip into the
28+
active Python interpreter (preferably using a virtual python environment) by ::
29+
30+
pip install hsd
31+
32+
or into the user space issueing ::
1733

18-
It was developed originally developed as the input format for a scientific
19-
simulation tool (DFTB+), but is absolutely general. A typical input written in
20-
HSD would look like ::
34+
pip install --user hsd
35+
36+
37+
Quick tutorial
38+
==============
39+
40+
A typical, self-explaining input written in HSD looks like ::
2141

2242
driver {
2343
conjugate_gradients {
@@ -35,11 +55,13 @@ HSD would look like ::
3555
}
3656
filling {
3757
fermi {
38-
temperature [kelvin] = 1e-8
58+
# This is comment which will be ignored
59+
# Note the attribute (unit) of the field below
60+
temperature [kelvin] = 100
3961
}
4062
}
4163
k_points_and_weights {
42-
supercell_folding = {
64+
supercell_folding {
4365
2 0 0
4466
0 2 0
4567
0 0 2
@@ -49,12 +71,56 @@ HSD would look like ::
4971
}
5072
}
5173

52-
Content in HSD format can be represented as JSON. Content in JSON format can be
53-
represented as HSD, provided it satisfies a restriction for arrays: Either all
54-
elements of an array must be objects or none of them. (This allows for a clear
55-
separation of structure and data and allows for the very simple input format.)
74+
The above input can be parsed into a Python dictionary with::
75+
76+
import hsd
77+
hsdinput = hsd.load("test.hsd")
78+
79+
The dictionary ``hsdinput`` will then look as::
80+
81+
{
82+
"driver": {
83+
"conjugate_gradients" {
84+
"moved_atoms": [1, 2, "7:19"],
85+
"max_steps": 100
86+
}
87+
},
88+
"hamiltonian": {
89+
"dftb": {
90+
"scc": True,
91+
"scc_tolerance": 1e-10,
92+
"mixer": {
93+
"broyden": {}
94+
},
95+
"filling": {
96+
"fermi": {
97+
"temperature": 100,
98+
"temperature.attrib": "kelvin"
99+
}
100+
}
101+
"k_points_and_weights": {
102+
"supercell_folding": [
103+
[2, 0, 0],
104+
[0, 2, 0],
105+
[0, 0, 2],
106+
[0.5, 0.5, 0.5]
107+
]
108+
}
109+
}
110+
}
111+
}
112+
113+
Being a simple Python dictionary, it can be easily queried and manipulated in
114+
Python ::
115+
116+
hsdinput["driver"]["conjugate_gradients"]["max_steps"] = 200
117+
118+
and then stored again in HSD format ::
119+
120+
hsd.dump(hsdinput, "test2.hsd")
121+
122+
123+
License
124+
========
56125

57-
Content in HSD format can be represented as XML (DOM-tree). Content in XML can
58-
be converted to HSD, provided it satisfies the restriction that every child has
59-
either data (text) or further children, but never both of them. (Again, this
60-
ensures the simplicity of the input format.)
126+
The hsd-python package is licensed under the `BSD 2-clause license <LICENSE>`_.

devtools/set_version

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env python3
2+
3+
"""Sets a version number in all relevant project files"""
4+
5+
import sys
6+
import re
7+
import os
8+
9+
# The pattern the version number must satisfy
10+
VERSION_PATTERN = r'\d+\.\d+(?:\.\d+)?(?:-\w+)?'
11+
12+
# List of (file name, search pattern, replacement pattern) tuples for all
13+
# the occurancies to be replaced.
14+
FILES_PATTERNS = [('src/hsd/__init__.py',
15+
r'^__version__\s*=\s*([\'"]){}\1'.format(VERSION_PATTERN),
16+
"__version__ = '{version}'"),
17+
('docs/introduction.rst',
18+
r'hsd-python version[ ]*{}.'.format(VERSION_PATTERN),
19+
'hsd-python version {shortversion}.'),
20+
('setup.cfg',
21+
r'version\s*=\s*{}'.format(VERSION_PATTERN),
22+
"version = {version}"),
23+
('docs/conf.py',
24+
r'release\s*=\s*([\'"]){}\1'.format(VERSION_PATTERN),
25+
"release = '{version}'"),
26+
('.github/workflows/ci.yml',
27+
r'HSD_PYTHON_VERSION:\s*([\'"]){}\1'.format(VERSION_PATTERN),
28+
"HSD_PYTHON_VERSION: '{version}'"),
29+
]
30+
31+
32+
def main():
33+
"""Main script."""
34+
35+
if len(sys.argv) < 2:
36+
sys.stderr.write("Missing version string\n")
37+
sys.exit(1)
38+
39+
version, shortversion = _get_version_strings(sys.argv[1])
40+
rootdir = os.path.join(os.path.dirname(sys.argv[0]), '..')
41+
_replace_version_in_files(FILES_PATTERNS, rootdir, version, shortversion)
42+
_replace_version_in_changelog(rootdir, version)
43+
44+
45+
def _get_version_strings(version):
46+
"""Returns version and the short version as string"""
47+
48+
match = re.match(VERSION_PATTERN, version)
49+
if match is None:
50+
print("Invalid version string")
51+
sys.exit(1)
52+
53+
shortversion = '.'.join(version.split('.')[0:2])
54+
return version, shortversion
55+
56+
57+
def _replace_version_in_files(files_patterns, rootdir, version, shortversion):
58+
"""Replaces version number in given files with given search/replacement patterns"""
59+
60+
for fname, regexp, repl in files_patterns:
61+
fname = os.path.join(rootdir, fname)
62+
print("Replacments in '{}': ".format(os.path.relpath(fname, rootdir)), end='')
63+
fp = open(fname, 'r')
64+
txt = fp.read()
65+
fp.close()
66+
replacement = repl.format(version=version, shortversion=shortversion)
67+
newtxt, nsub = re.subn(regexp, replacement, txt, flags=re.MULTILINE)
68+
print(nsub)
69+
fp = open(fname, 'w')
70+
fp.write(newtxt)
71+
fp.close()
72+
73+
74+
def _replace_version_in_changelog(rootdir, version):
75+
"""Replaces the unreleased section in CHANGELOG.rst"""
76+
77+
fname = os.path.join(rootdir, 'CHANGELOG.rst')
78+
print("Replacments in '{}': ".format(os.path.relpath(fname, rootdir)), end='')
79+
fp = open(fname, 'r')
80+
txt = fp.read()
81+
fp.close()
82+
decoration = '=' * len(version)
83+
newtxt, nsub = re.subn(
84+
r'^Unreleased\s*\n=+', version + r'\n' + decoration, txt,
85+
count=1, flags=re.MULTILINE)
86+
print(nsub)
87+
fp = open(fname, 'w')
88+
fp.write(newtxt)
89+
fp.close()
90+
91+
92+
if __name__ == '__main__':
93+
main()

devtools/travis-ci/before_install.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Temporarily change directory to $HOME to install software
2+
pushd .
3+
cd $HOME
4+
# Make sure some level of pip is installed
5+
python -m ensurepip
6+
7+
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
8+
HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade pyenv
9+
# Pyenv requires minor revision, get the latest
10+
PYENV_VERSION=$(pyenv install --list |grep $PYTHON_VER | sed -n "s/^[ \t]*\(${PYTHON_VER}\.*[0-9]*\).*/\1/p" | tail -n 1)
11+
# Install version
12+
pyenv install $PYENV_VERSION
13+
# Use version for this
14+
pyenv global $PYENV_VERSION
15+
# Setup up path shims
16+
eval "$(pyenv init -)"
17+
fi
18+
pip install --upgrade pip setuptools
19+
20+
# Restore original directory
21+
popd

0 commit comments

Comments
 (0)