Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ docs/_build

Releases/
dist/
*.egg-info

Tutorials/Klarner2018/jobs.py
Tutorials/*/*.json
Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
global-exclude *~
global-exclude *.pyc

recursive-include pyboolnet/binaries *
recursive-include pyboolnet/repository *
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,3 @@ clasp = ./clasp-3.1.1/clasp-3.1.1-x86-linux
bnet2prime = ./BNetToPrime/BNetToPrime_linux64
espresso = ./espresso/espresso_linux64
eqntott = ./eqntott/eqntott_linux64
dot = /usr/bin/dot
neato = /usr/bin/neato
fdp = /usr/bin/fdp
sfdp = /usr/bin/sfdp
circo = /usr/bin/circo
twopi = /usr/bin/twopi
convert = /usr/bin/convert
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,3 @@ clasp = ./clasp-3.2.0/clasp-3.2.0_mac64
bnet2prime = ./BNetToPrime/BNetToPrime_mac64
espresso = ./espresso/espresso_mac64
eqntott = ./eqntott/eqntott_mac64
dot = /usr/bin/dot
neato = /usr/bin/neato
fdp = /usr/bin/fdp
sfdp = /usr/bin/sfdp
circo = /usr/bin/circo
twopi = /usr/bin/twopi
convert = /usr/bin/convert
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,3 @@ clasp = ./clasp-3.1.1/clasp-3.1.1_win64.exe
bnet2prime = ./BNetToPrime/BNetToPrime_win64.exe
espresso = ./espresso/espresso_win64.exe
eqntott = ./eqntott/eqntott_win64.exe
dot = dot
neato = neato
fdp = fdp
sfdp = sfdp
circo = circo
twopi = twopi
convert = convert
64 changes: 52 additions & 12 deletions pyboolnet/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@
import logging
import math
import os

import platform
from importlib.resources import files, as_file
from pathlib import Path
import shutil

from typing import List
from configparser import ConfigParser

ROOT_DIR = os.path.join(os.path.dirname(__file__))

_SUBDIR_MAP = {
"Linux": "linux64",
"Darwin": "mac64",
"Windows": "win64",
}


log = logging.getLogger(__name__)

Expand All @@ -17,20 +29,48 @@ def read_txt_version() -> str:
with open(os.path.join(ROOT_DIR, "version.txt"), "r") as fp:
return fp.read()

def _get_platform_subdir() -> str:
system = platform.system()
try:
return _SUBDIR_MAP[system]
except KeyError:
raise RuntimeError(f"Unsupported OS: {system}")

def read_executables() -> dict:
config_parser = ConfigParser()
settings_file = os.path.join(ROOT_DIR, "binaries", "settings.cfg")

if not os.path.exists(settings_file):
execs = dict(
nusmv="./NuSMV-2.6.0/bin/NuSMV",
gringo="./gringo-4.4.0-x86-linux/gringo",
clasp="./clasp-3.1.1/clasp-3.1.1-x86-linux",
bnet2prime="./BNetToPrime/BNetToPrime")
else:
config_parser.read(settings_file)
execs = {n: config_parser.get("Executables", n) for n in config_parser.options("Executables")}
"""
Collects paths to executables
"""

execs = {}

# OS-specific binaries directory within installed package
subdir = _get_platform_subdir()
binaries_dir = files("pyboolnet.binaries") / subdir
settings_resource = binaries_dir / "settings.cfg"

if not settings_resource.exists():
raise RuntimeError(f"Missing settings.cfg in {binaries_dir}")

with as_file(settings_resource) as settings_path:
config_parser = ConfigParser()
config_parser.read(settings_path)
for name in config_parser.options("Executables"):
raw_path = config_parser.get("Executables", name)
p = Path(raw_path)

# relative path to the settings.cfg file
if p.is_absolute():
execs[name] = str(p)
else:
execs[name] = str((binaries_dir / raw_path).resolve())

# system tools
for executable in ["dot", "neato", "fdp", "sfdp", "circo", "twopi", "convert"]:
path = shutil.which(executable)
if path is None:
log.warning("Executable %s not found in system PATH", executable)
else:
execs[executable] = path

return execs

Expand Down
41 changes: 7 additions & 34 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,22 @@

from pyboolnet import VERSION

PACKAGE_DATA_FILES = []
THIS_OS = platform.system()
SUBDIR_MAP = dict(
Linux="linux64",
Darwin="mac64",
Windows="win64",
)

if "CONDA_BUILD" in os.environ:
subdir = "conda"
else:
try:
subdir = SUBDIR_MAP[THIS_OS]
except KeyError:
print(f"the operating system is not recognized: os={THIS_OS}")
sys.exit(1)

BINARIES_SOURCE_DIR = os.path.join("binaries", subdir)
print(f"detected os and binaries: {THIS_OS=}, {BINARIES_SOURCE_DIR=}")

BINARIES_TARGET_DIR = os.path.join("pyboolnet", "binaries")
copy_tree(src=BINARIES_SOURCE_DIR, dst=BINARIES_TARGET_DIR)
print(f"copy_tree: {BINARIES_SOURCE_DIR=}, {BINARIES_TARGET_DIR=}")

for root, _, filenames in os.walk(BINARIES_TARGET_DIR):
root = root.replace(BINARIES_TARGET_DIR, "binaries")
PACKAGE_DATA_FILES.extend([os.path.join(root, x) for x in filenames])

REPOSITORY_PATH = os.path.join("pyboolnet", "repository")
for root, _, filenames in os.walk(REPOSITORY_PATH):
root = root.replace(REPOSITORY_PATH, "repository")
PACKAGE_DATA_FILES.extend([os.path.join(root, x) for x in filenames])

setup(
name="pyboolnet",
version=VERSION,
description="Python toolbox for the generation, manipulation and analysis of Boolean networks.",
author="Hannes Klarner",
author_email="leevilux@yahoo.de",
url="https://github.com/hklarner/pyboolnet",
package_data={"pyboolnet": PACKAGE_DATA_FILES, "": ['version.txt']},
packages=find_packages(),
include_package_data=True,
package_data={
"pyboolnet": [
"binaries/*/*",
"binaries/*/*/*",
"repository/**/*"],
"": ['version.txt'],
},
classifiers=[
"Programming Language :: Python",
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
Expand Down