-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
130 lines (106 loc) · 4.51 KB
/
Copy pathsetup.py
File metadata and controls
130 lines (106 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python
import sys
import os
import glob
from distutils.core import setup
from distutils.command.install_data import install_data
from setuptools.command.install import install
import urllib.request
import re
import tarfile
import tempfile
import splotch
import subprocess
def compile_stan_code():
cmdstan_latest_url = 'https://api.github.com/repos/stan-dev/cmdstan/releases/latest'
# try to get the latest version number of CmdStan
req = urllib.request.Request(cmdstan_latest_url)
with urllib.request.urlopen(req) as response:
content = response.read()
latest_version = re.search('"tag_name":"([^"]*)"',str(content)).group(1)
# download the latest version of CmdStan
url_template = 'https://github.com/stan-dev/cmdstan/releases/download/%s/cmdstan-%s.tar.gz'
filename,_ = urllib.request.urlretrieve(url_template%(latest_version,latest_version.replace('v','')))
# extract the source file
temp_dir = tempfile.TemporaryDirectory()
with tarfile.open(filename) as f:
f.extractall(temp_dir.name)
# compile CmdStan
proc = subprocess.run(['make','build'],cwd=os.path.join(temp_dir.name,'cmdstan-%s'%(latest_version.replace('v',''))),stdout=sys.stdout,stderr=sys.stderr)
if proc.returncode:
if proc.stderr:
print(proc.stderr.decode('utf-8').strip())
sys.exit(3)
# find our stan models (i.e. stan/*.stan)
stan_files = glob.glob(os.path.join(os.getcwd(),'stan','*.stan'))
# compile our stan models
for stan_file in stan_files:
proc = subprocess.run(['make',re.sub('.stan$','',stan_file)],cwd=os.path.join(temp_dir.name,'cmdstan-%s'%(latest_version.replace('v',''))),stdout=sys.stdout,stderr=sys.stderr)
if proc.returncode:
print('Command "make %s" failed'%(re.sub('.stan$','',stan_file)))
if proc.stderr:
print(proc.stderr.decode('utf-8').strip())
sys.exit(3)
# our custom install_data script
# downloads and compiles CmdStan
# and compiles our Stan models
class StanCodeCompilation(install_data):
def run(self):
# let's not continue if the user didn't want to install CmdStan
# and compile the Stan models
if not compile_stan:
return
# compile our stan code first
compile_stan_code()
# run the default install_data script
install_data.run(self)
# our custom install script
# captures the install_option --stan
class InstallCommand(install):
user_options = install.user_options + [('stan',None,None)]
def initialize_options(self):
install.initialize_options(self)
self.stan = None
def finalize_options(self):
install.finalize_options(self)
def run(self):
#print(self.stan)
global compile_stan
if self.stan:
compile_stan = True
else:
compile_stan = False
install.run(self)
# read the long description
with open(os.path.join(os.path.abspath(os.path.dirname(__file__)),'README.md'),encoding='utf-8') as f:
long_description = f.read()
# read the package requirements
with open(os.path.join(os.path.abspath(os.path.dirname(__file__)),'requirements.txt'),encoding='utf-8') as f:
install_requires = f.read().splitlines()
# get the names of thestan executables
stan_files = [re.sub('.stan$','',stan_file) for stan_file in glob.glob(os.path.join(os.getcwd(),'stan','*.stan'))]
setup(name='cSplotch',
version=splotch.__version__,
description='Hierarchical model for Spatial Transcriptomics data',
long_description=long_description,
long_description_content_type='text/markdown',
author=splotch.__author__,
author_email=splotch.__email__,
url='https://github.com/adaly/cSplotch',
license=splotch.__license__,
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD 3-Clause "New" or "Revised" License (BSD-3-Clause)',
'Programming Language :: Python :: 3'],
packages=['splotch'],
scripts=['bin/splotch_prepare_count_files','bin/splotch_generate_input_files','bin/splotch',
'bin/splotch_summarize_output', 'bin/splotch_compile_lambdas',
'bin/splotch_compile_betas', 'bin/splotch_vinit'],
# could not pass binaries through the scripts argument
data_files=[('bin',stan_files)],
install_requires=install_requires,
cmdclass={
'install': InstallCommand,
'install_data': StanCodeCompilation}
)