Skip to content

Commit

Permalink
Fixed installation.
Browse files Browse the repository at this point in the history
Updated build and installation according to Poetry 1.0.1
See this for details:
python-poetry/poetry#2740
  • Loading branch information
Alexander-Belyi committed Feb 11, 2021
1 parent ead94f2 commit e4623f3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
39 changes: 30 additions & 9 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# from distutils.command.build_ext import build_ext
# from distutils.core import Extension
from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError
import os
import shutil

from pybind11.setup_helpers import Pybind11Extension, build_ext
from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError
from distutils.core import Distribution


ext_modules = [
Pybind11Extension(
"_combo", sources=["src/Graph.cpp", "src/Combo.cpp", "src/Binder.cpp"]
"pycombo._combo", sources=["src/Graph.cpp", "src/Combo.cpp", "src/Binder.cpp"]
)
]

Expand All @@ -20,7 +22,7 @@ def run(self):
try:
build_ext.run(self)
except (DistutilsPlatformError, FileNotFoundError):
raise BuildFailed("File not found. Could not compile C extension.")
raise BuildFailed("File not found. Could not compile C++ extension.")

def build_extension(self, ext):
try:
Expand All @@ -31,13 +33,32 @@ def build_extension(self, ext):
DistutilsPlatformError,
ValueError,
) as e:
raise BuildFailed(f"Could not compile C extension: {e}")
raise BuildFailed(f"Could not compile C++ extension: {e}")


def build(setup_kwargs):
"""
This function is mandatory in order to build the extensions.
"""
setup_kwargs.update(
{"ext_modules": ext_modules, "cmdclass": {"build_ext": ExtBuilder}}
)
distribution = Distribution({"name": "pycombo", "ext_modules": ext_modules})

cmd = ExtBuilder(distribution)
cmd.ensure_finalized()
cmd.run()

# Copy built extensions back to the project
for output in cmd.get_outputs():
relative_extension = os.path.relpath(output, cmd.build_lib)
if not os.path.exists(output):
continue

shutil.copyfile(output, relative_extension)
mode = os.stat(relative_extension).st_mode
mode |= (mode & 0o444) >> 2
os.chmod(relative_extension, mode)

return setup_kwargs


if __name__ == "__main__":
build({})
4 changes: 2 additions & 2 deletions pycombo/pyCombo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging
from typing import Optional, Tuple
import _combo as comboCPP
import pycombo._combo as comboCPP

__author__ = "Philipp Kats"
__copyright__ = "Philipp Kats"
Expand All @@ -27,7 +27,7 @@ def _check_repr(graph):
def get_combo_partition(
graph,
weight_prop: Optional[str] = 'weight',
max_communities: int = -1,
max_communities: int = -1,
modularity_resolution: int = 1,
num_split_attempts: int = 0,
fixed_split_step: int = 0,
Expand Down
19 changes: 14 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ version = "0.0.2"
description = "Python wrapper around Combo network partitioning algorythm (C++)"
authors = ["Philipp <casyfill@gmail.com>"]
license = "MIT"
build = 'build.py'

include = [
# C++ sources must be included in the sdist distributions
{path = "src", format = "sdist"},
# C++ extension must be included in the wheel distributions
{path = "pycombo/*.so", format = "wheel"},
{path = "pycombo/*.pyd", format = "wheel"},
]

[tool.poetry.build]
script = "build.py"
generate-setup-file = false

[tool.poetry.dependencies]
python = "^3.7"
Expand All @@ -22,10 +33,8 @@ black = "^20.8b1"
pre-commit = "^2.9.3"

[build-system]
requires = ["poetry>=0.12", "wheel", "setuptools","pybind11==2.6.0"]
build-backend = "poetry.masonry.api"
# requires = ["setuptools", "wheel", "pybind11==2.6.0"]
# build-backend = "setuptools.build_meta"
requires = ["poetry-core>=1.0.1", "pybind11==2.6.0"]
build-backend = "poetry.core.masonry.api"

[tool.pytest]
testpaths = "tests"

0 comments on commit e4623f3

Please sign in to comment.