Skip to content

Commit

Permalink
Merge pull request #137 from pabloem/pycodestyle
Browse files Browse the repository at this point in the history
Adding linter tests to continuous integration in Pykep
  • Loading branch information
darioizzo authored Oct 15, 2020
2 parents 2e1c97b + d66c752 commit 23060c3
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 24 deletions.
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ environment:
secure: M+qvYgRh05fEw6G9aglK4g==

matrix:
- BUILD_TYPE: "Pylint37-x64"
- BUILD_TYPE: "Release"
- BUILD_TYPE: "Debug"
# At the moment the build fails upon module import
Expand Down
3 changes: 2 additions & 1 deletion pykep/examples/_ex_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def algo_factory(name, original_screen_output=True):
pl = 5
else:
pl = 0
uda = pg.ipopt()
# Disable lint check on next line. Known issue (pagmo2/issues/261)
uda = pg.ipopt() # pylint: disable=no-member
uda.set_integer_option("print_level", pl)
uda.set_integer_option("acceptable_iter", 4)
uda.set_integer_option("max_iter", 150)
Expand Down
16 changes: 12 additions & 4 deletions pykep/orbit_plots/_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,17 @@ def plot_taylor(r0, v0, m0, thrust, tof, mu, veff, N=60, units=1, color='b', leg
x = [0.0] * N
y = [0.0] * N
z = [0.0] * N


# Replace r0, v0, m0 for r, v, m
r = r0
v = v0
m = m0
# We calculate the spacecraft position at each dt
for i in range(N):
x[i] = r[0] / units
y[i] = r[1] / units
z[i] = r[2] / units
r, v, m = propagate_taylor(r0, v0, m0, u, dt, mu, veff, -10, -10)
r, v, m = propagate_taylor(r, v, m, thrust, dt, mu, veff, -10, -10)

# And we plot
if legend:
Expand Down Expand Up @@ -351,13 +355,17 @@ def plot_taylor_disturbance(r0, v0, m0, thrust, disturbance, tof, mu, veff, N=60
y = [0.0] * N
z = [0.0] * N

# Replace r0, v0 and m0
r = r0
v = v0
m = m0
# We calculate the spacecraft position at each dt
for i in range(N):
x[i] = r[0] / units
y[i] = r[1] / units
z[i] = r[2] / units
r0, v0, m0 = propagate_taylor_disturbance(
r0, v0, m0, thrust, disturbance, dt, mu, veff, -10, -10)
r, v, m = propagate_taylor_disturbance(
r, v, m, thrust, disturbance, dt, mu, veff, -10, -10)

# And we plot
if legend:
Expand Down
19 changes: 10 additions & 9 deletions pykep/phasing/_dbscan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class dbscan():
"""
This class can be used to locate areas of the interplanetsry space that are 'dense' at one epoch.
This class can be used to locate areas of the interplanetary space that are 'dense' at one epoch.
Essentially, it locates planet clusters
"""
from pykep.core import AU, EARTH_VELOCITY
Expand Down Expand Up @@ -28,6 +28,7 @@ def __init__(self, planet_list):
self.n_clusters = None
self.members = None
self.core_members = None
self._scaling = None

def _orbital_metric(self, r, v):
from pykep.core import DAY2SEC
Expand Down Expand Up @@ -56,20 +57,20 @@ def cluster(self, t, eps=0.125, min_samples=10, metric='orbital', T=180, ref_r=A
if metric == 'euclidean':
self._X = [
[elem for tupl in p.eph(self._epoch) for elem in tupl] for p in self._asteroids]
scaling_vector = [ref_r] * 3
scaling_vector += [ref_v] * 3
self._scaling = [ref_r] * 3
self._scaling += [ref_v] * 3
elif metric == 'euclidean_r':
self._X = [list(p.eph(self._epoch)[0]) for p in self._asteroids]
scaling_vector = [ref_r] * 3
self._scaling = [ref_r] * 3
elif metric == 'orbital':
self._T = T
self._X = [self._orbital_metric(
*p.eph(self._epoch)) for p in self._asteroids]
scaling_vector = [1.] * 6 # no scaling
self._scaling = [1.] * 6 # no scaling
self._X = numpy.array(self._X)

scaling_vector = numpy.array(scaling_vector)
self._X = self._X / scaling_vector[None, :]
self._scaling = numpy.array(self._scaling)
self._X = self._X / self._scaling[None, :]

self._db = DBSCAN(eps=eps, min_samples=min_samples).fit(self._X)
self._core_samples = self._db.core_sample_indices_
Expand All @@ -88,7 +89,7 @@ def cluster(self, t, eps=0.125, min_samples=10, metric='orbital', T=180, ref_r=A
self.core_members[int(label)] = [
index for index in self._core_samples if self.labels[index] == label]

self._X = self._X * scaling_vector[None, :]
self._X = self._X * self._scaling[None, :]

def pretty(self):
"""Prints the cluster lists."""
Expand Down Expand Up @@ -149,7 +150,7 @@ def plot_cluster_evolution(self, cluster_id=None, only_core=False, epochs=range(
return
if cluster_id >= self.n_clusters or cluster_id < 0:
print(
"cluster_id should be larger then 0 and smaller than the number of clusters (-1)")
"cluster_id should be larger than 0 and smaller than the number of clusters (-1)")
return
if len(epochs) != 9:
print("The epochs requested must be exactly 9 as to assemble 3x3 subplots")
Expand Down
4 changes: 2 additions & 2 deletions pykep/phasing/_lambert.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pygmo.problem._base import base
from pygmo.util import hypervolume
from pygmo.problem._base import base # pylint: disable=import-error
from pygmo import hypervolume
from pykep.planet import gtoc7
from pykep.orbit_plots import plot_planet, plot_lambert
from pykep.core import lambert_problem, DAY2SEC, epoch, AU, damon
Expand Down
21 changes: 21 additions & 0 deletions pykep/trajopt/_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ def __init__(self, mass=1000., thrust=0.3, isp=3000., nseg=10, mu=pk.MU_SUN, hf=
self.leg.set_mu(mu)
self.leg.high_fidelity = hf

def fitness(self, z):
"""This function will be redefined in the inheriting classes
"""
pass

def _plot_traj(self, z, axis, units):
"""This function will be redefined in the inheriting classes
"""
pass

@staticmethod
def _get_controls(z):
"""This function will be redefined in the inheriting classes
"""
pass

def _pretty(self, z):
"""This function will be redefined in the inheriting classes
"""
pass

def get_nobj(self):
return 1

Expand Down
15 changes: 15 additions & 0 deletions pykep/trajopt/_indirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ def __init__(
raise TypeError(
"Both atol and rtol must be an instance of either float or int.")

def fitness(self, z):
"""This function will be redefined in the inheriting classes
"""
pass

def _plot_traj(self, z, axes, units):
"""This function will be redefined in the inheriting classes
"""
pass

def _pretty(self, z):
"""This function will be redefined in the inheriting classes
"""
pass

def get_nobj(self):
return 1

Expand Down
21 changes: 17 additions & 4 deletions tools/install_appveyor_mingw.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def run_command(raw_command, directory=None, verbose=True):
print("Release build detected, tag is '" +
os.environ['APPVEYOR_REPO_TAG_NAME'] + "'")
is_python_build = 'Python' in BUILD_TYPE
is_python_lint = 'Pylint' in BUILD_TYPE

# Check here for a list of installed software in the appveyor VMs: https://www.appveyor.com/docs/windows-images-software/
# USING: mingw64 8.1.0
Expand All @@ -64,8 +65,8 @@ def run_command(raw_command, directory=None, verbose=True):
run_command(r'7z x -aoa -oC:\\ boost.7z', verbose=False)

# Setup of the Python build variables (version based)
if is_python_build:
if 'Python37-x64' in BUILD_TYPE:
if is_python_build or is_python_lint:
if 'Python37-x64' in BUILD_TYPE or 'Pylint37-x64' in BUILD_TYPE:
python_version = r'37'
python_folder = r'Python37-x64'
python_library = r'C:\\' + python_folder + r'\\python37.dll '
Expand All @@ -84,6 +85,12 @@ def run_command(raw_command, directory=None, verbose=True):
pinterp = r"C:\\" + python_folder + r'\\python.exe'
pip = r"C:\\" + python_folder + r'\\scripts\\pip'
twine = r"C:\\" + python_folder + r'\\scripts\\twine'
# Set linter paths
pylint = r"C:\\" + python_folder + r'\\scripts\\pylint'
pycodestyle = r"C:\\" + python_folder + r'\\scripts\\pycodestyle'
mypy = r"C:\\" + python_folder + r'\\scripts\\mypy'


module_install_path = r"C:\\" + python_folder + r'\\Lib\\site-packages\\pykep'
# Install pip and deps.
run_command(pinterp + r' --version', verbose=True)
Expand All @@ -103,7 +110,7 @@ def run_command(raw_command, directory=None, verbose=True):
r'-DBoost_DATE_TIME_LIBRARY_RELEASE=c:\\local\\lib\\libboost_date_time-mgw81-mt-x64-1_70.dll '

# Configuration step.
if is_python_build:
if is_python_build or is_python_lint:
os.makedirs('build_keplerian_toolbox')
os.chdir('build_keplerian_toolbox')
run_command(r'cmake -G "MinGW Makefiles" .. ' + common_cmake_opts + \
Expand Down Expand Up @@ -149,7 +156,7 @@ def run_command(raw_command, directory=None, verbose=True):


# Testing, packaging.
if is_python_build:
if is_python_build or is_python_lint:
# Run the Python tests.
run_command(
pinterp + r' -c "from pykep import test; test.run_test_suite();"')
Expand All @@ -173,3 +180,9 @@ def run_command(raw_command, directory=None, verbose=True):
run_command(twine + r' upload -u darioizzo dist\\' +
os.listdir('dist')[0])

if is_python_lint:
# Run Python lint checks
run_command(pip + ' install pylint')
# Running pylint and erroring only on actual errors. Excluding
run_command(pylint + ' pykep -E --unsafe-load-any-extension=y')

18 changes: 14 additions & 4 deletions tools/wheel_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
AUTHOR = 'Dario Izzo'
AUTHOR_EMAIL = '[email protected]'
LICENSE = 'GPLv3+/LGPL3+'
INSTALL_REQUIRES = ['numpy', 'scipy', 'matplotlib']
INSTALL_REQUIRES = [
'numba',
'numpy',
'matplotlib',
'pygmo',
'pygmo_plugins_nonfree',
'scipy',
'sklearn',
]
CLASSIFIERS = [
# How mature is this project? Common values are
# 3 - Alpha
Expand Down Expand Up @@ -43,8 +51,10 @@ def has_ext_modules(foo):
return True


# Setup the list of external dlls.
# Setup the list of external dlls and other data files.
import os.path

PYKEP_UTIL_FILES = ['gravity_models/*/*txt']
if os.name == 'nt':
mingw_wheel_libs = 'mingw_wheel_libs_python{}{}.txt'.format(
sys.version_info[0], sys.version_info[1])
Expand All @@ -54,14 +64,14 @@ def has_ext_modules(foo):
'pykep.core': ['core.pyd'] + DLL_LIST,
'pykep.planet': ['planet.pyd'],
'pykep.sims_flanagan': ['sims_flanagan.pyd'],
'pykep.util': ['util.pyd']
'pykep.util': ['util.pyd'] + PYKEP_UTIL_FILES
}
else:
PACKAGE_DATA = {
'pykep.core': ['core.so'],
'pykep.planet': ['planet.so'],
'pykep.sims_flanagan': ['sims_flanagan.so'],
'pykep.util': ['util.so']
'pykep.util': ['util.so'] + PYKEP_UTIL_FILES
}

setup(name=NAME,
Expand Down

0 comments on commit 23060c3

Please sign in to comment.