This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
79 lines (66 loc) · 2.5 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
from setuptools import setup, find_packages, Command
import os
from os import path
import subprocess
import configparser
# Get config parameters
config = configparser.ConfigParser()
config.read('setup.cfg')
pkg_name = config['metadata']['name']
pypi_server = config['netsquid']['pypi-server']
def load_readme_text():
"""Load in README file as a string."""
try:
dir_path = path.abspath(path.dirname(__file__))
with open(path.join(dir_path, 'README.md'), encoding='utf-8') as f:
return f.read()
except FileNotFoundError:
return ""
def load_requirements():
"""Load in requirements.txt as a list of strings."""
try:
dir_path = path.abspath(path.dirname(__file__))
with open(path.join(dir_path, 'requirements.txt'), encoding='utf-8') as f:
install_requires = [line.strip() for line in f.readlines()]
return install_requires
except FileNotFoundError:
return ""
class DeployCommand(Command):
"""Run command for uploading binary wheel files to NetSquid PyPi index.
"""
description = "Deploy binary wheel files to NetSquid PyPi index."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print("Uploading binary snippet {} wheels to {} (requires authentication)"
.format(pkg_name, pypi_server))
if 'NETSQUIDCI_USER' not in os.environ:
print("ERROR: environment variable NETSQUIDCI_USER is not defined.")
return
# Check for wheel files
wheel_files = []
for f in os.listdir("dist/"):
if f.endswith(".whl"):
wheel_files.append("dist/{}".format(f))
# Upload wheel files
if len(wheel_files) > 0:
subprocess.check_output(("/usr/bin/scp", " ".join(wheel_files), "{}@{}:/srv/netsquid/pypi/{}/".format(
os.environ['NETSQUIDCI_USER'], pypi_server, pkg_name)), encoding='utf8')
else:
print("ERROR: no wheel files in dist/ to upload.")
setup(
cmdclass={"deploy": DeployCommand},
long_description=load_readme_text(),
long_description_content_type='text/markdown',
python_requires='>=3.5',
packages=find_packages(), # if offering a package
#py_modules=['pkgname.replace('-', '_')'], # if offering a single module file
install_requires=load_requirements(),
test_suite=pkg_name.replace('-', '_'),
zip_safe=False,
include_package_data=True,
platforms='any',
)