Skip to content

Commit

Permalink
Proposal to use pre-commit for continuous integration (#113)
Browse files Browse the repository at this point in the history
* Add pre-commit

* FIx typing

* Play with flake8

* Fix bug

* Update README.md

* Remove unnecessary file
  • Loading branch information
dachengx authored Aug 31, 2023
1 parent ae7a784 commit ecc08a4
Show file tree
Hide file tree
Showing 65 changed files with 1,831 additions and 1,787 deletions.
16 changes: 0 additions & 16 deletions .github/scripts/pre_pyflakes.sh

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/code_style.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
args: [--safe, --line-length=100]
- id: black-jupyter
args: [--safe, --line-length=100]
language_version: python3.9

- repo: https://github.com/pycqa/docformatter
rev: v1.7.5
hooks:
- id: docformatter

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
additional_dependencies: [types-PyYAML, types-tqdm]

- repo: https://github.com/pycqa/doc8
rev: v1.1.1
hooks:
- id: doc8
files: ^docs/.*\.(rst|md)$

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8

ci:
autoupdate_schedule: weekly
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ A high-Performance Program simuLatEs and fiTs REsponse of xEnon.
[![PyPI version shields.io](https://img.shields.io/pypi/v/appletree.svg)](https://pypi.python.org/pypi/appletree/)
[![Readthedocs Badge](https://readthedocs.org/projects/appletree/badge/?version=latest)](https://appletree.readthedocs.io/en/latest/?badge=latest)
[![CodeFactor](https://www.codefactor.io/repository/github/xenonnt/appletree/badge)](https://www.codefactor.io/repository/github/xenonnt/appletree)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/XENONnT/appletree/master.svg)](https://results.pre-commit.ci/latest/github/XENONnT/appletree/master)

## Installation and Set-Up

Expand Down Expand Up @@ -54,7 +55,7 @@ Then you are now good to go!

## Usage

The best way to start with the `appletree` package is to have a look at the tutorial `notebooks`.
The best way to start with the `appletree` package is to have a look at the tutorial `notebooks`.

## Contributing

Expand Down
36 changes: 14 additions & 22 deletions appletree/__init__.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,62 @@
__version__ = '0.2.3'
__version__ = "0.2.3"

# stop jax to preallocate memory
import os
os.environ['XLA_PYTHON_CLIENT_PREALLOCATE'] = 'false'
os.environ['XLA_PYTHON_CLIENT_ALLOCATOR'] = 'platform'

os.environ["XLA_PYTHON_CLIENT_PREALLOCATE"] = "false"
os.environ["XLA_PYTHON_CLIENT_ALLOCATOR"] = "platform"

from . import utils
from .utils import *

from . import hist
from .hist import *

from . import interpolation
from .interpolation import *

from . import config
from .config import *

from . import parameter
from .parameter import *

from . import randgen
from .randgen import *

from . import share
from .share import *

from . import plugins

from . import plugin
from .plugin import *

from . import components
from .components import *

from . import component
from .component import *

from . import likelihood
from .likelihood import *

from . import contexts
from .contexts import *

from . import context
from .context import *

# check CUDA support setup
from warnings import warn

platform = utils.get_platform()
if platform == 'cpu':
warning = 'You are running appletree on CPU, which usually results in low performance.'
if platform == "cpu":
warning = "You are running appletree on CPU, which usually results in low performance."
warn(warning)
try:
import jax

# try allocate something
jax.numpy.ones(1)
except BaseException:
if platform == 'gpu':
print('Can not allocate memory on GPU, please check your CUDA version.')
raise ImportError(f'Appletree is not correctly setup to be used on {platform.upper()}.')
if platform == "gpu":
print("Can not allocate memory on GPU, please check your CUDA version.")
raise ImportError(f"Appletree is not correctly setup to be used on {platform.upper()}.")

try:
import aptext

HAVE_APTEXT = True
print('Using aptext package from https://github.com/XENONnT/applefiles')
print("Using aptext package from https://github.com/XENONnT/applefiles")
except ImportError:
HAVE_APTEXT = False
print('Can not find aptext')
print("Can not find aptext")
Loading

0 comments on commit ecc08a4

Please sign in to comment.