github.com/getgauge/gauge@v1.6.9/build/pip/setup.tmpl (about) 1 """The setup installs Gauge CLI through pip.""" 2 from setuptools import setup 3 from setuptools.command.install import install 4 import json 5 import platform 6 import zipfile 7 import os 8 import sys 9 10 11 _version = "{0}" 12 _latest_version = "" 13 14 15 class CustomInstallCommand(install): 16 """Customized setuptools install command to download and setup.""" 17 18 _base_url = 'https://api.github.com/repos/getgauge/gauge/releases' 19 _arch_map = {{"ia32": "x86", "x64": "x86_64", "arm64": "arm64"}} 20 _os_map = {{"Darwin": "darwin", "Linux": "linux", "Windows": "windows"}} 21 _os_name = _os_map[platform.system()] 22 23 def _get_arch(self): 24 if 'arm64' in platform.platform(): 25 return self._arch_map['arm64'] 26 if '64' in platform.architecture()[0]: 27 return self._arch_map['x64'] 28 else: 29 return self._arch_map['ia32'] 30 31 def _get(self, url): 32 import requests 33 return requests.get(url) 34 35 def set_released_version(self): 36 global _latest_version 37 _latest_version = json.loads(self._get(self._base_url).text)[0]['tag_name'].replace('v', '') 38 39 def _get_gauge_file(self): 40 if self._os_name == 'win32': 41 return 'gauge.exe' 42 else: 43 return 'gauge' 44 45 def _gauge_package_fetch(self): 46 package_name = 'gauge-%s-%s.%s' % (_version, 47 self._os_name, self._get_arch()) 48 package_url = self._base_url.replace('api.', '').replace( 49 '/repos', '') + '/download/v%s/%s.zip' % (_version, package_name) 50 r2 = self._get(package_url) 51 with open("gauge.zip", "wb") as download: 52 download.write(r2.content) 53 54 def gauge_main_to_path(self): 55 """Place Gauge CLI into Scripts Directory.""" 56 self._gauge_package_fetch() 57 with zipfile.ZipFile('gauge.zip', "r") as z: 58 z.extractall() 59 target_path = os.path.join( 60 self.install_scripts, self._get_gauge_file()) 61 source_path = os.path.join(os.getcwd(), self._get_gauge_file()) 62 if os.path.isfile(target_path): 63 os.remove(target_path) 64 if os.path.isfile(source_path): 65 self.move_file(source_path, target_path) 66 if self._os_name != "win32": 67 if sys.version_info[0] == 3: 68 os.chmod(target_path, 0o755) 69 if sys.version_info[0] < 3: 70 os.chmod(target_path, 755) 71 72 def run(self): 73 """Custom Install / Run Command.""" 74 self.set_released_version() 75 self.gauge_main_to_path() 76 install.run(self) 77 print("\n***Gauge CLI - %s Installation Complete!***\n" % _version) 78 print("\n***Latest version of Gauge CLI is - %s***\n" % _latest_version) 79 80 81 82 def readme(): 83 """Get the README content for Long Description.""" 84 with open('README.md') as readme_file: 85 return readme_file.read() 86 87 88 setup( 89 name="{1}", 90 version=_version, 91 long_description=readme(), 92 long_description_content_type='text/markdown', 93 url='https://github.com/getgauge/gauge', 94 platforms=["Windows", "Linux", "Unix", "Mac OS-X"], 95 author='getgauge', 96 author_email='getgauge@googlegroups.com', 97 maintainer='getgauge', 98 license="Apache-2.0", 99 cmdclass={{ 100 'install': CustomInstallCommand, 101 }}, 102 classifiers=[ 103 "License :: OSI Approved :: Apache Software License", 104 "Development Status :: 5 - Production/Stable", 105 "Topic :: Internet", 106 "Topic :: Scientific/Engineering", 107 "Topic :: Software Development", 108 "Operating System :: Microsoft :: Windows", 109 "Operating System :: Unix", 110 "Operating System :: MacOS", 111 "Programming Language :: Python", 112 "Programming Language :: Python :: 2.7", 113 "Programming Language :: Python :: 3", 114 "Programming Language :: Python :: 3.4", 115 "Programming Language :: Python :: 3.5", 116 "Programming Language :: Python :: 3.6", 117 ], 118 install_requires=[ 119 'requests', 120 'markdown', 121 ], 122 setup_requires=['requests'] 123 )