Skip to content

Commit

Permalink
Fix build happening twice in manual installation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhers committed Aug 17, 2017
1 parent b73b395 commit 51185bf
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 56 deletions.
18 changes: 10 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ install:
cmake .. || travis_terminate 1;
sudo make install || travis_terminate 1;
cd ../..;
export EIGEN3_INCLUDE_DIR=/usr/local/include/eigen3;
fi'

before_script:
Expand All @@ -69,7 +70,8 @@ before_script:
- 'if [[ "$PYTHON_INSTALL" == "manual" ]]; then
mkdir build;
cd build;
cmake .. -DEIGEN3_INCLUDE_DIR=/usr/local/include/eigen3 -DENABLE_BOOST=ON -DENABLE_CPP_EXAMPLES=ON -DPYTHON=$(which python) || travis_terminate 1;
export INSTALL_PREFIX=$(dirname $(which python))/..;
cmake .. -DEIGEN3_INCLUDE_DIR=${EIGEN3_INCLUDE_DIR} -DENABLE_BOOST=ON -DENABLE_CPP_EXAMPLES=ON -DPYTHON=$(which python) -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX || travis_terminate 1;
else
pip install -v . || travis_terminate 1;
fi'
Expand All @@ -80,17 +82,17 @@ after_failure:
script:
- 'if [[ "$PYTHON_INSTALL" == "manual" ]]; then
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
make -j$(nproc);
fi;
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
make -j$(sysctl -n hw.ncpu);
export DYLD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/build/dynet:$DYLD_LIBRARY_PATH;
make -j$(nproc) || travis_terminate 1;
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
make -j$(sysctl -n hw.ncpu) || travis_terminate 1;
export DYLD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/build/dynet;
fi;
make install || travis_terminate 1;
make test || travis_terminate 1;
cd python;
python ../../setup.py build --build-dir=.. install --user || travis_terminate 1;
python ../../setup.py build --build-dir=.. --skip-build install --user || travis_terminate 1;
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
export DYLD_LIBRARY_PATH=$(dirname $(which python))/../lib:$DYLD_LIBRARY_PATH;
export DYLD_LIBRARY_PATH=$INSTALL_PREFIX/lib:$DYLD_LIBRARY_PATH;
fi'
- cd $TRAVIS_BUILD_DIR/tests/python
- python test.py
8 changes: 4 additions & 4 deletions doc/source/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The following is a list of all the commands needed to perform a manual install:
make -j 2 # replace 2 with the number of available cores
cd python
python ../../setup.py build --build-dir=.. install # add `--user` for a user-local install.
python ../../setup.py build --build-dir=.. --skip-build install # add `--user` for a user-local install.
# this should suffice, but on some systems you may need to add the following line to your
# init files in order for the compiled .so files be accessible to Python.
Expand Down Expand Up @@ -149,12 +149,12 @@ in the system, run the following:
.. code:: bash
cd $PATH_TO_DYNET/build/python
python ../../setup.py build --build-dir=.. install --user
python ../../setup.py build --build-dir=.. --skip-build install --user
The ``--user`` switch will install the module in your local
site-packages, and works without root privileges. To install the module
to the system site-packages (for all users), or to the current `virtualenv`
(if you are on one), run ``python ../../setup.py build --build-dir=.. install`` without this switch.
(if you are on one), run ``python ../../setup.py build --build-dir=.. --skip-build install`` without this switch.

You should now have a working python binding (the ``dynet`` module).

Expand Down Expand Up @@ -253,7 +253,7 @@ After running ``make -j 2``, you should have the files ``_dynet.so`` and
``_gdynet.so`` in the ``build/python`` folder.

As before, ``cd build/python`` followed by
``python ../../setup.py build --build-dir=.. install --user`` will install the module.
``python ../../setup.py build --build-dir=.. --skip-build install --user`` will install the module.



Expand Down
90 changes: 46 additions & 44 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ def strip_lib(filename):
class build(_build):
user_options = [
("build-dir=", None, "New or existing DyNet build directory."),
("skip-build", None, "Assume DyNet C++ library is already built."),
]

def __init__(self, *args, **kwargs):
self.build_dir = None
self.skip_build = False
_build.__init__(self, *args, **kwargs)

def initialize_options(self):
Expand All @@ -183,56 +185,56 @@ def run(self):
log.info("EIGEN3_INCLUDE_DIR=" + EIGEN3_INCLUDE_DIR)
log.info("CC_PATH=" + CC_PATH)
log.info("CXX_PATH=" + CXX_PATH)
log.info("SCRIPT_DIR" + SCRIPT_DIR)
log.info("BUILD_DIR" + BUILD_DIR)
log.info("SCRIPT_DIR=" + SCRIPT_DIR)
log.info("BUILD_DIR=" + BUILD_DIR)
log.info("INSTALL_PREFIX=" + INSTALL_PREFIX)
log.info("PYTHON=" + PYTHON)
run_process([CMAKE_PATH, "--version"])
run_process([CXX_PATH, "--version"])

# Prepare folders
os.chdir(SCRIPT_DIR)
if not os.path.exists(BUILD_DIR):
log.info("Creating build directory " + BUILD_DIR)
os.makedirs(BUILD_DIR)

os.chdir(BUILD_DIR)
if os.path.isdir(EIGEN3_INCLUDE_DIR):
log.info("Found eigen in " + EIGEN3_INCLUDE_DIR)
elif HG_PATH is None:
raise DistutilsSetupError("`hg` not found.")
else:
hg_cmd = [HG_PATH, "clone", "https://bitbucket.org/eigen/eigen"]
log.info("Cloning Eigen...")
if run_process(hg_cmd) != 0:
raise DistutilsSetupError(" ".join(hg_cmd))

os.environ["CXX"] = CXX_PATH
os.environ["CC"] = CC_PATH

# Build module
cmake_cmd = [
CMAKE_PATH,
SCRIPT_DIR,
"-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX,
"-DEIGEN3_INCLUDE_DIR=" + EIGEN3_INCLUDE_DIR,
"-DPYTHON=" + PYTHON,
]
log.info("Configuring...")
if run_process(cmake_cmd) != 0:
raise DistutilsSetupError(" ".join(cmake_cmd))

make_cmd = [MAKE_PATH] + MAKE_FLAGS
log.info("Compiling...")
if run_process(make_cmd) != 0:
raise DistutilsSetupError(" ".join(make_cmd))
BUILT_EXTENSIONS = True # because make calls build_ext

make_cmd = [MAKE_PATH, "install"]
log.info("Installing...")
if run_process(make_cmd) != 0:
raise DistutilsSetupError(" ".join(make_cmd))
if not self.skip_build:
# Prepare folders
if not os.path.isdir(BUILD_DIR):
log.info("Creating build directory " + BUILD_DIR)
os.makedirs(BUILD_DIR)

os.chdir(BUILD_DIR)
if os.path.isdir(EIGEN3_INCLUDE_DIR):
log.info("Found eigen in " + EIGEN3_INCLUDE_DIR)
elif HG_PATH is None:
raise DistutilsSetupError("`hg` not found.")
else:
hg_cmd = [HG_PATH, "clone", "https://bitbucket.org/eigen/eigen"]
log.info("Cloning Eigen...")
if run_process(hg_cmd) != 0:
raise DistutilsSetupError(" ".join(hg_cmd))

os.environ["CXX"] = CXX_PATH
os.environ["CC"] = CC_PATH

# Build module
cmake_cmd = [
CMAKE_PATH,
SCRIPT_DIR,
"-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX,
"-DEIGEN3_INCLUDE_DIR=" + EIGEN3_INCLUDE_DIR,
"-DPYTHON=" + PYTHON,
]
log.info("Configuring...")
if run_process(cmake_cmd) != 0:
raise DistutilsSetupError(" ".join(cmake_cmd))

make_cmd = [MAKE_PATH] + MAKE_FLAGS
log.info("Compiling...")
if run_process(make_cmd) != 0:
raise DistutilsSetupError(" ".join(make_cmd))

make_cmd = [MAKE_PATH, "install"]
log.info("Installing...")
if run_process(make_cmd) != 0:
raise DistutilsSetupError(" ".join(make_cmd))

BUILT_EXTENSIONS = True # because make calls build_ext
_build.run(self)


Expand Down

0 comments on commit 51185bf

Please sign in to comment.