Skip to content

Commit

Permalink
formatting and packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
dfm committed Oct 17, 2019
1 parent 9467f7a commit b131ded
Show file tree
Hide file tree
Showing 50 changed files with 645 additions and 495 deletions.
4 changes: 4 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[settings]
line_length=79
multi_line_output=3
known_third_party = h5py,matplotlib,numpy,pytest,scipy,setuptools
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements

- repo: https://github.com/asottile/seed-isort-config
rev: v1.9.2
hooks:
- id: seed-isort-config
args: [--application-directories=src]

- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.20
hooks:
- id: isort
args: []

- repo: https://github.com/psf/black
rev: 19.3b0
hooks:
- id: black
language_version: python3.6

- repo: https://github.com/dfm/black_nbconvert
rev: v0.1.1
hooks:
- id: black_nbconvert
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include README.rst LICENSE HISTORY.rst AUTHORS.rst
include LICENSE *.rst
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import os
import sys

from emcee import __version__ # NOQA

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath(".."))
from emcee import __version__ # NOQA
sys.path.insert(0, os.path.join(os.path.abspath(".."), "src"))

extensions = [
"sphinx.ext.autodoc",
Expand Down
38 changes: 20 additions & 18 deletions document/plots/oned.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import os
import sys
import time
from multiprocessing import Pool

import numpy as np
import matplotlib.pyplot as pl
import h5py
import matplotlib.pyplot as pl
import numpy as np

from multiprocessing import Pool
import emcee

sys.path.append(os.path.abspath(os.path.join(__file__, "..", "..", "..")))
import emcee

# import acor

Expand All @@ -20,8 +20,9 @@ def lnprobfn(p, icov):

def random_cov(ndim, dof=1):
v = np.random.randn(ndim * (ndim + dof)).reshape((ndim + dof, ndim))
return (sum([np.outer(v[i], v[i]) for i in range(ndim + dof)])
/ (ndim + dof))
return sum([np.outer(v[i], v[i]) for i in range(ndim + dof)]) / (
ndim + dof
)


_rngs = {}
Expand All @@ -31,33 +32,34 @@ def _worker(args):
i, outfn, nsteps = args

pid = os.getpid()
_random = _rngs.get(pid, np.random.RandomState(int(int(pid)
+ time.time())))
_random = _rngs.get(
pid, np.random.RandomState(int(int(pid) + time.time()))
)
_rngs[pid] = _random

ndim = int(np.ceil(2 ** (7 * _random.rand())))
nwalkers = 2 * ndim + 2
# nwalkers += nwalkers % 2
print ndim, nwalkers
print(ndim, nwalkers)

cov = random_cov(ndim)
icov = np.linalg.inv(cov)

ens_samp = emcee.EnsembleSampler(nwalkers, ndim, lnprobfn,
args=[icov])
ens_samp = emcee.EnsembleSampler(nwalkers, ndim, lnprobfn, args=[icov])
ens_samp.random_state = _random.get_state()
pos, lnprob, state = ens_samp.run_mcmc(np.random.randn(nwalkers * ndim)
.reshape([nwalkers, ndim]), nsteps)
pos, lnprob, state = ens_samp.run_mcmc(
np.random.randn(nwalkers * ndim).reshape([nwalkers, ndim]), nsteps
)

proposal = np.diag(cov.diagonal())
mh_samp = emcee.MHSampler(proposal, ndim, lnprobfn,
args=[icov])
mh_samp = emcee.MHSampler(proposal, ndim, lnprobfn, args=[icov])
mh_samp.random_state = state
mh_samp.run_mcmc(np.random.randn(ndim), nsteps)

f = h5py.File(outfn)
f["data"][i, :] = np.array([ndim, np.mean(ens_samp.acor),
np.mean(mh_samp.acor)])
f["data"][i, :] = np.array(
[ndim, np.mean(ens_samp.acor), np.mean(mh_samp.acor)]
)
f.close()


Expand All @@ -67,7 +69,7 @@ def oned():
nthreads = 2

outfn = os.path.join(os.path.split(__file__)[0], "gauss_scaling.h5")
print outfn
print(outfn)
f = h5py.File(outfn, "w")
f.create_dataset("data", (niter, 3), "f")
f.close()
Expand Down
32 changes: 0 additions & 32 deletions emcee/__init__.py

This file was deleted.

12 changes: 0 additions & 12 deletions emcee/model.py

This file was deleted.

62 changes: 0 additions & 62 deletions emcee/tests/integration/test_gaussian.py

This file was deleted.

20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[build-system]
requires = ["setuptools>=40.6.0", "wheel", "setuptools_scm"]
build-backend = "setuptools.build_meta"

[tool.black]
line-length = 79
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
'''
116 changes: 70 additions & 46 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,72 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#!/usr/bin/env python

# Inspired by:
# https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/

import codecs
import os
import sys
from setuptools import setup

if sys.argv[-1] == "publish":
os.system("python setup.py sdist; twine upload dist/*")
sys.exit()

# Hackishly inject a constant into builtins to enable importing of the
# package before all the dependencies are built.
if sys.version_info[0] < 3:
import __builtin__ as builtins
else:
import builtins
builtins.__EMCEE_SETUP__ = True
import emcee # NOQA

setup(
name="emcee",
version=emcee.__version__,
author="Daniel Foreman-Mackey",
author_email="[email protected]",
packages=[
"emcee",
"emcee.moves", "emcee.backends",
"emcee.tests", "emcee.tests.unit", "emcee.tests.integration",
],
url="http://emcee.readthedocs.io",
license="MIT",
description=("The Python ensemble sampling toolkit for affine-invariant "
"MCMC"),
long_description=open("README.rst").read(),
package_data={"": ["LICENSE", "AUTHORS.rst"]},
include_package_data=True,
install_requires=["numpy"],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
],
zip_safe=True,
)
import re

from setuptools import find_packages, setup

# PROJECT SPECIFIC

NAME = "emcee"
PACKAGES = find_packages(where="src")
META_PATH = os.path.join("src", "emcee", "__init__.py")
CLASSIFIERS = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
]
INSTALL_REQUIRES = ["numpy"]

# END PROJECT SPECIFIC


HERE = os.path.dirname(os.path.realpath(__file__))


def read(*parts):
with codecs.open(os.path.join(HERE, *parts), "rb", "utf-8") as f:
return f.read()


def find_meta(meta, meta_file=read(META_PATH)):
meta_match = re.search(
r"^__{meta}__ = ['\"]([^'\"]*)['\"]".format(meta=meta), meta_file, re.M
)
if meta_match:
return meta_match.group(1)
raise RuntimeError("Unable to find __{meta}__ string.".format(meta=meta))


if __name__ == "__main__":
setup(
name=NAME,
use_scm_version={
"write_to": os.path.join(
"src", NAME, "{0}_version.py".format(NAME)
),
"write_to_template": '__version__ = "{version}"\n',
},
author=find_meta("author"),
author_email=find_meta("email"),
maintainer=find_meta("author"),
maintainer_email=find_meta("email"),
url=find_meta("uri"),
license=find_meta("license"),
description=find_meta("description"),
long_description=read("README.rst"),
long_description_content_type="text/x-rst",
packages=PACKAGES,
package_dir={"": "src"},
include_package_data=True,
install_requires=INSTALL_REQUIRES,
classifiers=CLASSIFIERS,
zip_safe=False,
options={"bdist_wheel": {"universal": "1"}},
)
Loading

0 comments on commit b131ded

Please sign in to comment.