Skip to content

Commit

Permalink
Merge pull request #175 from metawards/feature_cythonise
Browse files Browse the repository at this point in the history
Feature cythonise
  • Loading branch information
Christopher Woods authored May 25, 2021
2 parents 02cc38a + c5448a7 commit 7acf961
Show file tree
Hide file tree
Showing 13 changed files with 826 additions and 724 deletions.
10 changes: 7 additions & 3 deletions doc/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Installation instructions

MetaWards is a Python package, but it does come with R wrappers. This
means that you can choose to install MetaWards either via Python or
via R.
via R. Note that MetaWards depends on data files that are
held in MetaWardsData. To use MetaWards, you must install MetaWardsData
following :doc:`these instructions <model_data>`.

Installation via Python
=======================
Expand Down Expand Up @@ -85,7 +87,8 @@ Once installed, you can run `metawards` by typing
metawards --version
This should print out some version information about MetaWards.
This should print out some version information about MetaWards,
including whether or not it found MetaWardsData.

If this doesn't work, then it is possible that the directory into which
`metawards` has been placed is not in your PATH (this is quite
Expand Down Expand Up @@ -114,7 +117,8 @@ by default in R is too old to run MetaWards (MetaWards needs
Python 3.7 or newer, while the default in reticulate is to install
and use Python 3.6).

Once you have MetaWards installed in Python, you first need to
Once you have MetaWards (and MetaWardsData)
installed in Python, you first need to
get the reticulate command that you will need to tell R which
Python interpreter to use. We have written a function to do
this for you. Open Python and type;
Expand Down
6 changes: 6 additions & 0 deletions doc/source/quickstart/01_R.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ the case by typing;
If you don't see ``TRUE`` returned, then double-check your installation.

.. note::

You also need to have installed MetaWardsData. If you have
not installed MetaWardsData then you need to install it by
following :doc:`these instructions <../model_data>`.

Now make sure that you have installed the
`tidyverse <https://www.tidyverse.org>`__, e.g. via;

Expand Down
6 changes: 6 additions & 0 deletions doc/source/quickstart/01_console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ type;
You should see that MetaWards version information is printed to the screen.
If not, then you need to :doc:`install MetaWards <../install>`.

.. note::

The output should show that MetaWardsData has been found. If you have
not installed MetaWardsData then you need to install it by
following :doc:`these instructions <../model_data>`.

You also need to be able to use a text editor, e.g. notepad, vim, emacs,
nano or pico. This quick start will use nano. Please use the editor
that you prefer.
Expand Down
6 changes: 6 additions & 0 deletions doc/source/quickstart/01_python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ analysing and plotting the results.
>>> import pandas as pd
.. note::

You also need to have installed MetaWardsData. If you have
not installed MetaWardsData then you need to install it by
following :doc:`these instructions <../model_data>`.

Importing metawards
-------------------

Expand Down
5 changes: 4 additions & 1 deletion doc/source/quickstart/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ Quick Start Guide

Please make sure you have installed ``metawards``, e.g. by following these
:doc:`installation instructions <../install>`. You can test this by
typing ``metawards --version`` on the terminal/console.
typing ``metawards --version`` on the terminal/console. Note that this
should show that MetaWardsData has been found. If you have
not installed MetaWardsData then you need to install it by
following :doc:`these instructions <../model_data>`.

You have three choices for how you use MetaWards, and thus three choices
for how you will follow this quick start guide;
Expand Down
34 changes: 28 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def get_openmp_flag():
extra_postargs=[flag])
except Exception:
# We are likely missing the path to the libomp library - get this path
print("\nCould not link - trying again, specifying the path to libomp")
print(
"\nCould not link - trying again, specifying the path to libomp")

compiler_dir = os.path.dirname(compiler.compiler_so[0])
libomp = glob(f"{compiler_dir}/../lib*/libomp*")
Expand Down Expand Up @@ -389,14 +390,35 @@ def no_cythonize(extensions, **_ignore):
dev_requires = fp.read().strip().split("\n")

if IS_WINDOWS:
mw_random_lib = glob("build/*/metawards.lib")
import sys
v = sys.version_info
print(os.getcwd())
print(f"build/*{v.major}.{v.minor}/metawards_random.lib")
mw_random_lib = glob(
f"build/*{v.major}.{v.minor}/metawards_random.lib")

if len(mw_random_lib) == 0:
if not is_build:
print("WARNING: CANNOT FIND metawards_random.lib!")
elif len(mw_random_lib) > 1:
mw_random_lib = [mw_random_lib[0]]

libs_dir = os.path.abspath(os.path.join(sys.prefix, "libs"))

if not os.path.exists(libs_dir):
print(f"Cannot find libs directory? {libs_dir}")
raise RuntimeError(f"Cannot find libs directory {libs_dir}")
if not is_build:
print(f"Installing {mw_random_lib} to {libs_dir}")
else:
mw_random_lib = glob("build/*/libmetawards_random.a")
import sys
v = sys.version_info
mw_random_lib = glob(
f"build/*{v.major}.{v.minor}/libmetawards_random.a")

if len(mw_random_lib) == 0:
if not is_build:
print("WARNING: CANNOT FIND metawards_random.lib!")
elif len(mw_random_lib) > 1:
mw_random_lib = [mw_random_lib[0]]

libs_dir = "lib"

setup(
Expand Down
13 changes: 13 additions & 0 deletions src/metawards/_interpret.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ def random_number(s: str = None, rng=None, minval: float = None,
from .utils._ran_binomial import ran_uniform
return rmin + ((rmax - rmin) * ran_uniform(rng))

@staticmethod
def list(s: any):
"""Interpret and return a list from the passed string 's'"""
try:
import ast
my_list = []
for val in ast.literal_eval(s):
my_list.append(val)

return my_list
except Exception:
raise ValueError(f"Cannot interpret a list from {s}")

@staticmethod
def integer(s: any, rng=None, minval: int = None,
maxval: int = None) -> int:
Expand Down
Loading

0 comments on commit 7acf961

Please sign in to comment.