This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsetup.py
executable file
·209 lines (172 loc) · 6.49 KB
/
setup.py
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
from shlex import split as parse
from subprocess import check_output
from setuptools import find_packages, setup
from setuptools.extension import Extension
CURR_DIR = os.path.dirname(__file__)
REQ_PATH = os.path.join(CURR_DIR, "requirements.txt")
def simple_call(command):
try:
return check_output(parse(command))
except Exception as e:
return 1
def spec_sys_calls(command):
if sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
command = [command, "sudo %s" % command]
return [command]
def install_cython_via_pip():
code = 1
calls = spec_sys_calls("pip3 install Cython")[0]
for i, command in enumerate(calls):
code = simple_call(command)
print(code)
if i >= len(calls) or code == 0:
break
return code
try:
from Cython.Build import cythonize
except ImportError: # Cython required
exit("Cython not found. You need to install Cython before pymarketcap.")
code = 1
base_call = "pip3 install -r %s" % REQ_PATH
calls = spec_sys_calls(base_call)
for i, command in enumerate(calls):
code = simple_call(command)
if i >= len(calls) or code == 0:
break
if code == 0:
print("Dependencies installed successfully.")
else:
print("Error installing dependencies, installing pymarketcap anywhere...")
# =========== Precompiler ===========
if "sdist" not in sys.argv:
from precompiler import run_builder, run_unbuilder
source = os.path.join(os.getcwd(), "pymarketcap", "core.pyx")
built = run_builder(source)
if not built:
if run_unbuilder():
if run_builder(source):
pass
else:
exit("Error building pymarketcap.")
else:
exit("Error building pymarketcap.")
# Check if minimum Python3.6
PYTHON_VERSION = sys.version_info
if PYTHON_VERSION < (3, 6,):
if PYTHON_VERSION > (3, 5,):
if "--quiet" not in sys.argv:
while True:
msg_scheme = "\nPython version:\n%s\n\nYou need " \
+ "to install almost Python3.6 in order to use " \
+ "the asynchronous Pymarketcap interface.\n" \
+ "Install pymarketcap without it anyway? Y/N: "
msg = msg_scheme % str(PYTHON_VERSION)
cont = str(input(msg)).lower()
if cont == "n":
exit("Installation cancelled.")
elif cont != "y":
print("Invalid option.")
else:
print("Installing pymarketcap...")
break
else:
exit("You need almost Python3.5 version to install pymarketcap.")
# =========== Cython compilation ===========
COMPILE_CURL = True
# Windows
if sys.platform.startswith('win32') and "--force-curl" not in sys.argv:
COMPILE_CURL = False
if "--force-curl" in sys.argv:
sys.argv.remove("--no-curl")
# Building on ReadTheDocs (very crazy):
if "--no-curl" in sys.argv or os.environ.get("READTHEDOCS") == "True":
COMPILE_CURL = False
if "--no-curl" in sys.argv:
sys.argv.remove("--no-curl")
def declare_cython_extension(ext_name, libraries=None):
"""Declare a Cython extension module for setuptools.
Args:
ext_name (str):
Absolute module name, e.g. use `mylibrary.mypackage.mymodule`
for the Cython source file `mylibrary/mypackage/mymodule.pyx`.
libraries (list):
Libraries needed to build the extension.
Returns (object):
Extension object that can be passed to ``setuptools.setup``.
"""
ext_path = ext_name.replace(".", os.path.sep) + ".pyx"
return Extension(ext_name, [ext_path], libraries=libraries)
ext_modules = [
declare_cython_extension("pymarketcap.core"),
declare_cython_extension("pymarketcap.processer"),
]
package_data = {"pymarketcap": ["core.pyx", "processer.pyx", ]}
if COMPILE_CURL:
ext_modules.append(
declare_cython_extension("pymarketcap.curl", libraries=["curl"])
)
package_data["pymarketcap"].extend(["curl.pyx", "curl.pxd"])
else:
core_path = os.path.join(CURR_DIR, "pymarketcap", "core.pyx")
with open(core_path, "r") as f:
content = f.readlines()
for i, line in enumerate(content):
if "from pymarketcap.curl import get_to_memory" in line:
content[i] = line.replace("curl", "url")
break
with open(core_path, "w") as f:
f.writelines(content)
ext_modules = cythonize(ext_modules)
# =========== Package metadata ===========
with open(os.path.join(CURR_DIR, 'README.rst')) as f:
LONG_DESC = f.read()
with open(REQ_PATH, "r") as f:
REQ = [line.strip("\n") for line in f.readlines()]
author, author_email = ("Álvaro Mondéjar Rubio", "[email protected]")
install = setup(
name="pymarketcap",
version="4.0.0017",
url="https://github.com/mondeja/pymarketcap",
download_url="https://github.com/mondeja/pymarketcap/archive/master.zip",
author=author,
maintainer=author,
author_email=author_email,
maintainer_email=author_email,
platforms=['any'],
license="BSD License",
description="Python3 API and web scraper for coinmarketcap.com.",
long_description=LONG_DESC,
keywords=["coinmarketcap", "cryptocurrency", "API", "wrapper",
"scraper", "json", "BTC", "Bitcoin", "C", "Curl", "Cython"],
install_requires=REQ,
packages=find_packages(exclude=["precompiler"]),
ext_modules=ext_modules,
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Financial and Insurance Industry",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Office/Business",
"Topic :: Office/Business :: Financial",
"Topic :: Office/Business :: Financial :: Accounting",
"Topic :: Office/Business :: Financial :: Investment",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
],
zip_safe=True,
provides=["setup_template_cython"]
)
print(
"\n%s v%s installation finished succesfully." % (
install.get_name().capitalize(),
install.get_version()
)
)