Skip to content

Commit

Permalink
Updated __init__ with version checking
Browse files Browse the repository at this point in the history
  • Loading branch information
FHTMitchell committed Aug 20, 2017
1 parent 31e2863 commit 6b67b2e
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
34 changes: 32 additions & 2 deletions code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
# To make module work
# __init__.py

import sys
import warnings

import numpy as _np
import sympy as _sp
import matplotlib as _mpl

__author__ = 'Mitchell, FHT'
__date__ = (2017, 8, 20)
__version__ = '0.2'
__verbose__ = True

pass
_ver_err = "You are running version {2} of {0}, version {1} or higher is required"
_ver_warn = "You are running version {2} of {0}, version {1} or higher is expected"

def _ver_assert(module, req_ver, warn=True):
assert isinstance(req_ver, tuple)
cur_ver = tuple(int(x) for x in module.__version__.split('.'))
if cur_ver < req_ver:
fmt = module.__name__, '.'.join(map(str, req_ver)), module.__version__
if warn:
warnings.warn(_ver_warn.format(*fmt))
else:
raise Exception(_ver_err.format(*fmt))


if sys.version_info < (3,6,0):
_fmt = 'python', '3.6.0', '.'.join(map(str, sys.version_info[:3]))
raise Exception(_ver_err.format(*_fmt))

_ver_assert(_np, (1, 11, 3))
_ver_assert(_sp, (1, 0))
_ver_assert(_mpl, (2, 0, 0))

from . import driver, main, problem, solver, tests
5 changes: 0 additions & 5 deletions code/desktop.ini

This file was deleted.

9 changes: 5 additions & 4 deletions code/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import collections
import numpy as np

from method import methods
from stepper import Stepper
from problem import Problem
from timers import Timer
from .method import methods
from .stepper import Stepper
from .problem import Problem
from .timers import Timer

from typing import *

__author__ = 'Mitchell, FHT'
Expand Down
6 changes: 3 additions & 3 deletions code/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# main.py

from driver import Driver
from problem import Lagrange
from solver import Newton
from .driver import Driver
from .problem import Lagrange
from .solver import Newton

__author__ = 'Mitchell, FHT'
__date__ = (2017, 8, 20)
Expand Down
12 changes: 9 additions & 3 deletions code/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import sympy as sp
import matplotlib.pyplot as plt

import dsympy
from timers import Timer
from . import dsympy
from .timers import Timer
from typing import *
import warnings

__author__ = 'Mitchell, FHT'
__date__ = (2017, 8, 20)
Expand All @@ -20,7 +21,12 @@
vx, vy, vz = [sp.diff(s, t) for s in (x, y, z)]
rho = x ** 2 + y ** 2 + z ** 2

fig_path = r'D:\GoogleDrive\Work\Year 5\MScProject\Fergus Mitchell MSc (Obrechkoff)\Code\figs'

try:
fig_path = os.path.join(__file__, '..', 'figs')
except NameError:
warnings.warn('fig_path unable to be automatircally created. '
'Please set problem.fig_path')


def problems():
Expand Down
2 changes: 1 addition & 1 deletion code/solver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# solver.py

import numpy as np
from timers import Timer
from .timers import Timer
from typing import *

__author__ = 'Mitchell, FHT'
Expand Down
2 changes: 1 addition & 1 deletion code/stepper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#stepper.py

import numpy as np
from method import Method
from .method import Method
from collections import deque
from typing import *

Expand Down

0 comments on commit 6b67b2e

Please sign in to comment.