diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 2337663..b247e38 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,6 +1,5 @@ [bumpversion] -current_version = 1.0.0a21 - +current_version = 1.0.0a22 parse = (?P\d+)\.(?P\d+)\.(?P\d+)((?P[a-z]+))(?P\d+) serialize = {major}.{minor}.{patch}{release}{release_version} @@ -14,9 +13,5 @@ values = [bumpversion:file:setup.py] -[bumpversion:file:mssqltoolsservice/setup.py] - [bumpversion:file:mssqlscripter/__init__.py] -[bumpversion:file:mssqltoolsservice/mssqltoolsservice/__init__.py] - diff --git a/.gitignore b/.gitignore index c8a26f3..2f57025 100644 --- a/.gitignore +++ b/.gitignore @@ -93,7 +93,7 @@ ENV/ # sqltoolsservice binaries /mssqlscripter/sqltoolsservice/* -/mssqltoolsservice/mssqltoolsservice/bin/* +/mssqlscripter/mssqltoolsservice/bin/* # VSCode configuration diff --git a/MANIFEST.in b/MANIFEST.in index 97e2ad3..4c177e5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,4 @@ include LICENSE.txt include README.rst +include mssqlscripter/mssqltoolsservice/bin/* +include mssqlscripter/mssqltoolsservice/bin/*/* \ No newline at end of file diff --git a/build.py b/build.py index a03e814..36afc41 100644 --- a/build.py +++ b/build.py @@ -6,23 +6,53 @@ # -------------------------------------------------------------------------------------------- from __future__ import print_function +from azure.storage.blob import BlockBlobService, ContentSettings import os -import re import sys -import tempfile import utility -from azure.storage.blob import BlockBlobService, ContentSettings +import mssqlscripter.mssqltoolsservice.external as mssqltoolsservice AZURE_STORAGE_CONNECTION_STRING = os.environ.get('AZURE_STORAGE_CONNECTION_STRING') BLOB_CONTAINER_NAME = 'simple' -UPLOADED_PACKAGE_LINKS = [] +UPLOADED_PACKAGE_LINKS = [] def print_heading(heading, f=None): print('{0}\n{1}\n{0}'.format('=' * len(heading), heading), file=f) -def upload_index_file(service, blob_name, title, links): +def build(platform_names): + """ + Builds mssql-scripter package. + """ + print_heading('Cleanup') + + # clean + utility.clean_up(utility.MSSQLSCRIPTER_DIST_DIRECTORY) + utility.cleaun_up_egg_info_sub_directories(utility.ROOT_DIR) + + print_heading('Running setup') + + # install general requirements. + utility.exec_command('pip install -r dev_requirements.txt', utility.ROOT_DIR) + + # convert windows line endings to unix for mssql-cli bash script + utility.exec_command('python dos2unix.py mssql-scripter mssql-scripter', utility.ROOT_DIR) + + for platform in platform_names: + mssqltoolsservice.copy_sqltoolsservice(platform) + + print_heading('Building mssql-scripter {} wheel package package'.format(platform)) + utility.exec_command('python --version', utility.ROOT_DIR) + utility.exec_command( + 'python setup.py check -r -s bdist_wheel --plat-name {}'.format(platform), + utility.ROOT_DIR, + continue_on_error=False) + + mssqltoolsservice.clean_up_sqltoolsservice() + + +def _upload_index_file(service, blob_name, title, links): print('Uploading index file {}'.format(blob_name)) service.create_blob_from_text( container_name=BLOB_CONTAINER_NAME, @@ -37,11 +67,11 @@ def upload_index_file(service, blob_name, title, links): content_language=None, content_md5=None, cache_control=None - ) + ) ) -def gen_pkg_index_html(service, pkg_name): +def _gen_pkg_index_html(service, pkg_name): links = [] index_file_name = pkg_name+'/' for blob in list(service.list_blobs(BLOB_CONTAINER_NAME, prefix=index_file_name)): @@ -49,11 +79,11 @@ def gen_pkg_index_html(service, pkg_name): # Exclude the index file from being added to the list continue links.append(blob.name.replace(index_file_name, '')) - upload_index_file(service, index_file_name, 'Links for {}'.format(pkg_name), links) + _upload_index_file(service, index_file_name, 'Links for {}'.format(pkg_name), links) UPLOADED_PACKAGE_LINKS.append(index_file_name) -def upload_package(service, file_path, pkg_name): +def _upload_package(service, file_path, pkg_name): print('Uploading {}'.format(file_path)) file_name = os.path.basename(file_path) blob_name = '{}/{}'.format(pkg_name, file_name) @@ -62,63 +92,84 @@ def upload_package(service, file_path, pkg_name): blob_name=blob_name, file_path=file_path ) - gen_pkg_index_html(service, pkg_name) - -def build(options): - supported_actions = ['nightly'] - action = None +def validate_package(platform_names): + """ + Install mssql-scripter wheel package locally. + """ + root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) + # Local install of mssql-scripter. + mssqlscripter_wheel_dir = os.listdir(utility.MSSQLSCRIPTER_DIST_DIRECTORY) + current_platform = utility.get_current_platform() - if len(options) >= 1: - if options[0] not in supported_actions: - print('Please provide a supported action {}.'.format(supported_actions)) - return - action = options[0] + mssqlscripter_wheel_name = [pkge for pkge in mssqlscripter_wheel_dir if current_platform in pkge] - if action == 'nightly': - assert AZURE_STORAGE_CONNECTION_STRING, 'Set AZURE_STORAGE_CONNECTION_STRING environment variable' - - print_heading('Cleanup') - - # clean - utility.clean_up(utility.MSSQLSCRIPTER_DIST_DIRECTORY) - utility.clean_up(utility.MSSQLTOOLSSERVICE_DIST_DIRECTORY) - utility.cleaun_up_egg_info_sub_directories(utility.ROOT_DIR) - utility.cleaun_up_egg_info_sub_directories(utility.MSSQLTOOLSSERVICE_DIRECTORY) - - print_heading('Running setup') - - # install general requirements. - utility.exec_command('pip install -r dev_requirements.txt', utility.ROOT_DIR) - - print_heading('Running mssql-scripter tests') - utility.exec_command('tox', utility.ROOT_DIR, continue_on_error = False) + # To ensure we have a clean install, we disable the cache as to prevent cache overshadowing actual changes made. + utility.exec_command( + 'pip install --no-cache-dir --no-index ./dist/{}'.format(mssqlscripter_wheel_name), + root_dir, continue_on_error=False) - print_heading('Building mssql-scripter pip package') - utility.exec_command('python setup.py check -r -s sdist', utility.ROOT_DIR, continue_on_error = False) - - print_heading('Building mssqltoolsservice pip package') - utility.exec_command('python buildwheels.py', utility.MSSQLTOOLSSERVICE_DIRECTORY, continue_on_error = False) - if action == 'nightly': - blob_service = BlockBlobService(connection_string=AZURE_STORAGE_CONNECTION_STRING) - - print_heading('Uploading packages to blob storage ') - for pkg in os.listdir(utility.MSSQLSCRIPTER_DIST_DIRECTORY): - pkg_path = os.path.join(utility.MSSQLSCRIPTER_DIST_DIRECTORY, pkg) - print('Uploading package {}'.format(pkg_path)) - upload_package(blob_service, pkg_path, 'mssql-scripter') - - for pkg in os.listdir(utility.MSSQLTOOLSSERVICE_DIST_DIRECTORY): - pkg_path = os.path.join(utility.MSSQLTOOLSSERVICE_DIST_DIRECTORY, pkg) - pkg_name = os.path.basename(pkg_path).split('-')[0].replace('_', '-').lower() - print('Uploading package {}'.format(pkg_name)) - upload_package(blob_service, pkg_path, pkg_name) - - # Upload the final index file - upload_index_file(blob_service, 'index.html', 'Simple Index', UPLOADED_PACKAGE_LINKS) +def publish_daily(platforms_names): + """ + Publish mssql-scripter wheel package to daily storage account. + """ + print('Publishing to simple container within storage account.') + assert AZURE_STORAGE_CONNECTION_STRING, 'Set AZURE_STORAGE_CONNECTION_STRING environment variable' + + blob_service = BlockBlobService(connection_string=AZURE_STORAGE_CONNECTION_STRING) + + print_heading('Uploading packages to blob storage ') + for pkg in os.listdir(utility.MSSQLSCRIPTER_DIST_DIRECTORY): + pkg_path = os.path.join(utility.MSSQLSCRIPTER_DIST_DIRECTORY, pkg) + print('Uploading package {}'.format(pkg_path)) + _upload_package(blob_service, pkg_path, 'mssql-scripter') + + # Upload index files + _gen_pkg_index_html(blob_service, 'mssql-scripter') + _upload_index_file(blob_service, 'index.html', 'Simple Index', UPLOADED_PACKAGE_LINKS) + + +def publish_official(platforms_names): + """ + Publish mssql-scripter wheel package to PyPi. + """ + mssqlscripter_wheel_dir = os.listdir(utility.MSSQLSCRIPTER_DIST_DIRECTORY) + # Run twine action for mssqlscripter. + # Only authorized users with credentials will be able to upload this package. + # Credentials will be stored in a .pypirc file. + for mssqlscripter_wheel_name in mssqlscripter_wheel_dir: + utility.exec_command( + 'twine upload {} pypi'.format(mssqlscripter_wheel_name), + utility.MSSQLSCRIPTER_DIST_DIRECTORY) if __name__ == '__main__': - build(sys.argv[1:]) \ No newline at end of file + action = 'build' + supported_platforms = [ + 'win32', + 'win_amd64', + 'win64', + 'macosx_10_11_intel', + 'manylinux1_x86_64', + 'manylinux1_i686'] + + targets = { + 'build': build, + 'validate_package': validate_package, + 'publish_daily': publish_daily, + 'publish_official': publish_official + } + + if len(sys.argv) > 1: + action = sys.argv[1] + + if len(sys.argv) > 2: + supported_platforms = [sys.argv[2]] + + if action in targets: + targets[action](supported_platforms) + else: + print('{} is not a supported action'.format(action)) + print('Supported actions are {}'.format(list(targets.keys()))) diff --git a/dev_setup.py b/dev_setup.py index ebbaccb..d22ecf9 100644 --- a/dev_setup.py +++ b/dev_setup.py @@ -9,19 +9,21 @@ from __future__ import print_function import os -import setup +import platform import utility +import mssqlscripter.mssqltoolsservice.external as mssqltoolsservice print('Running dev setup...') print('Root directory \'{}\'\n'.format(utility.ROOT_DIR)) # install general requirements. utility.exec_command('pip install -r dev_requirements.txt', utility.ROOT_DIR) +run_time_id = utility.get_current_platform() + +if run_time_id: + mssqltoolsservice.copy_sqltoolsservice(run_time_id) +else: + print("This platform does not support mssqltoolsservice.") -# install mssqltoolsservice if this platform supports it. -mssqltoolsservice_package_name = os.environ['MSSQLTOOLSSERVICE_PACKAGE_NAME'] -print('Installing {}...'.format(mssqltoolsservice_package_name)) -# mssqltoolsservice package name is retrieved from environment variable set by setup.py. -utility.exec_command('pip install {}'.format(mssqltoolsservice_package_name), utility.ROOT_DIR) print('Finished dev setup.') diff --git a/doc/pypi_release_steps.md b/doc/pypi_release_steps.md index 655dc18..39fb03b 100644 --- a/doc/pypi_release_steps.md +++ b/doc/pypi_release_steps.md @@ -40,37 +40,25 @@ bumpversion release_version  -> 1.0.0a1 ##### Windows ``` rmdir /s dist - rmdir /s mssqltoolsservice\dist ``` ##### OSX/Ubuntu (bash) ``` rm -rf dist - rm -rf mssqltoolsservice/dist ``` -2. Build mssql-scripter source distribution and verify readme.rst, From `` execute: +2. Build mssql-scripter platform wheels and verify readme.rst, From `` execute: ``` - python setup.py check -r -s sdist + python build.py ``` - -3. Build mssqltoolsservice wheels for each supported platform, From `/mssqltoolsservice` execute: - ``` - python buildwheels.py - ``` - - Build a OS-Specific wheel: + + Build a OS-Specific wheel: ``` - python buildwheels.py CentOS_7 - python buildwheels.py Debian_8 - python buildwheels.py Fedora_23 - python buildwheels.py openSUSE_13_2 - python buildwheels.py OSX_10_11_64 - python buildwheels.py RHEL_7 - python buildwheels.py Ubuntu_14 - python buildwheels.py Ubuntu_16 - python buildwheels.py Windows_7_64 - python buildwheels.py Windows_7_86 + python build.py build win32 + python build.py build win_amd64 + python build.py build macosx_10_11_intel + python build.py build manylinux1_x86_64 ``` + 4. Add a .pypirc configuration file: - Create a .pypirc file in your user directory: @@ -97,9 +85,9 @@ bumpversion release_version  -> 1.0.0a1 5. Test install locally - To install the local mssql-scripter pip package, from `` execute: + To install the local mssql-scripter wheel package, from `` execute: ``` - sudo pip install --no-index -i ./mssqltoolsservice/dist/* ./dist/mssql-scripter-1.0.0a1.tar.gz + sudo pip install --no-index -i ./dist/mssql_scripter-1.0.0a1-py2.py3-none-win32.whl ``` 6. Test install via pypi server: diff --git a/dos2unix.py b/dos2unix.py new file mode 100644 index 0000000..9feff85 --- /dev/null +++ b/dos2unix.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +"""\ +convert dos linefeeds (crlf) to unix (lf) +usage: dos2unix.py +""" + +__version__ = "1" # version is needed for packaging + +import sys + +if len(sys.argv[1:]) != 2: + sys.exit(__doc__) + +content = '' +outsize = 0 +with open(sys.argv[1], 'rb') as infile: + content = infile.read() +with open(sys.argv[2], 'wb') as output: + for line in content.splitlines(): + outsize += len(line) + 1 + output.write(line + b'\n') + +print("Done. Stripped %s bytes." % (len(content)-outsize)) \ No newline at end of file diff --git a/mssqlscripter/__init__.py b/mssqlscripter/__init__.py index 7446743..cdc2fbf 100644 --- a/mssqlscripter/__init__.py +++ b/mssqlscripter/__init__.py @@ -4,4 +4,4 @@ # -------------------------------------------------------------------------------------------- -__version__ = '1.0.0a21' +__version__ = '1.0.0a22' diff --git a/mssqlscripter/main.py b/mssqlscripter/main.py index bd3d1d2..593c1f4 100644 --- a/mssqlscripter/main.py +++ b/mssqlscripter/main.py @@ -18,7 +18,7 @@ import mssqlscripter.argparser as parser import mssqlscripter.scriptercallbacks as scriptercallbacks import mssqlscripter.sqltoolsclient as sqltoolsclient -import mssqltoolsservice +import mssqlscripter.mssqltoolsservice as mssqltoolsservice logger = logging.getLogger(u'mssqlscripter.main') diff --git a/mssqltoolsservice/mssqltoolsservice/__init__.py b/mssqlscripter/mssqltoolsservice/__init__.py similarity index 94% rename from mssqltoolsservice/mssqltoolsservice/__init__.py rename to mssqlscripter/mssqltoolsservice/__init__.py index 29775e2..faf2925 100644 --- a/mssqltoolsservice/mssqltoolsservice/__init__.py +++ b/mssqlscripter/mssqltoolsservice/__init__.py @@ -10,9 +10,6 @@ import platform -__version__ = '1.0.0a21' - - def get_executable_path(): """ Find mssqltoolsservice executable relative to this package. @@ -34,7 +31,7 @@ def get_executable_path(): mssqltoolsservice_full_path = os.path.abspath(os.path.join(mssqltoolsservice_base_path, mssqltoolsservice_name)) - if (not os.path.exists(mssqltoolsservice_full_path)): + if not os.path.exists(mssqltoolsservice_full_path): error_message = '{} does not exist. Please re-install the mssql-scripter package'.format(mssqltoolsservice_full_path) raise EnvironmentError(error_message) diff --git a/mssqlscripter/mssqltoolsservice/external.py b/mssqlscripter/mssqltoolsservice/external.py new file mode 100644 index 0000000..7565f76 --- /dev/null +++ b/mssqlscripter/mssqltoolsservice/external.py @@ -0,0 +1,61 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- +from __future__ import print_function + +import os +import sys +import tarfile +import utility +import zipfile + +from future.standard_library import install_aliases +install_aliases() + + +SQLTOOLSSERVICE_BASE = os.path.join(utility.ROOT_DIR, 'sqltoolsservice/') + +# Supported platform key's must match those in mssqlscript's setup.py. +SUPPORTED_PLATFORMS = { + 'manylinux1_x86_64': SQLTOOLSSERVICE_BASE + 'manylinux1/' + 'Microsoft.SqlTools.ServiceLayer-linux-x64-netcoreapp2.0.tar.gz', + 'manylinux1_i686': SQLTOOLSSERVICE_BASE + 'manylinux1/' + 'Microsoft.SqlTools.ServiceLayer-linux-x64-netcoreapp2.0.tar.gz', + 'macosx_10_11_intel': SQLTOOLSSERVICE_BASE + 'macosx_10_11_intel/' + 'Microsoft.SqlTools.ServiceLayer-osx-x64-netcoreapp2.0.tar.gz', + 'win_amd64': SQLTOOLSSERVICE_BASE + 'win64/' + 'Microsoft.SqlTools.ServiceLayer-win-x64-netcoreapp2.0.zip', + 'win_64': SQLTOOLSSERVICE_BASE + 'win64/' + 'Microsoft.SqlTools.ServiceLayer-win-x64-netcoreapp2.0.zip', + 'win32': SQLTOOLSSERVICE_BASE + 'win32/' + 'Microsoft.SqlTools.ServiceLayer-win-x86-netcoreapp2.0.zip' +} + +TARGET_DIRECTORY = os.path.abspath(os.path.join(os.path.abspath(__file__), '..', 'bin')) + + +def copy_sqltoolsservice(platform): + """ + For each supported platform, build a universal wheel. + """ + # Clean up dangling directories if previous run was interrupted. + utility.clean_up(directory=TARGET_DIRECTORY) + + if not platform or platform not in SUPPORTED_PLATFORMS: + print('Please provide a valid platform flag.' + + '[win32, win_amd64, win64, manylinux1_x86_64, manylinux1_i686, macosx_10_11_intel]') + sys.exit(1) + + copy_file_path = SUPPORTED_PLATFORMS[platform] + + print('Sqltoolsservice archive found at {}'.format(copy_file_path)) + if copy_file_path.endswith('tar.gz'): + compressed_file = tarfile.open(name=copy_file_path, mode='r:gz') + elif copy_file_path.endswith('.zip'): + compressed_file = zipfile.ZipFile(copy_file_path) + + if not os.path.exists(TARGET_DIRECTORY): + os.makedirs(TARGET_DIRECTORY) + + print(u'Bin placing sqltoolsservice for this platform: {}.'.format(platform)) + print(u'Extracting files from {}'.format(copy_file_path)) + compressed_file.extractall(TARGET_DIRECTORY) + + +def clean_up_sqltoolsservice(): + utility.clean_up(directory=TARGET_DIRECTORY) diff --git a/mssqltoolsservice/LICENSE.txt b/mssqltoolsservice/LICENSE.txt deleted file mode 100644 index 1f56e39..0000000 --- a/mssqltoolsservice/LICENSE.txt +++ /dev/null @@ -1,13 +0,0 @@ -Microsoft SQL Tools Service - -Copyright (c) Microsoft Corporation - -All rights reserved. - -MIT License - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/mssqltoolsservice/MANIFEST.in b/mssqltoolsservice/MANIFEST.in deleted file mode 100644 index 298e934..0000000 --- a/mssqltoolsservice/MANIFEST.in +++ /dev/null @@ -1,4 +0,0 @@ -include README.rst -include LICENSE.txt -include mssqltoolsservice/bin/* -include mssqltoolsservice/bin/*/* diff --git a/mssqltoolsservice/README.rst b/mssqltoolsservice/README.rst deleted file mode 100644 index a7a73ee..0000000 --- a/mssqltoolsservice/README.rst +++ /dev/null @@ -1,17 +0,0 @@ -mssqltoolsservice -================= - -The platform specific mssqltoolsservice package provides external -dependencies to the mssql-scripter tool. - -Installing this standalone package will not provide any functionality. -This package is not recommended to be installed directly via pip and -should only be handled via mssql-scripter’s install. - -Support is not provided to this package alone. - -`Microsoft SQL Tools Service GitHub repository`_ -`mssql-scripter GitHub repository`_ - -.. _Microsoft SQL Tools Service GitHub repository: https://github.com/Microsoft/sqltoolsservice -.. _mssql-scripter GitHub repository: https://github.com/Microsoft/mssql-scripter \ No newline at end of file diff --git a/mssqltoolsservice/buildwheels.py b/mssqltoolsservice/buildwheels.py deleted file mode 100644 index 58e1d66..0000000 --- a/mssqltoolsservice/buildwheels.py +++ /dev/null @@ -1,86 +0,0 @@ -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- -from __future__ import print_function - -import io -import os -import requests -import sys -import tarfile -import utility -import zipfile - -from future.standard_library import install_aliases -install_aliases() -from urllib.request import urlopen - - -DOWNLOAD_URL_BASE = 'https://mssqlscripter.blob.core.windows.net/sqltoolsservice-10-12-2017/' - -# Supported platform key's must match those in mssqlscript's setup.py. -SUPPORTED_PLATFORMS = { - 'Linux_64': DOWNLOAD_URL_BASE + 'Microsoft.SqlTools.ServiceLayer-linux-x64-netcoreapp2.0.tar.gz', - 'OSX_10_11_64': DOWNLOAD_URL_BASE + 'Microsoft.SqlTools.ServiceLayer-osx-x64-netcoreapp2.0.tar.gz', - 'Windows_7_64': DOWNLOAD_URL_BASE + 'Microsoft.SqlTools.ServiceLayer-win-x64-netcoreapp2.0.zip', - 'Windows_7_86': DOWNLOAD_URL_BASE + 'Microsoft.SqlTools.ServiceLayer-win-x86-netcoreapp2.0.zip' -} - - -CURRENT_DIRECTORY = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) -BUILD_DIRECTORY = os.path.abspath(os.path.join(CURRENT_DIRECTORY, 'build')) -TARGET_DIRECTORY = os.path.abspath(os.path.join(os.path.abspath(__file__), '..', 'mssqltoolsservice', 'bin')) - - -def download_and_unzip(download_file_path, directory): - """ - Download and unzip files to the target directory. - """ - # Download and unzip each file. - if download_file_path.endswith('tar.gz'): - response = urlopen(download_file_path) - compressed_file = tarfile.open(mode='r|gz', fileobj=response) - elif download_file_path.endswith('.zip'): - response = response = requests.get(download_file_path) - compressed_file = zipfile.ZipFile(io.BytesIO(response.content)) - - if not os.path.exists(directory): - os.makedirs(directory) - - print(u'Extracting files from {}'.format(download_file_path)) - compressed_file.extractall(directory) - - -def build_sqltoolsservice_wheels(platforms): - """ - For each supported platform, build a universal wheel. - """ - # Clean up dangling directories if previous run was interrupted. - utility.clean_up(directory=TARGET_DIRECTORY) - utility.clean_up(directory=BUILD_DIRECTORY) - - if not platforms: - # Defaults to all supported platforms. - platforms = SUPPORTED_PLATFORMS.keys() - - print(u'Generating .whl files for the following platforms: {}'.format(platforms)) - for platform in platforms: - if platform not in SUPPORTED_PLATFORMS: - print(u'{} is not a supported platform'.format(platform)) - break - # Set environment variable to communicate current platform to setup.py. - os.environ[u'MSSQLTOOLSSERVICE_PLATFORM'] = platform - - print(u'Calling setup bdist_wheel for platform:{}'.format(platform)) - print(SUPPORTED_PLATFORMS[platform]) - download_and_unzip(SUPPORTED_PLATFORMS[platform], directory=TARGET_DIRECTORY) - utility.exec_command(u'python setup.py check -r -s bdist_wheel', CURRENT_DIRECTORY) - - print(u'Cleaning up mssqltoolservice and build directory for platform:{}'.format(platform)) - utility.clean_up(directory=TARGET_DIRECTORY) - utility.clean_up(directory=BUILD_DIRECTORY) - - -if __name__ == '__main__': - build_sqltoolsservice_wheels(sys.argv[1:]) diff --git a/mssqltoolsservice/setup.cfg b/mssqltoolsservice/setup.cfg deleted file mode 100644 index 1d40481..0000000 --- a/mssqltoolsservice/setup.cfg +++ /dev/null @@ -1,11 +0,0 @@ -[metadata] -description-file = README.rst -license_file = LICENSE.txt - -[bdist_wheel] -universal=1 - -[flake8] -ignore= - # E501: line too long. - E501 diff --git a/mssqltoolsservice/setup.py b/mssqltoolsservice/setup.py deleted file mode 100644 index eb8b347..0000000 --- a/mssqltoolsservice/setup.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python - -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- - -from setuptools import setup -import io -import os -import sys - -# This version number is in place in two places and must be in sync with -# mssqlscripter's version in setup.py. - -MSSQLTOOLSSERVICE_VERSION = '1.0.0a21' - - -# If we have source, validate version numbers match to prevent -# uploading releases with mismatched versions. -try: - with io.open('mssqltoolsservice/__init__.py', 'r', encoding='utf-8') as f: - content = f.read() -except IOError: - pass -else: - import re - # use regex to look for version. - m = re.search(r'__version__\s*=\s*[\'"](.+?)[\'"]', content) - if not m: - print('Could not find __version__ in mssqltoolsservice/__init__.py') - sys.exit(1) - if m.group(1) != MSSQLTOOLSSERVICE_VERSION: - print( - 'mssqltoolsservice mismatch source = "{}"; setup = "{}"'.format( - m.group(1), - MSSQLTOOLSSERVICE_VERSION)) - sys.exit(1) - - -# Find the platform we are building against. -# This file should not be called directly. -PLATFORM = os.environ['MSSQLTOOLSSERVICE_PLATFORM'] - -CLASSIFIERS = [ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Intended Audience :: System Administrators', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'License :: OSI Approved :: MIT License', -] - -setup( - name='mssqltoolsservice_{}'.format(PLATFORM), - version=MSSQLTOOLSSERVICE_VERSION, - description='Microsoft SQL Tools Service', - license='MIT', - author='Microsoft Corporation', - author_email='sqlxplatclieng@microsoft.com', - url='https://github.com/Microsoft/sqltoolsservice', - zip_safe=True, - long_description=open('README.rst').read(), - classifiers=CLASSIFIERS, - include_package_data=True, - packages=[ - 'mssqltoolsservice' - ], -) diff --git a/register_upload.py b/register_upload.py deleted file mode 100644 index 7ed6407..0000000 --- a/register_upload.py +++ /dev/null @@ -1,53 +0,0 @@ -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- - -import os -import sys -import utility - - -def register_or_upload_to_pypi(options): - """ - Registers or uploads against a pypi server. - """ - supported_actions = ['register', 'upload'] - - if len(options) >= 1 and options[0] not in supported_actions: - print('Please provide a supported action (register or upload).') - return - - action = options[0] - repository = '' - if len(options) == 2: - # We were provided a explicity repo to target. - # If we were not provided a repo nor does a .pypirc file exists, - # twine will use environment variable TWINE_REPOSITORY, TWINE_USERNAME, - # and TWINE_PASSWORD. - repository = '-r {}'.format(options[1]) - print( - 'Repository argument was provided, targeting {}'.format( - options[1])) - - mssqlscripter_sdist_name = os.listdir(utility.MSSQLSCRIPTER_DIST_DIRECTORY)[0] - # Run twine action for mssqlscripter. - utility.exec_command( - 'twine {} {} {}'.format( - action, - mssqlscripter_sdist_name, - repository), - utility.MSSQLSCRIPTER_DIST_DIRECTORY) - - for wheel_name in os.listdir(utility.MSSQLTOOLSSERVICE_DIST_DIRECTORY): - # Run twine action for mssqltoolsservice wheels. - utility.exec_command( - 'twine {} {} {}'.format( - action, - wheel_name, - repository), - utility.MSSQLTOOLSSERVICE_DIST_DIRECTORY) - - -if __name__ == '__main__': - register_or_upload_to_pypi(sys.argv[1:]) diff --git a/setup.cfg b/setup.cfg index b27f31d..fc79896 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,7 +20,7 @@ ignore = # forgoing the need for them to modify this file to ignore their venv directory. filename = ./mssqlscripter/*.py, - ./mssqltoolsservice/*.py, + ./mssqlscripter/mssqltoolsservice/*.py, ./dev_setup.py, ./setup.py, ./utility.py, diff --git a/setup.py b/setup.py index ed5c7c4..daa7f3b 100644 --- a/setup.py +++ b/setup.py @@ -12,96 +12,7 @@ from setuptools import setup -# This version number is in place in two places and must be in sync with -# mssqltoolsservice's version in setup.py. - -MSSQLSCRIPTER_VERSION = '1.0.0a21' - - -# If we have the source, validate our setup version matches source version. -# This will prevent uploading releases with mismatched versions. This will -# also ensure mssqlscripter's version is in sync with mssqltoolsservice. -try: - with io.open('mssqlscripter/__init__.py', 'r', encoding='utf-8') as f: - mssqlscripter_info = f.read() - with io.open('mssqltoolsservice/mssqltoolsservice/__init__.py', 'r', encoding='utf-8') as f: - mssqltoolsservice_info = f.read() -except IOError: - pass -else: - import re - # Use regex to parse for version. - scripter_version = re.search( - r'__version__\s*=\s*[\'"](.+?)[\'"]', - mssqlscripter_info) - toolsservice_version = re.search( - r'__version__\s*=\s*[\'"](.+?)[\'"]', - mssqltoolsservice_info) - - if not scripter_version: - print('Could not find __version__ in mssqlscripter/__init__.py') - sys.exit(1) - if not toolsservice_version: - print( - 'Could not find __version__ in mssqltoolsservice/mssqltoolsservice/__init__.py') - sys.exit(1) - # Validate mssqlscripter source and setup versions. - if scripter_version.group(1) != MSSQLSCRIPTER_VERSION: - print('mssqlscripter version mismatch, source = "{}"; setup = "{}"'.format( - scripter_version.group(1), MSSQLSCRIPTER_VERSION)) - sys.exit(1) - # Validate mssqlscripter version with mssqltoolsservice. - if scripter_version.group(1) != toolsservice_version.group(1): - print( - 'mssqltoolsservice version mismatch, mssqscripter = "{}"; mssqltoolsservice = "{}"'.format( - scripter_version.group(1), - toolsservice_version.group(1))) - sys.exit(1) - -MSSQLTOOLSSERVICE_PACKAGE_NAME = 'mssqltoolsservice-{}=={}' -MSSQLTOOLSSERVICE_PACKAGE_SUFFIX = [ - 'OSX_10_11_64', - 'Windows_7_64', - 'Windows_7_86', - 'Linux_64' -] - - -def _get_runtime_id( - system=_platform.system(), - architecture=_platform.architecture()[0], - version=_platform.version()): - """ - Find supported run time id for current platform. - """ - run_time_id = None - - if system == 'Windows': - if architecture == '32bit': - run_time_id = 'Windows_7_86' - elif architecture == '64bit': - run_time_id = 'Windows_7_64' - elif system == 'Darwin': - if architecture == '64bit': - run_time_id = 'OSX_10_11_64' - elif system == 'Linux': - if architecture == '64bit': - run_time_id = 'Linux_64' - - return run_time_id - - -def get_mssqltoolsservice_package_name(run_time_id=_get_runtime_id()): - """ - Retrieve sql tools service package name for this platform if supported. - """ - if run_time_id and run_time_id in MSSQLTOOLSSERVICE_PACKAGE_SUFFIX: - # set package suffix name for other uses like building wheels outside of setup.py. - os.environ['MSSQLTOOLSSERVICE_PACKAGE_SUFFIX'] = run_time_id - return MSSQLTOOLSSERVICE_PACKAGE_NAME.format( - run_time_id, MSSQLSCRIPTER_VERSION).replace('_', '-').lower() - - raise EnvironmentError('mssqltoolsservice is not supported on this platform.') +MSSQLSCRIPTER_VERSION = '1.0.0a22' CLASSIFIERS = [ @@ -126,12 +37,6 @@ def get_mssqltoolsservice_package_name(run_time_id=_get_runtime_id()): if sys.version_info < (3, 4): DEPENDENCIES.append('enum34>=1.1.6') -DEPENDENCIES.append(get_mssqltoolsservice_package_name()) - -# Using a environment variable to communicate mssqltoolsservice package name for -# other modules that need that info like dev_setup.py. -os.environ['MSSQLTOOLSSERVICE_PACKAGE_NAME'] = DEPENDENCIES[-1] - setup( install_requires=DEPENDENCIES, name='mssql-scripter', @@ -151,6 +56,7 @@ def get_mssqltoolsservice_package_name(run_time_id=_get_runtime_id()): ], packages=[ 'mssqlscripter', + 'mssqlscripter.mssqltoolsservice', 'mssqlscripter.jsonrpc', 'mssqlscripter.jsonrpc.contracts'], ) diff --git a/sqltoolsservice/macosx_10_11_intel/Microsoft.SqlTools.ServiceLayer-osx-x64-netcoreapp2.0.tar.gz b/sqltoolsservice/macosx_10_11_intel/Microsoft.SqlTools.ServiceLayer-osx-x64-netcoreapp2.0.tar.gz new file mode 100644 index 0000000..0e66118 Binary files /dev/null and b/sqltoolsservice/macosx_10_11_intel/Microsoft.SqlTools.ServiceLayer-osx-x64-netcoreapp2.0.tar.gz differ diff --git a/sqltoolsservice/manylinux1/Microsoft.SqlTools.ServiceLayer-linux-x64-netcoreapp2.0.tar.gz b/sqltoolsservice/manylinux1/Microsoft.SqlTools.ServiceLayer-linux-x64-netcoreapp2.0.tar.gz new file mode 100644 index 0000000..d5cc8b8 Binary files /dev/null and b/sqltoolsservice/manylinux1/Microsoft.SqlTools.ServiceLayer-linux-x64-netcoreapp2.0.tar.gz differ diff --git a/sqltoolsservice/win32/Microsoft.SqlTools.ServiceLayer-win-x86-netcoreapp2.0.zip b/sqltoolsservice/win32/Microsoft.SqlTools.ServiceLayer-win-x86-netcoreapp2.0.zip new file mode 100644 index 0000000..0fff9d9 Binary files /dev/null and b/sqltoolsservice/win32/Microsoft.SqlTools.ServiceLayer-win-x86-netcoreapp2.0.zip differ diff --git a/sqltoolsservice/win64/Microsoft.SqlTools.ServiceLayer-win-x64-netcoreapp2.0.zip b/sqltoolsservice/win64/Microsoft.SqlTools.ServiceLayer-win-x64-netcoreapp2.0.zip new file mode 100644 index 0000000..7bd04f4 Binary files /dev/null and b/sqltoolsservice/win64/Microsoft.SqlTools.ServiceLayer-win-x64-netcoreapp2.0.zip differ diff --git a/tox.ini b/tox.ini index 57e48f3..fba45fc 100644 --- a/tox.ini +++ b/tox.ini @@ -3,9 +3,7 @@ # won't fail the test run if only one is found. skip_missing_interpreters=True envlist = py27,py36 -# We will build the sdist ourselves as we need to detect -# what platform we are on and install the generated wheel -# locally. +# We will build the wheel ourselves dynamically. skipsdist=True [testenv] @@ -25,10 +23,7 @@ commands= # Run unit tests with code coverage. pytest --cov-report xml --cov mssqlscripter - # Verify readme.rst and build mssql-scripter sdist. - python setup.py check -r -s sdist - - # Verify readme.rst, build mssqltoolsservice wheel, and install mssql-scripter. - python verify_packaging.py clean + # Verify readme.rst and build mssql-scripter wheel. + python build.py build python -m mssqlscripter -h diff --git a/utility.py b/utility.py index 0b8f10f..03dc025 100644 --- a/utility.py +++ b/utility.py @@ -6,20 +6,15 @@ from __future__ import print_function from subprocess import check_call, CalledProcessError import os +import platform import shutil import sys ROOT_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) -MSSQLTOOLSSERVICE_DIRECTORY = os.path.abspath(os.path.join( - os.path.abspath(__file__), '..', 'mssqltoolsservice')) - MSSQLSCRIPTER_DIST_DIRECTORY = os.path.abspath( os.path.join(os.path.abspath(__file__), '..', 'dist')) -MSSQLTOOLSSERVICE_DIST_DIRECTORY = os.path.abspath(os.path.join( - os.path.abspath(__file__), '..', 'mssqltoolsservice', 'dist')) - def exec_command(command, directory, continue_on_error=True): """ @@ -51,3 +46,24 @@ def clean_up(directory): except Exception: # Ignored, directory may not exist which is fine. pass + + +def get_current_platform(): + """ + Get current platform name. + """ + system = platform.system() + arch = platform.architecture()[0] + + run_time_id = None + if system == 'Windows': + if arch == '32bit': + run_time_id = 'win32' + elif arch == '64bit': + run_time_id = 'win_amd64' + elif system == 'Darwin': + run_time_id = 'macosx_10_11_intel' + elif system == 'Linux': + run_time_id = 'manylinux1_x86_64' + + return run_time_id diff --git a/verify_packaging.py b/verify_packaging.py deleted file mode 100644 index e2eee6b..0000000 --- a/verify_packaging.py +++ /dev/null @@ -1,43 +0,0 @@ -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- - -from __future__ import print_function -import utility -import os -import setup # called via "verify_package.py clean"" to detect platform for wheel generation. - - -root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) - - -def build_wheel_for_current_platform(): - """ - Build mssqltoolsservice wheel for current platform. - """ - # Build mssqltoolsservice wheel for this platform. - current_platform = os.environ['MSSQLTOOLSSERVICE_PACKAGE_SUFFIX'] - utility.exec_command( - 'python mssqltoolsservice/buildwheels.py {}'.format(current_platform), - root_dir, - continue_on_error=False - ) - - -def verify_local_install(): - """ - Install mssql-scripter package locally that resolves mssqltoolsservice dependency from local build. - """ - # Local install of mssql-scripter. - mssqlscripter_sdist_name = os.listdir(utility.MSSQLSCRIPTER_DIST_DIRECTORY)[0] - # To ensure we have a clean install, we disable the cache as to prevent cache overshadowing actual changes made. - utility.exec_command( - 'pip install --no-cache-dir --no-index --find-links=./mssqltoolsservice/dist ./dist/{}'.format(mssqlscripter_sdist_name), - root_dir, continue_on_error=False - ) - - -if __name__ == '__main__': - build_wheel_for_current_platform() - verify_local_install()