Skip to content

Commit

Permalink
pip install pybind (#17)
Browse files Browse the repository at this point in the history
* pip install pybind, flake8/mypy setup.py
* Remove MANIFEST.in
*Update README for pip install
*mypy is wrong about 'build' so setup.py not added yet
  • Loading branch information
hoffmang9 authored May 18, 2020
1 parent be02389 commit 73c916a
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 45 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ jobs:
fetch-depth: 0
# we need fetch-depth 0 so setuptools_scm can resolve tags

- name: Checkout submodules
uses: snickerbockers/submodules-init@v4

- uses: actions/setup-python@v1
name: Install Python
with:
python-version: '3.7'

- name: Install cibuildwheel
- name: Install cibuildwheel and pybind11
run: |
python -m pip install --upgrade pip
pip install wheel
pip install wheel pybind11==2.5.0
pip install cibuildwheel==1.3.0
- name: Lint source with flake8
run: |
pip install flake8
flake8 src
flake8 src setup.py
- name: Lint source with mypy
run: |
Expand Down Expand Up @@ -60,9 +63,11 @@ jobs:
&& rm -f /usr/bin/cmake
&& yum -y install boost-devel gmp-devel
&& python -m pip install --upgrade pip
&& pip install pybind11==2.5.0
CIBW_BEFORE_BUILD_MACOS: >
brew install boost
&& python -m pip install --upgrade pip
&& pip install pybind11==2.5.0
CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=10.14
CIBW_BUILD_VERBOSITY_MACOS: 0
CIBW_TEST_REQUIRES: pytest
Expand All @@ -74,6 +79,7 @@ jobs:
&& cp {wheel} {dest_dir}
CIBW_BEFORE_BUILD_WINDOWS: >
python -m pip install --upgrade pip
&& pip install pybind11==2.5.0
&& git clone https://github.com/Chia-Network/mpir_gc_x64.git
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: >
ls -l mpir_gc_x64 && pip uninstall -y delocate
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Chia-Network/chiavdf.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Chia-Network/chiavdf/context:python)
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/Chia-Network/chiavdf.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Chia-Network/chiavdf/context:cpp)

## Building
This component requires cmake, boost and GMP.
## Building a wheel
Compiling chiavdf requires cmake, boost and GMP.
```
pip install wheel setuptools_scm
python3 -m venv venv
source venv/bin/activate
pip install wheel setuptools_scm pybind11
pip wheel .
```

The primary build process for this repository is to use GitHub Actions to
build binary wheels for MacOS, Linux, and Windows and publish them with
a source wheel on PyPi. See `.github/workflows/build.yml`. setup.py adds
a dependency on [pybind11](https://github.com/pybind/pybind11) by invoking git
to check out the pybind submodules. Building is then managed by
a dependency on [pybind11](https://github.com/pybind/pybind11) using
`pip install pybind11`. Building is then managed by
[cibuildwheel](https://github.com/joerick/cibuildwheel). Further installation
is then available via `pip install chiavdf` e.g.

Expand All @@ -37,7 +40,7 @@ To build vdf_client set the environment variable BUILD_VDF_CLIENT to "Y".
Similarly, to build vdf_bench set the environment variable BUILD_VDF_BENCH to
"Y". `export BUILD_VDF_BENCH=Y`.

This is currently automated in the
This is currently automated via pip in the
[install-timelord.sh](https://github.com/Chia-Network/chia-blockchain/blob/master/install-timelord.sh)
script in the
[chia-blockchain repository](https://github.com/Chia-Network/chia-blockchain)
Expand Down
59 changes: 24 additions & 35 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from distutils.command.install import install
from distutils.command.build import build
import os
import re
import shutil
import sys
import platform
import subprocess

from setuptools import Command
from distutils.command.build import build
from distutils.command.install import install
from distutils.version import LooseVersion
from setuptools.command.build_ext import build_ext
from setuptools import setup, setuptools, Extension, Command


BUILD_HOOKS = []
Expand Down Expand Up @@ -46,18 +54,6 @@ class install_hook(HookCommand):
############################################


import os
import re
import shutil
import sys
import platform
import subprocess

from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from distutils.version import LooseVersion


class CMakeExtension(Extension):
def __init__(self, name, sourcedir=''):
Extension.__init__(self, name, sources=['./'])
Expand Down Expand Up @@ -95,18 +91,9 @@ def run(self):
try:
out = subprocess.check_output(['cmake', '--version'])
except OSError:
raise RuntimeError("CMake must be installed to build" +
" the following extensions: " +
", ".join(e.name for e in self.extensions))
"""
Work around pybind11's need to be on the filesystem
"""
if os.path.exists('.gitmodules'):
try:
subprocess.run(['git', 'submodule', 'update', '--init', '--recursive'])
except OSError:
raise RuntimeError("git is not available"
+ ", ".join(e.name for e in self.extensions))
raise RuntimeError("CMake must be installed to build"
+ " the following extensions: "
+ ", ".join(e.name for e in self.extensions))

if platform.system() == "Windows":
cmake_version = LooseVersion(
Expand Down Expand Up @@ -137,8 +124,9 @@ def build_extension(self, ext):

env = os.environ.copy()
env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(
env.get('CXXFLAGS', ''),
self.distribution.get_version())
env.get('CXXFLAGS', ''),
self.distribution.get_version()
)
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, env=env)
subprocess.check_call(['cmake', '--build', '.'] + build_args)

Expand All @@ -161,7 +149,7 @@ def __str__(self):
ext_modules = [
Extension(
'chiavdf',
sorted (
sorted(
[
"src/python_bindings/fastvdf.cpp",
"src/refcode/lzcnt.c",
Expand Down Expand Up @@ -204,7 +192,8 @@ def cpp_flag(compiler):
flags = ['-std=c++17', '-std=c++14', '-std=c++11']

for flag in flags:
if has_flag(compiler, flag): return flag
if has_flag(compiler, flag):
return flag

raise RuntimeError('Unsupported compiler -- at least C++11 support '
'is needed!')
Expand All @@ -213,12 +202,12 @@ def cpp_flag(compiler):
class BuildExt(build_ext):
"""A custom build extension for adding compiler-specific options."""
c_opts = {
'msvc': ['/EHsc','/std:c++17'],
'unix': [],
'msvc': ['/EHsc', '/std:c++17'],
'unix': [""],
}
l_opts = {
'msvc': [],
'unix': [],
'msvc': [""],
'unix': [""],
}

if sys.platform == 'darwin':
Expand Down
Loading

0 comments on commit 73c916a

Please sign in to comment.