-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Marcel Müller <[email protected]>
Showing
19 changed files
with
392 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.6.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-shebang-scripts-are-executable | ||
- id: check-toml | ||
- id: check-yaml | ||
- id: check-added-large-files | ||
- id: debug-statements | ||
language_version: python3 | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.5.7 | ||
hooks: | ||
# Run the linter. | ||
- id: ruff | ||
types_or: [ python, pyi, jupyter ] | ||
args: [ --fix ] | ||
# Run the formatter. | ||
- id: ruff-format | ||
types_or: [ python, pyi, jupyter ] | ||
|
||
- repo: https://github.com/asottile/pyupgrade | ||
rev: v3.17.0 | ||
hooks: | ||
- id: pyupgrade | ||
|
||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: v1.11.1 | ||
hooks: | ||
- id: mypy | ||
|
||
default_language_version: | ||
python: python3.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
## MindLess Molecule GENerator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# conda env create -f environment.yaml | ||
name: mlmgen | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- ruff | ||
- coverage | ||
- numpy | ||
- pre-commit | ||
- pytest | ||
- tox | ||
- pip: | ||
- covdefaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
[build-system] | ||
requires = ["wheel", "setuptools>=64", "setuptools_scm>=8"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "mlmgen" | ||
authors = [ | ||
{ name = "Marcel Müller", email = "[email protected]" }, | ||
] | ||
description = "MindLess Molecule GENerator" | ||
readme = "README.md" | ||
requires-python = ">=3.8" | ||
license = { file = "LICENSE.md" } | ||
classifiers = [ | ||
"License :: OSI Approved :: MIT License", | ||
"Programming Language :: Python :: 3 :: Only", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
"Topic :: Scientific/Engineering", | ||
"Typing :: Typed", | ||
] | ||
dependencies = ["numpy"] | ||
dynamic = ["version"] | ||
|
||
[project.optional-dependencies] | ||
dev = [ | ||
"ruff", | ||
"covdefaults", | ||
"coverage", | ||
"pre-commit", | ||
"pytest", | ||
"tox", | ||
"setuptools_scm>=8", | ||
] | ||
|
||
[project.scripts] | ||
mlmgen = "mlmgen:console_entry_point" | ||
|
||
[tool.setuptools_scm] | ||
version_file = "src/mlmgen/__version__.py" | ||
|
||
[tool.pytest.ini_options] | ||
testpaths = ["test"] | ||
pythonpath = ["src"] | ||
|
||
[tool.coverage.run] | ||
plugins = ["covdefaults"] | ||
source = ["./src"] | ||
|
||
[tool.coverage.report] | ||
fail_under = 50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
Squarer | ||
======= | ||
Dummy command line tool to square a number. | ||
""" | ||
|
||
from .__version__ import __version__ | ||
from .cli import console_entry_point | ||
from .mymath import square_a_number as square | ||
|
||
__all__ = ["__version__", "console_entry_point", "square"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" | ||
Entry point for command line interface via `python -m <prog>`. | ||
""" | ||
|
||
from .cli import console_entry_point | ||
|
||
if __name__ == "__main__": | ||
# print("Hello from __main__.py") | ||
raise SystemExit(console_entry_point()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# file generated by setuptools_scm | ||
# don't change, don't track in version control | ||
TYPE_CHECKING = False | ||
if TYPE_CHECKING: | ||
from typing import Tuple, Union | ||
|
||
VERSION_TUPLE = Tuple[Union[int, str], ...] | ||
else: | ||
VERSION_TUPLE = object | ||
|
||
version: str | ||
__version__: str | ||
__version_tuple__: VERSION_TUPLE | ||
version_tuple: VERSION_TUPLE | ||
|
||
__version__ = version = "0.1.dev26+g7432299.d20240810" | ||
__version_tuple__ = version_tuple = (0, 1, "dev26", "g7432299.d20240810") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
""" | ||
Command line interface | ||
====================== | ||
This module contains functionality for the CLI. | ||
""" | ||
|
||
from .entrypoint import console_entry_point | ||
|
||
__all__ = ["console_entry_point"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
Entrypoint for command line interface. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import argparse | ||
from collections.abc import Sequence | ||
|
||
from ..mymath import square_a_number as square | ||
|
||
|
||
def console_entry_point(argv: Sequence[str] | None = None) -> int: | ||
# get command line argument | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("number", type=float, help="Number to square.") | ||
args = parser.parse_args(argv) | ||
|
||
# print result | ||
print(square(args.number)) | ||
|
||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
""" | ||
Math | ||
==== | ||
This module contains all mathematical functions. | ||
""" | ||
|
||
from .calc import square_a_number | ||
|
||
__all__ = ["square_a_number"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
Mathematical functions. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
|
||
def square_a_number(a: float | int) -> float | int: | ||
if not isinstance(a, (float, int)): | ||
raise TypeError("Float or int expected.") | ||
|
||
return a * a |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
""" | ||
Setup for pytest. | ||
""" | ||
|
||
import numpy as np | ||
|
||
# import pytest | ||
|
||
np.random.seed(0) | ||
np.set_printoptions(precision=16) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
Test program call from command line. | ||
""" | ||
|
||
import pytest | ||
|
||
from mlmgen.cli import console_entry_point | ||
|
||
|
||
def test_entrypoint(capsys: pytest.CaptureFixture) -> None: | ||
# pylint: disable=too-many-function-args | ||
console_entry_point(["2.0"]) | ||
|
||
out, err = capsys.readouterr() | ||
assert out == "4.0\n" | ||
assert err == "" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
Test the squaring function. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from mlmgen.mymath import square_a_number | ||
|
||
|
||
@pytest.mark.parametrize("value", [1.0, 2, -3.0]) | ||
def test_squarer(value: int | float) -> None: | ||
expected = value * value | ||
actual = square_a_number(value) | ||
|
||
assert pytest.approx(expected) == actual | ||
|
||
|
||
def test_squarer_fail() -> None: | ||
with pytest.raises(TypeError): | ||
square_a_number("2") # type: ignore | ||
|
||
|
||
def test_dummy() -> None: | ||
# show effect of `conftest.py` by setting printoptions | ||
print(np.array([1.0 / 3.0])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[tox] | ||
envlist = py{312} | ||
|
||
[testenv] | ||
deps = | ||
covdefaults | ||
coverage | ||
pytest | ||
commands = | ||
coverage erase | ||
coverage run -m pytest -svv {posargs:test} | ||
coverage report -m | ||
coverage xml -o coverage.xml |