Skip to content

Commit 7c31ede

Browse files
committed
Commit initial package structure.
1 parent ca43bd5 commit 7c31ede

File tree

3 files changed

+194
-0
lines changed

3 files changed

+194
-0
lines changed

dist_utils.py

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# -*- coding: utf-8 -*-
2+
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from __future__ import absolute_import
18+
import os
19+
import re
20+
import sys
21+
22+
from distutils.version import StrictVersion
23+
24+
GET_PIP = 'curl https://bootstrap.pypa.io/get-pip.py | python'
25+
26+
try:
27+
import pip
28+
from pip import __version__ as pip_version
29+
except ImportError as e:
30+
print('Failed to import pip: %s' % (str(e)))
31+
print('')
32+
print('Download pip:\n%s' % (GET_PIP))
33+
sys.exit(1)
34+
35+
try:
36+
# pip < 10.0
37+
from pip.req import parse_requirements
38+
except ImportError:
39+
# pip >= 10.0
40+
41+
try:
42+
from pip._internal.req.req_file import parse_requirements
43+
except ImportError as e:
44+
print('Failed to import parse_requirements from pip: %s' % (str(e)))
45+
print('Using pip: %s' % (str(pip_version)))
46+
sys.exit(1)
47+
48+
__all__ = [
49+
'check_pip_version',
50+
'fetch_requirements',
51+
'apply_vagrant_workaround',
52+
'get_version_string',
53+
'parse_version_string'
54+
]
55+
56+
57+
def check_pip_version(min_version='6.0.0'):
58+
"""
59+
Ensure that a minimum supported version of pip is installed.
60+
"""
61+
if StrictVersion(pip.__version__) < StrictVersion(min_version):
62+
print("Upgrade pip, your version '{0}' "
63+
"is outdated. Minimum required version is '{1}':\n{2}".format(pip.__version__,
64+
min_version,
65+
GET_PIP))
66+
sys.exit(1)
67+
68+
69+
def fetch_requirements(requirements_file_path):
70+
"""
71+
Return a list of requirements and links by parsing the provided requirements file.
72+
"""
73+
links = []
74+
reqs = []
75+
for req in parse_requirements(requirements_file_path, session=False):
76+
# Note: req.url was used before 9.0.0 and req.link is used in all the recent versions
77+
link = getattr(req, 'link', getattr(req, 'url', None))
78+
if link:
79+
links.append(str(link))
80+
reqs.append(str(req.req))
81+
return (reqs, links)
82+
83+
84+
def apply_vagrant_workaround():
85+
"""
86+
Function which detects if the script is being executed inside vagrant and if it is, it deletes
87+
"os.link" attribute.
88+
Note: Without this workaround, setup.py sdist will fail when running inside a shared directory
89+
(nfs / virtualbox shared folders).
90+
"""
91+
if os.environ.get('USER', None) == 'vagrant':
92+
del os.link
93+
94+
95+
def get_version_string(init_file):
96+
"""
97+
Read __version__ string for an init file.
98+
"""
99+
100+
with open(init_file, 'r') as fp:
101+
content = fp.read()
102+
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
103+
content, re.M)
104+
if version_match:
105+
return version_match.group(1)
106+
107+
raise RuntimeError('Unable to find version string in %s.' % (init_file))
108+
109+
110+
# alias for get_version_string
111+
parse_version_string = get_version_string

setup.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import os
17+
18+
from setuptools import setup, find_packages
19+
20+
from dist_utils import check_pip_version
21+
from dist_utils import fetch_requirements
22+
from dist_utils import parse_version_string
23+
24+
check_pip_version()
25+
26+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
27+
REQUIREMENTS_FILE = os.path.join(BASE_DIR, 'requirements.txt')
28+
INIT_FILE = os.path.join(BASE_DIR, 'st2rbac_enterprise_backend_default', '__init__.py')
29+
30+
version = parse_version_string(INIT_FILE)
31+
install_reqs, dep_links = fetch_requirements(REQUIREMENTS_FILE)
32+
33+
setup(
34+
name='st2-enterprise-rbac-backend-default',
35+
version=version,
36+
description='Enterprise RBAC backend for StackStorm.',
37+
author='StackStorm, Inc.',
38+
author_email='[email protected]',
39+
url='https://github.com/StackStorm/st2-enterprise-rbac-backend-default',
40+
license='Proprietary License',
41+
download_url=(
42+
'https://github.com/StackStorm/st2-enterprise-rbac-backend-default/tarball/master'
43+
),
44+
classifiers=[
45+
'License :: Other/Proprietary License'
46+
'Programming Language :: Python',
47+
'Programming Language :: Python :: 2',
48+
'Programming Language :: Python :: 2.7',
49+
'Programming Language :: Python :: 3',
50+
'Programming Language :: Python :: 3.6',
51+
'Environment :: Console',
52+
],
53+
platforms=['Any'],
54+
scripts=[],
55+
provides=['st2rbac_enterprise_backend_default'],
56+
packages=find_packages(),
57+
include_package_data=True,
58+
install_requires=install_reqs,
59+
dependency_links=dep_links,
60+
test_suite='tests',
61+
entry_points={
62+
'st2rbac.backends.backend': [
63+
'enterprise = st2rbac_enterprise_backend_default.',
64+
],
65+
},
66+
zip_safe=False
67+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
__version__ = '3.0dev'

0 commit comments

Comments
 (0)