Skip to content

Commit 7fe7416

Browse files
authored
Ron/platform wheels support (microsoft#161)
* Merge release 1.0.0a21 (microsoft#155) * Use SqlToolsService built on .NET Core 2.0 and a build script updates (microsoft#131) * Bump version to 1.0.0a19 * Use .NET Core 2.0 RTM built sqltoolsservice * Add build script to upload to azure blob storage * Upgrade to VS 2017 * Remove 3.3 as supported Python version * Fix perf issue where main event loop takes 100% of CPU (microsoft#132) Fix perf issue where main event loop takes 100% of CPU We have a 2 threads: Thread microsoft#1 runs in a loop polling the response queue Thread microsoft#2 runs in a loop decoding responses from the sqltoolsservice over stdout and posting them to the response queue Since thread microsoft#1 doesn't sleep, it's takes 100% CPU. In addition, running python 2.7 on windows, microsoft#2 doesn’t preempt the CPU due to microsoft#1 taking all of the CPU cycles, so no response is processed. Fix is simple – thread microsoft#1 needs to sleep so thread microsoft#2 can get scheduled and get it’s work done. * Refine event loop perf fix in main.py Refine event loop perf fix in main.py * Fixing regular expression Previous regex would result in release:a1 and release_version: 12. Modified the regex for part Release to only pick up lower case letters. * Adding missing forward slash on test pypi url * fixing typos/grammar (microsoft#138) fixing typos/grammar. * Updating to release version 1.0.0a20. * Create doc for official msft docs page * Updated documentation page with usage_guide * Added link to download adventureworks * Updated with sqlcmd usage * Added in run and cloud shell support * Update/consolidate linux install (microsoft#153) * universal linux wheel gen and setup update. * Updating version cfg. * Updating sqltoolsservice container. * Updating spacing for flake8. * Updating team email. (microsoft#154) * Updating mssqltoolsservice to be integrated as a package of mssqlscripter. * Updating sqltoolsservice to be loaded from the repro instead of storage account. * Fix index file generation for daily storage account. * Fixing manylinux1 tag. * Updating platform tag for win x64. * Renaming sqltoolsservice win x64 folder. * Adding platform tags for win_amd64, manylinux1_x86_64, manylinux1_i686. * version bumping to 1.0.0a22. * Flake8 format fixes. * Erroring out when build receives invalid flag.
1 parent cb837c3 commit 7fe7416

27 files changed

+249
-514
lines changed

.bumpversion.cfg

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[bumpversion]
2-
current_version = 1.0.0a21
3-
2+
current_version = 1.0.0a22
43
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((?P<release>[a-z]+))(?P<release_version>\d+)
54
serialize =
65
{major}.{minor}.{patch}{release}{release_version}
@@ -14,9 +13,5 @@ values =
1413

1514
[bumpversion:file:setup.py]
1615

17-
[bumpversion:file:mssqltoolsservice/setup.py]
18-
1916
[bumpversion:file:mssqlscripter/__init__.py]
2017

21-
[bumpversion:file:mssqltoolsservice/mssqltoolsservice/__init__.py]
22-

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ ENV/
9393

9494
# sqltoolsservice binaries
9595
/mssqlscripter/sqltoolsservice/*
96-
/mssqltoolsservice/mssqltoolsservice/bin/*
96+
/mssqlscripter/mssqltoolsservice/bin/*
9797

9898

9999
# VSCode configuration

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
include LICENSE.txt
22
include README.rst
3+
include mssqlscripter/mssqltoolsservice/bin/*
4+
include mssqlscripter/mssqltoolsservice/bin/*/*

build.py

+111-60
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,53 @@
66
# --------------------------------------------------------------------------------------------
77

88
from __future__ import print_function
9+
from azure.storage.blob import BlockBlobService, ContentSettings
910
import os
10-
import re
1111
import sys
12-
import tempfile
1312
import utility
14-
from azure.storage.blob import BlockBlobService, ContentSettings
13+
import mssqlscripter.mssqltoolsservice.external as mssqltoolsservice
1514

1615
AZURE_STORAGE_CONNECTION_STRING = os.environ.get('AZURE_STORAGE_CONNECTION_STRING')
1716
BLOB_CONTAINER_NAME = 'simple'
18-
UPLOADED_PACKAGE_LINKS = []
17+
UPLOADED_PACKAGE_LINKS = []
1918

2019

2120
def print_heading(heading, f=None):
2221
print('{0}\n{1}\n{0}'.format('=' * len(heading), heading), file=f)
2322

2423

25-
def upload_index_file(service, blob_name, title, links):
24+
def build(platform_names):
25+
"""
26+
Builds mssql-scripter package.
27+
"""
28+
print_heading('Cleanup')
29+
30+
# clean
31+
utility.clean_up(utility.MSSQLSCRIPTER_DIST_DIRECTORY)
32+
utility.cleaun_up_egg_info_sub_directories(utility.ROOT_DIR)
33+
34+
print_heading('Running setup')
35+
36+
# install general requirements.
37+
utility.exec_command('pip install -r dev_requirements.txt', utility.ROOT_DIR)
38+
39+
# convert windows line endings to unix for mssql-cli bash script
40+
utility.exec_command('python dos2unix.py mssql-scripter mssql-scripter', utility.ROOT_DIR)
41+
42+
for platform in platform_names:
43+
mssqltoolsservice.copy_sqltoolsservice(platform)
44+
45+
print_heading('Building mssql-scripter {} wheel package package'.format(platform))
46+
utility.exec_command('python --version', utility.ROOT_DIR)
47+
utility.exec_command(
48+
'python setup.py check -r -s bdist_wheel --plat-name {}'.format(platform),
49+
utility.ROOT_DIR,
50+
continue_on_error=False)
51+
52+
mssqltoolsservice.clean_up_sqltoolsservice()
53+
54+
55+
def _upload_index_file(service, blob_name, title, links):
2656
print('Uploading index file {}'.format(blob_name))
2757
service.create_blob_from_text(
2858
container_name=BLOB_CONTAINER_NAME,
@@ -37,23 +67,23 @@ def upload_index_file(service, blob_name, title, links):
3767
content_language=None,
3868
content_md5=None,
3969
cache_control=None
40-
)
70+
)
4171
)
4272

4373

44-
def gen_pkg_index_html(service, pkg_name):
74+
def _gen_pkg_index_html(service, pkg_name):
4575
links = []
4676
index_file_name = pkg_name+'/'
4777
for blob in list(service.list_blobs(BLOB_CONTAINER_NAME, prefix=index_file_name)):
4878
if blob.name == index_file_name:
4979
# Exclude the index file from being added to the list
5080
continue
5181
links.append(blob.name.replace(index_file_name, ''))
52-
upload_index_file(service, index_file_name, 'Links for {}'.format(pkg_name), links)
82+
_upload_index_file(service, index_file_name, 'Links for {}'.format(pkg_name), links)
5383
UPLOADED_PACKAGE_LINKS.append(index_file_name)
5484

5585

56-
def upload_package(service, file_path, pkg_name):
86+
def _upload_package(service, file_path, pkg_name):
5787
print('Uploading {}'.format(file_path))
5888
file_name = os.path.basename(file_path)
5989
blob_name = '{}/{}'.format(pkg_name, file_name)
@@ -62,63 +92,84 @@ def upload_package(service, file_path, pkg_name):
6292
blob_name=blob_name,
6393
file_path=file_path
6494
)
65-
gen_pkg_index_html(service, pkg_name)
66-
6795

68-
def build(options):
6996

70-
supported_actions = ['nightly']
71-
action = None
97+
def validate_package(platform_names):
98+
"""
99+
Install mssql-scripter wheel package locally.
100+
"""
101+
root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))
102+
# Local install of mssql-scripter.
103+
mssqlscripter_wheel_dir = os.listdir(utility.MSSQLSCRIPTER_DIST_DIRECTORY)
104+
current_platform = utility.get_current_platform()
72105

73-
if len(options) >= 1:
74-
if options[0] not in supported_actions:
75-
print('Please provide a supported action {}.'.format(supported_actions))
76-
return
77-
action = options[0]
106+
mssqlscripter_wheel_name = [pkge for pkge in mssqlscripter_wheel_dir if current_platform in pkge]
78107

79-
if action == 'nightly':
80-
assert AZURE_STORAGE_CONNECTION_STRING, 'Set AZURE_STORAGE_CONNECTION_STRING environment variable'
81-
82-
print_heading('Cleanup')
83-
84-
# clean
85-
utility.clean_up(utility.MSSQLSCRIPTER_DIST_DIRECTORY)
86-
utility.clean_up(utility.MSSQLTOOLSSERVICE_DIST_DIRECTORY)
87-
utility.cleaun_up_egg_info_sub_directories(utility.ROOT_DIR)
88-
utility.cleaun_up_egg_info_sub_directories(utility.MSSQLTOOLSSERVICE_DIRECTORY)
89-
90-
print_heading('Running setup')
91-
92-
# install general requirements.
93-
utility.exec_command('pip install -r dev_requirements.txt', utility.ROOT_DIR)
94-
95-
print_heading('Running mssql-scripter tests')
96-
utility.exec_command('tox', utility.ROOT_DIR, continue_on_error = False)
108+
# To ensure we have a clean install, we disable the cache as to prevent cache overshadowing actual changes made.
109+
utility.exec_command(
110+
'pip install --no-cache-dir --no-index ./dist/{}'.format(mssqlscripter_wheel_name),
111+
root_dir, continue_on_error=False)
97112

98-
print_heading('Building mssql-scripter pip package')
99-
utility.exec_command('python setup.py check -r -s sdist', utility.ROOT_DIR, continue_on_error = False)
100-
101-
print_heading('Building mssqltoolsservice pip package')
102-
utility.exec_command('python buildwheels.py', utility.MSSQLTOOLSSERVICE_DIRECTORY, continue_on_error = False)
103113

104-
if action == 'nightly':
105-
blob_service = BlockBlobService(connection_string=AZURE_STORAGE_CONNECTION_STRING)
106-
107-
print_heading('Uploading packages to blob storage ')
108-
for pkg in os.listdir(utility.MSSQLSCRIPTER_DIST_DIRECTORY):
109-
pkg_path = os.path.join(utility.MSSQLSCRIPTER_DIST_DIRECTORY, pkg)
110-
print('Uploading package {}'.format(pkg_path))
111-
upload_package(blob_service, pkg_path, 'mssql-scripter')
112-
113-
for pkg in os.listdir(utility.MSSQLTOOLSSERVICE_DIST_DIRECTORY):
114-
pkg_path = os.path.join(utility.MSSQLTOOLSSERVICE_DIST_DIRECTORY, pkg)
115-
pkg_name = os.path.basename(pkg_path).split('-')[0].replace('_', '-').lower()
116-
print('Uploading package {}'.format(pkg_name))
117-
upload_package(blob_service, pkg_path, pkg_name)
118-
119-
# Upload the final index file
120-
upload_index_file(blob_service, 'index.html', 'Simple Index', UPLOADED_PACKAGE_LINKS)
114+
def publish_daily(platforms_names):
115+
"""
116+
Publish mssql-scripter wheel package to daily storage account.
117+
"""
118+
print('Publishing to simple container within storage account.')
119+
assert AZURE_STORAGE_CONNECTION_STRING, 'Set AZURE_STORAGE_CONNECTION_STRING environment variable'
120+
121+
blob_service = BlockBlobService(connection_string=AZURE_STORAGE_CONNECTION_STRING)
122+
123+
print_heading('Uploading packages to blob storage ')
124+
for pkg in os.listdir(utility.MSSQLSCRIPTER_DIST_DIRECTORY):
125+
pkg_path = os.path.join(utility.MSSQLSCRIPTER_DIST_DIRECTORY, pkg)
126+
print('Uploading package {}'.format(pkg_path))
127+
_upload_package(blob_service, pkg_path, 'mssql-scripter')
128+
129+
# Upload index files
130+
_gen_pkg_index_html(blob_service, 'mssql-scripter')
131+
_upload_index_file(blob_service, 'index.html', 'Simple Index', UPLOADED_PACKAGE_LINKS)
132+
133+
134+
def publish_official(platforms_names):
135+
"""
136+
Publish mssql-scripter wheel package to PyPi.
137+
"""
138+
mssqlscripter_wheel_dir = os.listdir(utility.MSSQLSCRIPTER_DIST_DIRECTORY)
139+
# Run twine action for mssqlscripter.
140+
# Only authorized users with credentials will be able to upload this package.
141+
# Credentials will be stored in a .pypirc file.
142+
for mssqlscripter_wheel_name in mssqlscripter_wheel_dir:
143+
utility.exec_command(
144+
'twine upload {} pypi'.format(mssqlscripter_wheel_name),
145+
utility.MSSQLSCRIPTER_DIST_DIRECTORY)
121146

122147

123148
if __name__ == '__main__':
124-
build(sys.argv[1:])
149+
action = 'build'
150+
supported_platforms = [
151+
'win32',
152+
'win_amd64',
153+
'win64',
154+
'macosx_10_11_intel',
155+
'manylinux1_x86_64',
156+
'manylinux1_i686']
157+
158+
targets = {
159+
'build': build,
160+
'validate_package': validate_package,
161+
'publish_daily': publish_daily,
162+
'publish_official': publish_official
163+
}
164+
165+
if len(sys.argv) > 1:
166+
action = sys.argv[1]
167+
168+
if len(sys.argv) > 2:
169+
supported_platforms = [sys.argv[2]]
170+
171+
if action in targets:
172+
targets[action](supported_platforms)
173+
else:
174+
print('{} is not a supported action'.format(action))
175+
print('Supported actions are {}'.format(list(targets.keys())))

dev_setup.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@
99
from __future__ import print_function
1010

1111
import os
12-
import setup
12+
import platform
1313
import utility
14+
import mssqlscripter.mssqltoolsservice.external as mssqltoolsservice
1415

1516
print('Running dev setup...')
1617
print('Root directory \'{}\'\n'.format(utility.ROOT_DIR))
1718

1819
# install general requirements.
1920
utility.exec_command('pip install -r dev_requirements.txt', utility.ROOT_DIR)
21+
run_time_id = utility.get_current_platform()
22+
23+
if run_time_id:
24+
mssqltoolsservice.copy_sqltoolsservice(run_time_id)
25+
else:
26+
print("This platform does not support mssqltoolsservice.")
2027

21-
# install mssqltoolsservice if this platform supports it.
22-
mssqltoolsservice_package_name = os.environ['MSSQLTOOLSSERVICE_PACKAGE_NAME']
23-
print('Installing {}...'.format(mssqltoolsservice_package_name))
24-
# mssqltoolsservice package name is retrieved from environment variable set by setup.py.
25-
utility.exec_command('pip install {}'.format(mssqltoolsservice_package_name), utility.ROOT_DIR)
2628

2729
print('Finished dev setup.')

doc/pypi_release_steps.md

+11-23
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,25 @@ bumpversion release_version  -> 1.0.0a<b>1</b>
4040
##### Windows
4141
```
4242
rmdir /s dist
43-
rmdir /s mssqltoolsservice\dist
4443
```
4544
4645
##### OSX/Ubuntu (bash)
4746
```
4847
rm -rf dist
49-
rm -rf mssqltoolsservice/dist
5048
```
51-
2. Build mssql-scripter source distribution and verify readme.rst, From `<clone_root>` execute:
49+
2. Build mssql-scripter platform wheels and verify readme.rst, From `<clone_root>` execute:
5250
```
53-
python setup.py check -r -s sdist
51+
python build.py
5452
```
55-
56-
3. Build mssqltoolsservice wheels for each supported platform, From `<clone_root>/mssqltoolsservice` execute:
57-
```
58-
python buildwheels.py
59-
```
60-
61-
Build a OS-Specific wheel:
53+
54+
Build a OS-Specific wheel:
6255
```
63-
python buildwheels.py CentOS_7
64-
python buildwheels.py Debian_8
65-
python buildwheels.py Fedora_23
66-
python buildwheels.py openSUSE_13_2
67-
python buildwheels.py OSX_10_11_64
68-
python buildwheels.py RHEL_7
69-
python buildwheels.py Ubuntu_14
70-
python buildwheels.py Ubuntu_16
71-
python buildwheels.py Windows_7_64
72-
python buildwheels.py Windows_7_86
56+
python build.py build win32
57+
python build.py build win_amd64
58+
python build.py build macosx_10_11_intel
59+
python build.py build manylinux1_x86_64
7360
```
61+
7462
4. Add a .pypirc configuration file:
7563
7664
- Create a .pypirc file in your user directory:
@@ -97,9 +85,9 @@ bumpversion release_version  -> 1.0.0a<b>1</b>
9785
9886
5. Test install locally
9987
100-
To install the local mssql-scripter pip package, from `<clone_root>` execute:
88+
To install the local mssql-scripter wheel package, from `<clone_root>` execute:
10189
```
102-
sudo pip install --no-index -i ./mssqltoolsservice/dist/* ./dist/mssql-scripter-1.0.0a1.tar.gz
90+
sudo pip install --no-index -i ./dist/mssql_scripter-1.0.0a1-py2.py3-none-win32.whl
10391
```
10492
10593
6. Test install via pypi server:

dos2unix.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
"""\
3+
convert dos linefeeds (crlf) to unix (lf)
4+
usage: dos2unix.py <input> <output>
5+
"""
6+
7+
__version__ = "1" # version is needed for packaging
8+
9+
import sys
10+
11+
if len(sys.argv[1:]) != 2:
12+
sys.exit(__doc__)
13+
14+
content = ''
15+
outsize = 0
16+
with open(sys.argv[1], 'rb') as infile:
17+
content = infile.read()
18+
with open(sys.argv[2], 'wb') as output:
19+
for line in content.splitlines():
20+
outsize += len(line) + 1
21+
output.write(line + b'\n')
22+
23+
print("Done. Stripped %s bytes." % (len(content)-outsize))

mssqlscripter/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# --------------------------------------------------------------------------------------------
55

66

7-
__version__ = '1.0.0a21'
7+
__version__ = '1.0.0a22'

mssqlscripter/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import mssqlscripter.argparser as parser
1919
import mssqlscripter.scriptercallbacks as scriptercallbacks
2020
import mssqlscripter.sqltoolsclient as sqltoolsclient
21-
import mssqltoolsservice
21+
import mssqlscripter.mssqltoolsservice as mssqltoolsservice
2222

2323
logger = logging.getLogger(u'mssqlscripter.main')
2424

0 commit comments

Comments
 (0)