Skip to content

Commit

Permalink
Merge pull request #514 from wd15/pip
Browse files Browse the repository at this point in the history
Make pymks pip installable
  • Loading branch information
wd15 authored Aug 17, 2020
2 parents f3d0c38 + 4310539 commit 7780e16
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 36 deletions.
38 changes: 36 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Python CircleCI 2.0 configuration file
version: 2.1
jobs:
build:
conda_develop:
docker:
- image: continuumio/miniconda3

working_directory: ~/repo
working_directory: ~/repo-conda-develop

steps:
# Step 1: obtain repo from GitHub
Expand Down Expand Up @@ -45,3 +45,37 @@ jobs:
py.test notebooks/multiphase.ipynb
py.test notebooks/checkerboard.ipynb
py.test notebooks/fiber.ipynb
pip_install:
docker:
- image: continuumio/miniconda3

working_directory: ~/repo-pip-install

steps:

- checkout

- run:
name: Setup
command: |
conda create -n pip-install python=3
source activate pip-install
pip install .
- run:
name: Test
no_output_timeout: 30m
command: |
set -e
source activate pip-install
python -c "import pymks; pymks.test()"
workflows:
version: 2
test:
jobs:
- conda_develop
- pip_install
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ install:
- nix-shell --pure --command "echo 'run nix-shell'"
script:
- nix-shell --pure --command "export PYMKS_USE_FFTW=$PYMKS_USE_FFTW; py.test --cov-fail-under=100"
- nix-shell --pure --command "pylint --rcfile=.pylintrc pymks/__init__.py pymks/fmks pymks/fmks/tests"
- nix-shell --pure --command "flake8 pymks/__init__.py pymks/fmks pymks/fmks/tests"
- nix-shell --pure --command "black --check pymks/__init__.py pymks/fmks pymks/fmks/tests"
- nix-shell --pure --command "pylint --rcfile=.pylintrc setup.py pymks/__init__.py pymks/fmks pymks/fmks/tests"
- nix-shell --pure --command "flake8 setup.py pymks/__init__.py pymks/fmks pymks/fmks/tests"
- nix-shell --pure --command "black --check setup.py pymks/__init__.py pymks/fmks pymks/fmks/tests"
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ Nix](https://nixos.org/nix/manual/#chap-quick-start), run

to drop into a shell with PyMKS and all its requirements available.

#### Pip

Install a minimal version of PyMKS with

$ pip install pymks

This is enough to run the tests, but not the examples. Some optional
packages are not available via Pip.

## Testing

To test a PyMKS installation use
Expand Down
20 changes: 18 additions & 2 deletions pymks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
pass

import os

from .fmks.data.cahn_hilliard import solve_cahn_hilliard
from .fmks.plot import plot_microstructures
from .fmks.bases.primitive import PrimitiveTransformer
Expand All @@ -20,12 +21,26 @@
from .fmks.localization import ReshapeTransformer
from .fmks.localization import coeff_to_real
from .fmks.data.delta import generate_delta
from .fmks.data.elastic_fe import solve_fe
from .fmks.data.multiphase import generate_multiphase
from .fmks.correlations import FlattenTransformer
from .fmks.correlations import TwoPointCorrelation
from .fmks.data.checkerboard import generate_checkerboard

try:
import sfepy # noqa: F401
except ImportError:

def solve_fe(*_, **__):
"""Dummy funcion when sfepy unavailable
"""
# pylint: disable=redefined-outer-name, import-outside-toplevel, unused-import
import sfepy # noqa: F401, F811


else:
from .fmks.data.elastic_fe import solve_fe

# the following will be deprecated
from .mks_localization_model import MKSLocalizationModel
from .bases.primitive import PrimitiveBasis
from .bases.legendre import LegendreBasis
Expand All @@ -35,6 +50,7 @@
MKSRegressionModel = MKSLocalizationModel
DiscreteIndicatorBasis = PrimitiveBasis
ContinuousIndicatorBasis = PrimitiveBasis
# the above will be deprecatec


def test():
Expand All @@ -43,7 +59,7 @@ def test():
"""
import pytest # pylint: disable=import-outside-toplevel

path = os.path.split(__file__)[0]
path = os.path.join(os.path.split(__file__)[0], "fmks")
pytest.main(args=[path, "--doctest-modules", "-r s"])


Expand Down
74 changes: 45 additions & 29 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#!/usr/bin/env python

"""PyMKS - the materials knowledge system in Python
See the documenation for details at https://pymks.org
"""

import warnings
import os
import subprocess
from setuptools import setup, find_packages
import os


def make_version(package_name):
Expand All @@ -11,6 +17,7 @@ def make_version(package_name):
Returns:
version number of the form "3.1.1.dev127+g413ed61".
"""

def _minimal_ext_cmd(cmd):
"""Run a command in a subprocess.
Expand All @@ -22,28 +29,22 @@ def _minimal_ext_cmd(cmd):
"""
# construct minimal environment
env = {}
for k in ['SYSTEMROOT', 'PATH']:
for k in ["SYSTEMROOT", "PATH"]:
value = os.environ.get(k)
if value is not None:
env[k] = value
# LANGUAGE is used on win32
env['LANGUAGE'] = 'C'
env['LANG'] = 'C'
env['LC_ALL'] = 'C'
out = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
env=env).communicate()[0]
env["LANGUAGE"] = "C"
env["LANG"] = "C"
env["LC_ALL"] = "C"
out = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
return out

version = 'unknown'
version = "unknown"

if os.path.exists('.git'):
if os.path.exists(".git"):
try:
out = _minimal_ext_cmd(['git',
'describe',
'--tags',
'--match',
'v*'])
out = _minimal_ext_cmd(["git", "describe", "--tags", "--match", "v*"])
# ticket:475 - fix for bytecode received in Py3k
# http://jeetworks.org/node/67
outdecode = out.decode("utf-8")
Expand All @@ -57,13 +58,16 @@ def _minimal_ext_cmd(cmd):
else:
version = version[0][1:]
except OSError:
import warnings
warnings.warn("Could not run ``git describe``")
elif os.path.exists('pymks.egg-info'):
elif os.path.exists("pymks.egg-info"):
# pylint: disable=import-outside-toplevel
from pkg_resources import get_distribution, DistributionNotFound

try:
version = get_distribution(package_name).version # pylint: disable=no-member
except DistributionNotFound: # pragma: no cover
version = get_distribution(
package_name
).version # pylint: disable=no-member
except DistributionNotFound: # pragma: no cover
version = "unknown, try running `python setup.py egg_info`"

return version
Expand All @@ -72,13 +76,25 @@ def _minimal_ext_cmd(cmd):
PACKAGE_NAME = "pymks"


setup(name=PACKAGE_NAME,
version=make_version(PACKAGE_NAME),
description='Materials Knowledge Systems in Python (PyMKS)',
author='Daniel Wheeler',
author_email='[email protected]',
url='http://pymks.org',
packages=find_packages(),
package_data={'': ['tests/*.py']},
install_requires=[],
data_files=['setup.cfg'])
setup(
name=PACKAGE_NAME,
version=make_version(PACKAGE_NAME),
description="Materials Knowledge Systems in Python (PyMKS)",
author="Daniel Wheeler",
author_email="[email protected]",
url="http://pymks.org",
packages=find_packages(),
package_data={"": ["tests/*.py"]},
install_requires=[
"pytest",
"numpy",
"dask",
"Deprecated",
"matplotlib",
"scikit-learn",
"pytest-cov",
"nbval",
"toolz",
],
data_files=["setup.cfg"],
)

0 comments on commit 7780e16

Please sign in to comment.