Skip to content

Commit

Permalink
Setup Python package information and build setup for 3.12 (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
charnley authored Feb 11, 2024
1 parent 250b111 commit 68eaf19
Show file tree
Hide file tree
Showing 7,278 changed files with 747 additions and 183 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

name: Test Python package

on:
push:
branches:
- '**'
pull_request:
branches: [ main ]

jobs:
test:
name: Testing
runs-on: "ubuntu-latest"
defaults:
run:
shell: bash -l {0}
strategy:
matrix:
python-version: ['3.12']
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: dev
environment-file: ./environment_dev.yaml
python-version: ${{ matrix.python-version }}
- run: |
ls
pwd
which python
conda info
- run: pip install . -v
- run: make test python=python
# - run: make format python=python
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# repo specific
./env
*.sqlite3
*.whl


# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
args: ['--maxkb=3000']

- repo: https://github.com/myint/autoflake
rev: v1.4
rev: v2.2.0
hooks:
- id: autoflake
name: Removes unused variables
Expand Down Expand Up @@ -54,7 +54,7 @@ repos:
args: ["--line-length=99"]

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 7.0.0
hooks:
- id: flake8
name: Checks pep8 style
Expand All @@ -65,7 +65,8 @@ repos:
# ignore long comments (E501), as long lines are formatted by black
# ignore Whitespace before ':' (E203)
# ignore Line break occurred before a binary operator (W503)
"--ignore=E501,E203,W503",
# ignore ambiguous variable name (E741)
"--ignore=E501,E203,W503,E741",
]

- repo: https://github.com/pseewald/fprettify
Expand Down
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
python=./env/bin/python
mamba=mamba
pkg=qmllib
pip=./env/bin/pip
j=1

.PHONY: build

all: env setup

env:
${mamba} env create -f ./environment_dev.yaml -p ./env --quiet
${pip} install -e .

setup: ./.git/hooks/pre-commit

./.git/hooks/pre-commit:
${python} -m pre_commit install

format:
${python} -m pre_commit run --all-files

test:
${python} -m pytest -rs \
./tests/test_kernels.py \
./tests/test_solvers.py \
./tests/test_distance.py \
./tests/test_slatm.py

types:
${python} -m monkeytype run $(which pytest) ./tests/
${python} -m monkeytype list-modules | grep ${pkg} | parallel -j${j} "${python} -m monkeytype apply {}"

cov:
${python} -m pytest -vrs --cov=${pkg} --cov-report html tests

compile:
${python} _compile.py

build:
@#${python} -m build .
# ${python} -m pip wheel --no-deps -v .
${python} -m pip wheel -v .
ls *.whl

clean:
find ./src/ -type f \
-name "*.so" \
-name "*.pyc" \
-name ".pyo" \
-delete
rm -rf *.whl
rm -fr ./build/ ./__pycache__/

clean-env:
rm -rf ./env/
rm ./.git/hooks/pre-commit
33 changes: 32 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,30 @@ This package is and should stay free-function design oriented.
How to install
====

raise NotImplementedError
A proper pip-package is on the way, for now

pip install git+https://github.com/qmlcode/qmllib

or if you want a specific feature branch

pip install git+https://github.com/qmlcode/qmllib@feature_branch

====
How to start developing
====

Know a issue and want to get started developing?

git clone repo.url qmllib.git
cd qmllib.git
make # setup env
make compile # compile

You know have a conda environment in `./env` and are ready to run

make test

happy developing

====
How to use
Expand All @@ -45,3 +68,11 @@ How to contribute
* Create pull requests
* Create discussions

=====
What TODO
=====

* Setup ifort flags
* Setup based on FCC env variable or --global-option flags
* Find MKL from env (for example conda)
* Find what numpy has been linked too (lapack or mkl)
89 changes: 89 additions & 0 deletions _compile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
""" Compile script for Fortran """

import os
import subprocess
from pathlib import Path

f90_modules = {
"representations/frepresentations": ["frepresentations.f90"],
"representations/facsf": ["facsf.f90"],
"representations/fslatm": ["fslatm.f90"],
"representations/fchl/ffchl_module": [
"ffchl_module.f90",
"ffchl_scalar_kernels.f90",
"ffchl_kernel_types.f90",
"ffchl_kernels.f90",
"ffchl_electric_field_kernels.f90",
"ffchl_force_kernels.f90",
],
"solvers/fsolvers": ["fsolvers.f90"],
"kernels/fdistance": ["fdistance.f90"],
"kernels/fkernels": ["fkernels.f90", "fkpca.f90"],
"kernels/fgradient_kernels": ["fgradient_kernels.f90"],
}


def find_mkl():

return


def find_flags(fcc: str):
"""Find compiler flags"""

# TODO Find math lib
# TODO Find os

# -lgomp", "-lpthread", "-lm", "-ldl
# ["-L${MKLROOT}/lib/intel64", "-lmkl_rt"]

# COMPILER_FLAGS = ["-O3", "-fopenmp", "-m64", "-march=native", "-fPIC",
# "-Wno-maybe-uninitialized", "-Wno-unused-function", "-Wno-cpp"]
# LINKER_FLAGS = ["-lgomp"]

flags = ["-L/usr/lib/", "-lblas", "-llapack"]

return flags


def find_fcc():
"""Find the fortran compiler. Either gnu or intel"""

# fcc = "ifort"
fcc = "gfortran"

return fcc


def main():
"""Compile f90 in src/qmllib"""

fcc = find_fcc()
flags = find_flags(fcc)

os.environ["FCC"] = fcc

for module_name, module_sources in f90_modules.items():

path = Path(module_name)

parent = path.parent
stem = path.stem
cwd = Path("src/qmllib") / parent
cmd = ["python", "-m", "numpy.f2py", "-c"] + flags + module_sources + ["-m", str(stem)]
print(cwd, " ".join(cmd))

proc = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
stdout = proc.stdout
stderr = proc.stderr
exitcode = proc.returncode

if exitcode > 0:
print(stdout)
print()
print(stderr)
exit(exitcode)


if __name__ == "__main__":
main()
18 changes: 18 additions & 0 deletions environment_dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: qmllib_dev
channels:
- conda-forge
- defaults
dependencies:
- python==3.12
- jupytext
- monkeytype
- numpy
- pandas
- pip
- pre-commit
- pytest
- scikit-learn
- scipy
# build
- meson
- ninja
25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[build-system]
requires = ["setuptools", "numpy", "meson", "ninja"]
build-backend = "setuptools.build_meta"

[project]
name = "qmllib"
dynamic = ["version"]
authors = []
requires-python = ">=3.12"

[options.packages.find]
where="src"

[tool.setuptools]
include-package-data = true

[tool.setuptools.dynamic]
version = {attr = "qmllib.version.__version__"}

[tool.setuptools.package-data]
"*" = ['*.so']


# [tool.black]
# line-length = 120
8 changes: 8 additions & 0 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"include": [
"src"
],
"exclude": [
"env"
]
}
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
log_cli_level = DEBUG
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)
log_cli_date_format=%Y-%m-%d %H:%M:%S
14 changes: 14 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys
from pathlib import Path

from setuptools import setup

try:
import _compile
except ImportError:
sys.path.append(str(Path(__file__).resolve().parent))
import _compile

if __name__ == "__main__":
_compile.main()
setup()
1 change: 1 addition & 0 deletions src/qmllib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from qmllib.version import __version__
Empty file.
Loading

0 comments on commit 68eaf19

Please sign in to comment.