mirror of https://github.com/KLayout/klayout.git
Merge pull request #149 from lightwave-lab/pymod-pr
Extending db and improving setup.py & travis
This commit is contained in:
commit
521b197285
107
.travis.yml
107
.travis.yml
|
|
@ -1,40 +1,43 @@
|
|||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
dist: trusty # Ubuntu 14.04
|
||||
sudo: false
|
||||
language: python
|
||||
python: '2.6'
|
||||
# python 3 osx
|
||||
- os: osx
|
||||
osx_image: xcode9.4 # macOS 10.13
|
||||
env:
|
||||
- MATRIX_EVAL=""
|
||||
- os: linux
|
||||
dist: trusty # Ubuntu 14.04
|
||||
sudo: false
|
||||
language: python
|
||||
python: '2.7'
|
||||
- ARCHFLAGS="-std=c++11"
|
||||
- PIP_UPDATE="1"
|
||||
- os: osx
|
||||
osx_image: xcode8.3 # macOS 10.12
|
||||
env:
|
||||
- MATRIX_EVAL="brew install python2 || brew link --overwrite python@2" # deficient python2 in travis's xcode8.3 (no ssl)
|
||||
- ARCHFLAGS="-std=c++11"
|
||||
- PIP_UPDATE="1"
|
||||
- os: osx
|
||||
osx_image: xcode8 # macOS 10.11
|
||||
env:
|
||||
- MATRIX_EVAL=""
|
||||
- os: linux
|
||||
dist: trusty # Ubuntu 14.04
|
||||
sudo: false
|
||||
language: python
|
||||
python: '3.3'
|
||||
- ARCHFLAGS="-std=c++11"
|
||||
- PIP_UPDATE="1"
|
||||
# python 2 osx
|
||||
- os: osx
|
||||
osx_image: xcode9.4 # macOS 10.13
|
||||
env:
|
||||
- MATRIX_EVAL=""
|
||||
- os: linux
|
||||
dist: trusty # Ubuntu 14.04
|
||||
sudo: false
|
||||
language: python
|
||||
python: '3.4'
|
||||
- MATRIX_EVAL="brew update; brew bundle; shopt -s expand_aliases; alias python='python3'; alias pip='pip3';"
|
||||
- ARCHFLAGS="-std=c++11"
|
||||
- PIP_UPDATE="1"
|
||||
- os: osx
|
||||
osx_image: xcode8.3 # macOS 10.12
|
||||
env:
|
||||
- MATRIX_EVAL=""
|
||||
- os: linux
|
||||
dist: trusty # Ubuntu 14.04
|
||||
sudo: false
|
||||
language: python
|
||||
python: '3.5'
|
||||
- MATRIX_EVAL="brew update; brew bundle; shopt -s expand_aliases; alias python='python3'; alias pip='pip3';"
|
||||
- ARCHFLAGS="-std=c++11"
|
||||
- PIP_UPDATE="1"
|
||||
- os: osx
|
||||
osx_image: xcode8 # macOS 10.11
|
||||
env:
|
||||
- MATRIX_EVAL=""
|
||||
- MATRIX_EVAL="brew update; brew bundle; shopt -s expand_aliases; alias python='python3'; alias pip='pip3';"
|
||||
- ARCHFLAGS="-std=c++11"
|
||||
- PIP_UPDATE="1"
|
||||
- os: linux
|
||||
dist: trusty # Ubuntu 14.04
|
||||
sudo: false
|
||||
|
|
@ -42,25 +45,59 @@ matrix:
|
|||
python: '3.6'
|
||||
env:
|
||||
- MATRIX_EVAL=""
|
||||
- os: osx
|
||||
osx_image: xcode9.3 # macOS 10.13
|
||||
- PIP_UPDATE="1"
|
||||
- os: linux
|
||||
dist: trusty # Ubuntu 14.04
|
||||
sudo: false
|
||||
language: python
|
||||
python: '2.7'
|
||||
env:
|
||||
- MATRIX_EVAL=""
|
||||
- os: osx
|
||||
osx_image: xcode8.3 # macOS 10.12
|
||||
- PIP_UPDATE="1"
|
||||
- os: linux
|
||||
dist: trusty # Ubuntu 14.04
|
||||
sudo: false
|
||||
language: python
|
||||
python: '2.6'
|
||||
env:
|
||||
- MATRIX_EVAL=""
|
||||
- os: osx
|
||||
osx_image: xcode8 # macOS 10.11
|
||||
- PIP_UPDATE="0" # setuptools installed from last pip has syntax error on py 2.6
|
||||
- os: linux
|
||||
dist: trusty # Ubuntu 14.04
|
||||
sudo: false
|
||||
language: python
|
||||
python: '3.3'
|
||||
env:
|
||||
- MATRIX_EVAL=""
|
||||
- PIP_UPDATE="1"
|
||||
- os: linux
|
||||
dist: trusty # Ubuntu 14.04
|
||||
sudo: false
|
||||
language: python
|
||||
python: '3.4'
|
||||
env:
|
||||
- MATRIX_EVAL=""
|
||||
- PIP_UPDATE="1"
|
||||
- os: linux
|
||||
dist: trusty # Ubuntu 14.04
|
||||
sudo: false
|
||||
language: python
|
||||
python: '3.5'
|
||||
env:
|
||||
- MATRIX_EVAL=""
|
||||
- PIP_UPDATE="1"
|
||||
|
||||
before_install:
|
||||
- env
|
||||
- rvm install ruby --latest
|
||||
- gem install dropbox-deployment
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew bundle; shopt -s expand_aliases; alias python='python3'; fi
|
||||
- eval "${MATRIX_EVAL}"
|
||||
- if [ "${PIP_UPDATE}" == "1" ]; then
|
||||
pip --version;
|
||||
pip install --upgrade pip || sudo pip install --upgrade pip;
|
||||
pip --version;
|
||||
pip install --upgrade setuptools wheel || sudo pip install --upgrade setuptools wheel;
|
||||
fi
|
||||
- python -c "import distutils.sysconfig as sysconfig; print(sysconfig.__file__)"
|
||||
|
||||
install:
|
||||
|
|
|
|||
44
setup.py
44
setup.py
|
|
@ -59,6 +59,49 @@ import glob
|
|||
import os
|
||||
import platform
|
||||
import distutils.sysconfig as sysconfig
|
||||
from distutils.errors import CompileError
|
||||
import multiprocessing
|
||||
N_cores = multiprocessing.cpu_count()
|
||||
|
||||
|
||||
# monkey-patch for parallel compilation
|
||||
# from https://stackoverflow.com/questions/11013851/speeding-up-build-process-with-distutils
|
||||
def parallelCCompile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None):
|
||||
# those lines are copied from distutils.ccompiler.CCompiler directly
|
||||
macros, objects, extra_postargs, pp_opts, build = self._setup_compile(
|
||||
output_dir, macros, include_dirs, sources, depends, extra_postargs)
|
||||
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
|
||||
# parallel code
|
||||
|
||||
N = min(N_cores, len(objects) // 2, 8) # number of parallel compilations
|
||||
N = max(N, 1)
|
||||
print("Compiling with", N, "threads.")
|
||||
import multiprocessing.pool
|
||||
|
||||
def _single_compile(obj):
|
||||
try:
|
||||
src, ext = build[obj]
|
||||
except KeyError:
|
||||
return
|
||||
n_tries = 2
|
||||
while n_tries > 0:
|
||||
try:
|
||||
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
|
||||
except CompileError:
|
||||
n_tries -= 1
|
||||
print("Building", obj, "has failed. Trying again.")
|
||||
else:
|
||||
break
|
||||
# convert to list, imap is evaluated on-demand
|
||||
list(multiprocessing.pool.ThreadPool(N).imap(_single_compile, objects))
|
||||
return objects
|
||||
|
||||
|
||||
# only if python version > 2.6, somehow the travis compiler hangs in 2.6
|
||||
import sys
|
||||
if sys.version_info[0] * 10 + sys.version_info[1] > 26:
|
||||
import distutils.ccompiler
|
||||
distutils.ccompiler.CCompiler.compile = parallelCCompile
|
||||
|
||||
# ----------------------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -298,6 +341,7 @@ rdb = Extension(config.root + '.rdb',
|
|||
# Core setup function
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Number of cores", N_cores)
|
||||
setup(name=config.root,
|
||||
version=config.version(),
|
||||
description='KLayout standalone Python package',
|
||||
|
|
|
|||
|
|
@ -24,16 +24,24 @@
|
|||
#ifndef HDR_dbHash
|
||||
#define HDR_dbHash
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# include <ext/hash_map>
|
||||
# include <ext/hash_set>
|
||||
namespace std_ext = __gnu_cxx;
|
||||
# define DB_HASH_NAMESPACE __gnu_cxx
|
||||
#else
|
||||
# include <hash_map>
|
||||
# include <hash_set>
|
||||
#if defined(__APPLE__)
|
||||
#define __EXT_HASH_DEPRECATED
|
||||
#endif
|
||||
#if defined(__EXT_HASH_DEPRECATED) // clang compiler complains about deprecation warning on ext/hash_map and ext/hash_set
|
||||
# include <unordered_map>
|
||||
# include <unordered_set>
|
||||
# define DB_HASH_NAMESPACE std
|
||||
namespace std_ext = std;
|
||||
# define DB_HASH_NAMESPACE std
|
||||
#elif defined(__GNUC__)
|
||||
# include <ext/hash_map>
|
||||
# include <ext/hash_set>
|
||||
namespace std_ext = __gnu_cxx;
|
||||
# define DB_HASH_NAMESPACE __gnu_cxx
|
||||
#else
|
||||
# include <hash_map>
|
||||
# include <hash_set>
|
||||
namespace std_ext = std;
|
||||
# define DB_HASH_NAMESPACE std
|
||||
#endif
|
||||
|
||||
#include "dbPoint.h"
|
||||
|
|
@ -74,7 +82,7 @@ namespace DB_HASH_NAMESPACE
|
|||
};
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64) || defined(__APPLE__)
|
||||
#if defined(_WIN64)
|
||||
/**
|
||||
* @brief Specialization missing for long long on WIN64
|
||||
*/
|
||||
|
|
@ -100,6 +108,13 @@ namespace DB_HASH_NAMESPACE
|
|||
};
|
||||
#endif
|
||||
|
||||
#if defined(__EXT_HASH_DEPRECATED)
|
||||
template<typename _Key, typename _Tp>
|
||||
using hash_map = unordered_map<_Key, _Tp>;
|
||||
template<typename _Value>
|
||||
using hash_set = unordered_set<_Value>;
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
inline size_t hfunc (const T &t)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -194,6 +194,20 @@ public:
|
|||
*/
|
||||
point<C> &operator*= (long s);
|
||||
|
||||
/**
|
||||
* @brief Division by some divisor.
|
||||
*
|
||||
* Scaline involves rounding which in our case is simply handled
|
||||
* with the coord_traits scheme.
|
||||
*/
|
||||
|
||||
point<C> &operator/= (double s);
|
||||
|
||||
/**
|
||||
* @brief Dividing self by some integer divisor
|
||||
*/
|
||||
point<C> &operator/= (long s);
|
||||
|
||||
/**
|
||||
* @brief The euclidian distance to another point
|
||||
*
|
||||
|
|
@ -452,6 +466,32 @@ operator* (const db::point<C> &p, unsigned int s)
|
|||
return point<C> (p.x () * s, p.y () * s);
|
||||
}
|
||||
|
||||
template <class C, typename Number>
|
||||
inline point<C>
|
||||
operator/ (const db::point<C> &p, Number s)
|
||||
{
|
||||
double mult = 1.0 / static_cast<double>(s);
|
||||
return point<C> (p.x () * mult, p.y () * mult);
|
||||
}
|
||||
|
||||
template <class C>
|
||||
inline point<C> &
|
||||
point<C>::operator/= (double s)
|
||||
{
|
||||
double mult = 1.0 / static_cast<double>(s);
|
||||
*this *= mult;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
inline point<C> &
|
||||
point<C>::operator/= (long s)
|
||||
{
|
||||
double mult = 1.0 / static_cast<double>(s);
|
||||
*this *= mult;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
inline point<C> &
|
||||
point<C>::operator*= (double s)
|
||||
|
|
|
|||
|
|
@ -266,6 +266,20 @@ public:
|
|||
*/
|
||||
vector<C> operator*= (long s);
|
||||
|
||||
/**
|
||||
* @brief Division by some divisor.
|
||||
*
|
||||
* Scaline involves rounding which in our case is simply handled
|
||||
* with the coord_traits scheme.
|
||||
*/
|
||||
|
||||
vector<C> &operator/= (double s);
|
||||
|
||||
/**
|
||||
* @brief Dividing self by some integer divisor
|
||||
*/
|
||||
vector<C> &operator/= (long s);
|
||||
|
||||
/**
|
||||
* @brief The euclidian length
|
||||
*/
|
||||
|
|
@ -450,6 +464,32 @@ vector<C>::operator* (long s) const
|
|||
return vector<C> (m_x * s, m_y * s);
|
||||
}
|
||||
|
||||
template <class C, typename Number>
|
||||
inline vector<C>
|
||||
operator/ (const db::vector<C> &p, Number s)
|
||||
{
|
||||
double mult = 1.0 / static_cast<double>(s);
|
||||
return vector<C> (p.x () * mult, p.y () * mult);
|
||||
}
|
||||
|
||||
template <class C>
|
||||
inline vector<C> &
|
||||
vector<C>::operator/= (double s)
|
||||
{
|
||||
double mult = 1.0 / static_cast<double>(s);
|
||||
*this *= mult;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
inline vector<C> &
|
||||
vector<C>::operator/= (long s)
|
||||
{
|
||||
double mult = 1.0 / static_cast<double>(s);
|
||||
*this *= mult;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
inline vector<C>
|
||||
vector<C>::operator*= (double s)
|
||||
|
|
|
|||
|
|
@ -70,6 +70,23 @@ struct point_defs
|
|||
return C (*p * s);
|
||||
}
|
||||
|
||||
static C divide (const C *p, double s)
|
||||
{
|
||||
return C (*p / s);
|
||||
}
|
||||
|
||||
static C iscale (C *p, double s)
|
||||
{
|
||||
*p *= s;
|
||||
return *p;
|
||||
}
|
||||
|
||||
static C idiv (C *p, double s)
|
||||
{
|
||||
*p /= s;
|
||||
return *p;
|
||||
}
|
||||
|
||||
static C negate (const C *p)
|
||||
{
|
||||
return -*p;
|
||||
|
|
@ -175,6 +192,30 @@ struct point_defs
|
|||
"Returns the scaled object. All coordinates are multiplied with the given factor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("*=", &iscale,
|
||||
"@brief Scaling by some factor\n"
|
||||
"\n"
|
||||
"@args f\n"
|
||||
"\n"
|
||||
"Scales object in place. All coordinates are multiplied with the given factor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("/", ÷,
|
||||
"@brief Division by some divisor\n"
|
||||
"\n"
|
||||
"@args d\n"
|
||||
"\n"
|
||||
"Returns the scaled object. All coordinates are divided with the given divisor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("/=", &idiv,
|
||||
"@brief Division by some divisor\n"
|
||||
"\n"
|
||||
"@args d\n"
|
||||
"\n"
|
||||
"Divides the object in place. All coordinates are divided with the given divisor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method ("distance", (double (C::*) (const C &) const) &C::double_distance,
|
||||
"@brief The Euclidian distance to another point\n"
|
||||
"\n"
|
||||
|
|
|
|||
|
|
@ -70,6 +70,23 @@ struct vector_defs
|
|||
return C (*p * s);
|
||||
}
|
||||
|
||||
static C divide (const C *p, double s)
|
||||
{
|
||||
return C (*p / s);
|
||||
}
|
||||
|
||||
static C iscale (C *p, double s)
|
||||
{
|
||||
*p *= s;
|
||||
return *p;
|
||||
}
|
||||
|
||||
static C idiv (C *p, double s)
|
||||
{
|
||||
*p /= s;
|
||||
return *p;
|
||||
}
|
||||
|
||||
static C negate (const C *p)
|
||||
{
|
||||
return -*p;
|
||||
|
|
@ -202,6 +219,30 @@ struct vector_defs
|
|||
"Returns the scaled object. All coordinates are multiplied with the given factor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("*=", &iscale,
|
||||
"@brief Scaling by some factor\n"
|
||||
"\n"
|
||||
"@args f\n"
|
||||
"\n"
|
||||
"Scales object in place. All coordinates are multiplied with the given factor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("/", ÷,
|
||||
"@brief Division by some divisor\n"
|
||||
"\n"
|
||||
"@args d\n"
|
||||
"\n"
|
||||
"Returns the scaled object. All coordinates are divided with the given divisor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("/=", &idiv,
|
||||
"@brief Division by some divisor\n"
|
||||
"\n"
|
||||
"@args d\n"
|
||||
"\n"
|
||||
"Divides the object in place. All coordinates are divided with the given divisor and if "
|
||||
"necessary rounded."
|
||||
) +
|
||||
method_ext ("vprod", &vprod,
|
||||
"@brief Computes the vector product between self and the given vector\n"
|
||||
"\n"
|
||||
|
|
|
|||
|
|
@ -493,7 +493,11 @@ static std::string extract_python_name (const std::string &name)
|
|||
} else if (name == "-@") {
|
||||
return "__neg__";
|
||||
} else if (name == "/") {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
return "__div__";
|
||||
#else
|
||||
return "__truediv__";
|
||||
#endif
|
||||
} else if (name == "*") {
|
||||
return "__mul__";
|
||||
} else if (name == "%") {
|
||||
|
|
@ -515,7 +519,11 @@ static std::string extract_python_name (const std::string &name)
|
|||
} else if (name == "-=") {
|
||||
return "__isub__";
|
||||
} else if (name == "/=") {
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
return "__idiv__";
|
||||
#else
|
||||
return "__itruediv__";
|
||||
#endif
|
||||
} else if (name == "*=") {
|
||||
return "__imul__";
|
||||
} else if (name == "%=") {
|
||||
|
|
@ -2698,6 +2706,11 @@ PythonModule::make_classes (const char *mod_name)
|
|||
add_python_doc (*c, mt, mid, tl::to_string (tr ("This method enables iteration of the object")));
|
||||
alt_names.push_back ("__iter__");
|
||||
|
||||
} else if (name == "__mul__") {
|
||||
// Adding right multiplication
|
||||
// Rationale: if pyaObj * x works, so should x * pyaObj
|
||||
add_python_doc (*c, mt, mid, tl::to_string (tr ("This method is also available as '__mul__'")));
|
||||
alt_names.push_back ("__rmul__");
|
||||
}
|
||||
|
||||
for (std::vector <std::string>::const_iterator an = alt_names.begin (); an != alt_names.end (); ++an) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "tlThreads.h"
|
||||
#include "tlUtils.h"
|
||||
#include "tlTimer.h"
|
||||
#include "tlLog.h"
|
||||
#include "tlInternational.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
|
||||
#include "tlTimer.h"
|
||||
#include "tlUtils.h"
|
||||
#include "tlLog.h"
|
||||
#include "tlString.h"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue