diff --git a/.bumpversion.cfg b/.bumpversion.cfg new file mode 100644 index 0000000..a4d2822 --- /dev/null +++ b/.bumpversion.cfg @@ -0,0 +1,6 @@ +[bumpversion] +current_version = 0.1.10 +commit = True +tag = True + +[bumpversion:file:setup.py] diff --git a/.circleci/config.yml b/.circleci/config.yml index 1a0edea..2ad3b66 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,3 +1,48 @@ +build: &build + working_directory: /mnt/crate + steps: + - checkout + - attach_workspace: + at: "." + - restore_cache: + keys: + - cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }} + - run: + name: Print version information + command: rustc --version; cargo --version; python -V; + - run: + name: Build 35 + command: | + pip install -r requirement-dev.txt && python compile.py build + - run: + name: Test 35 + command: | + cp build/lib/py_sourcemap/*.so py_sourcemap/ && \ + nosetests + - run: + name: Prune the output files + command: | + for file in target/release/* target/release/.??*; do + [ -d $file -o ! -x $file ] && rm -r $file + done + - persist_to_workspace: + root: "." + paths: + - ./* + +deploy: &deploy + docker: + - image: tsub/ghr:latest + working_directory: /mnt/crate + steps: + - attach_workspace: + at: "." + - run: + name: 'Deploy to Github Release' + command: | + export GIT_TAG="$(git describe --tags $(git rev-list --tags --max-count=1))"; \ + ghr -u "${CIRCLE_PROJECT_USERNAME}" -r "${CIRCLE_PROJECT_REPONAME}" "${GIT_TAG}" build/lib/py_sourcemap/*.so + version: 2 jobs: cargo_fetch: @@ -25,128 +70,36 @@ jobs: - /usr/local/cargo/registry - /usr/local/cargo/git build35: + <<: *build docker: - image: broooooklyn/rust-python:3.5 - working_directory: /mnt/crate - steps: - - checkout - - attach_workspace: - at: "." - - restore_cache: - keys: - - cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }} - - run: - name: Print version information - command: rustc --version; cargo --version - - run: - name: Build 35 - command: | - python compile.py build - - run: - name: Prune the output files - command: | - for file in target/release/* target/release/.??*; do - [ -d $file -o ! -x $file ] && rm -r $file - done - - persist_to_workspace: - root: "." - paths: - - ./* + build36: + <<: *build docker: - image: broooooklyn/rust-python:3.6 - working_directory: /mnt/crate - steps: - - checkout - - attach_workspace: - at: "." - - restore_cache: - keys: - - cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }} - - run: - name: Print version information - command: rustc --version; cargo --version - - run: - name: Build 36 - command: | - python compile.py build - - run: - name: Prune the output files - command: | - for file in target/release/* target/release/.??*; do - [ -d $file -o ! -x $file ] && rm -r $file - done - - persist_to_workspace: - root: "." - paths: - - ./* + build37: + <<: *build docker: - image: broooooklyn/rust-python:3.7 - working_directory: /mnt/crate - steps: - - checkout - - attach_workspace: - at: "." - - restore_cache: - keys: - - cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }} - - run: - name: Print version information - command: rustc --version; cargo --version - - run: - name: Build 37 - command: | - python compile.py build - - run: - name: Prune the output files - command: | - for file in target/release/* target/release/.??*; do - [ -d $file -o ! -x $file ] && rm -r $file - done - - persist_to_workspace: - root: "." - paths: - - ./* - deploy35: - docker: - - image: tsub/ghr:latest - working_directory: /mnt/crate - steps: - - attach_workspace: - at: "." - - run: - name: 'Deploy to Github Release' - command: | - export GIT_TAG="$(git describe --tags $(git rev-list --tags --max-count=1))"; \ - ghr -u "${CIRCLE_PROJECT_USERNAME}" -r "${CIRCLE_PROJECT_REPONAME}" "${GIT_TAG}" build/lib/py_sourcemap/*.so + deploy35: *deploy - deploy36: - docker: - - image: tsub/ghr:latest - working_directory: /mnt/crate - steps: - - attach_workspace: - at: "." - - run: - name: 'Deploy to Github Release' - command: | - export GIT_TAG="$(git describe --tags $(git rev-list --tags --max-count=1))"; \ - ghr -u "${CIRCLE_PROJECT_USERNAME}" -r "${CIRCLE_PROJECT_REPONAME}" "${GIT_TAG}" build/lib/py_sourcemap/*.so + deploy36: *deploy + + deploy37: *deploy - deploy37: + pip_deploy: docker: - - image: tsub/ghr:latest + - image: broooooklyn/rust-python:latest working_directory: /mnt/crate steps: - attach_workspace: at: "." - run: name: 'Deploy to Github Release' - command: | - export GIT_TAG="$(git describe --tags $(git rev-list --tags --max-count=1))"; \ - ghr -u "${CIRCLE_PROJECT_USERNAME}" -r "${CIRCLE_PROJECT_REPONAME}" "${GIT_TAG}" build/lib/py_sourcemap/*.so + command: pip install -r requirement-dev.txt && make release nightly: machine: true @@ -182,6 +135,8 @@ workflows: filters: tags: only: /.*/ + branches: + only: master - build36: requires: - cargo_fetch @@ -191,6 +146,8 @@ workflows: filters: tags: only: /.*/ + branches: + only: master - build37: requires: - cargo_fetch @@ -200,3 +157,15 @@ workflows: filters: tags: only: /.*/ + branches: + only: master + - pip_deploy: + requires: + - deploy35 + - deploy36 + - deploy37 + filters: + tags: + only: /.*/ + branches: + only: master diff --git a/.gitignore b/.gitignore index 0beba92..2664d90 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ build *.so .eggs *.egg-info +dist # editor related .vscode diff --git a/.travis.yml b/.travis.yml index 690063e..b10c823 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,20 +4,26 @@ python: - "3.6" - "3.7" os: osx +osx_image: xcode9.3 cache: cargo before_install: - brew update - brew install rust - rustup default nightly +install: + - pip install -r requirements-dev.txt + script: | - python compile.py build + python compile.py build && \ + cp build/lib/py_sourcemap/*.so py_sourcemap/ && \ + nosetests deploy: provider: releases api_key: secure: $GITHUB_TOKEN - file: build/lib/py_sourcemap/py_sourcemap.so + file: build/lib/py_sourcemap/*.so skip_cleanup: true on: tags: true diff --git a/Dockerfile b/Dockerfile index 3c837e3..444136c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,28 @@ -FROM ubuntu:16.04 - -ENV GHR_VERSION="0.9.0" +FROM ubuntu:18.04 ARG PYTHON_VERSION=3.6 ENV RUSTUP_HOME=/usr/local/rustup \ CARGO_HOME=/usr/local/cargo \ PATH=/usr/local/cargo/bin:$PATH \ - RUST_VERSION=1.28.0 + RUST_VERSION=nightly RUN apt-get update && \ - apt-get install software-properties-common python-software-properties -y && \ + echo $PYTHON_VERSION && \ + apt-get install software-properties-common -y --no-install-recommends && \ add-apt-repository ppa:deadsnakes/ppa -y && \ - apt-get update && \ - apt-get install python${PYTHON_VERSION} python3-pip wget git curl -y && \ + apt-get install python${PYTHON_VERSION} wget build-essential git curl -y --no-install-recommends && \ apt-get upgrade -y && \ apt-get autoremove -y && \ ln -sf /usr/bin/python${PYTHON_VERSION} /usr/bin/python && \ - curl -fSL -o ghr.tar.gz "https://github.com/tcnksm/ghr/releases/download/v${GHR_VERSION}/ghr_v${GHR_VERSION}_linux_amd64.tar.gz" && \ - tar -xvzf ghr.tar.gz && \ - mv ghr_v0.9.0_linux_amd64/ghr /usr/local/bin && \ - chown root:root /usr/local/bin/ghr && \ - rm -r \ - ghr.tar.gz \ - ghr_v0.9.0_linux_amd64 + if [ $PYTHON_VERSION = '3.6' ]; \ + then \ + apt-get install python3-pip -y --no-install-recommends && \ + ln -sf /usr/bin/pip3 /usr/bin/pip; \ + else \ + curl https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION}; \ + fi && \ + pip install --upgrade pip RUN set -eux; \ dpkgArch="$(dpkg --print-architecture)"; \ @@ -44,4 +43,6 @@ RUN set -eux; \ rustup default nightly && \ rustup --version; \ cargo --version; \ - rustc --version; + rustc --version; \ + python -V; \ + pip -V; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ef904f7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2018 LeetCode + +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/Makefile b/Makefile new file mode 100644 index 0000000..141390d --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +format: + yapf **/*.py -i + +release: + python3 setup.py sdist bdist_wheel + twine upload --repository-url https://upload.pypi.org/legacy/ dist/* -u $PYPI_USERNAME -p $PYPI_PASSWORD diff --git a/README.md b/README.md index 2b1cbd8..fd840d6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # py-sourcemap + A tiny [source-map-mappings](https://github.com/fitzgen/source-map-mappings) bindings for python using [PyO3](https://github.com/PyO3/pyo3) diff --git a/compile.py b/compile.py index 179b8bd..e7e035a 100644 --- a/compile.py +++ b/compile.py @@ -3,23 +3,26 @@ from setuptools import setup try: - from setuptools_rust import Binding, RustExtension + from setuptools_rust import Binding, RustExtension except ImportError: - import subprocess + import subprocess - errno = subprocess.call([sys.executable, "-m", "pip", "install", "setuptools-rust"]) - if errno: - print("Please install setuptools-rust package") - raise SystemExit(errno) - else: - from setuptools_rust import Binding, RustExtension + errno = subprocess.call( + [sys.executable, "-m", "pip", "install", "setuptools-rust"]) + if errno: + print("Please install setuptools-rust package") + raise SystemExit(errno) + else: + from setuptools_rust import Binding, RustExtension -setup(name='py-sourcemap', - version='0.1', - rust_extensions=[RustExtension('py_sourcemap.py_sourcemap', - 'Cargo.toml', binding=Binding.PyO3)], - packages=['py_sourcemap'], - setup_requires=['setuptools_rust>=0.10.2'], - # rust extensions are not zip safe, just like C-extensions. - zip_safe=False -) +setup( + name='py-sourcemap', + version='0.1', + rust_extensions=[ + RustExtension( + 'py_sourcemap.py_sourcemap', 'Cargo.toml', binding=Binding.PyO3) + ], + packages=['py_sourcemap'], + setup_requires=['setuptools_rust>=0.10.2'], + # rust extensions are not zip safe, just like C-extensions. + zip_safe=False) diff --git a/py_sourcemap/__init__.py b/py_sourcemap/__init__.py index 5c8ae78..1101173 100644 --- a/py_sourcemap/__init__.py +++ b/py_sourcemap/__init__.py @@ -1,3 +1,5 @@ from .py_sourcemap import SourcemapParser +name = 'py_sourcemap' + __all__ = ["SourcemapParser"] diff --git a/requirement-dev.txt b/requirement-dev.txt new file mode 100644 index 0000000..3632d19 --- /dev/null +++ b/requirement-dev.txt @@ -0,0 +1,4 @@ +yapf==0.23.0 +twine==1.11.0 +bumpversion==0.5.3 +nose==1.3.7 diff --git a/setup.py b/setup.py index 01c6f7f..4cf6703 100644 --- a/setup.py +++ b/setup.py @@ -1,39 +1,72 @@ +import platform +import os +import sys + +from urllib.request import urlopen + from setuptools import setup from setuptools.command.install import install + +version = '0.1.10' +local_build = os.environ.get('LOCAL', 0) + + +with open('README.md', 'r') as f: + long_description = f.read() + + class PostInstallCommand(install): """Post-installation for installation mode.""" + def run(self): - ''' - Write downloading process here - mv target .so file into `py_sourcemap/py_sourcemap.so` - ''' + version_tag = 'v{}'.format(version) + url_template = 'https://github.com/LeetCode-OpenSource/py-sourcemap/releases/download/{tag}/py_sourcemap.cpython-{py_ver}-{platform}.so' + py_version = '{}{}m'.format(sys.version_info.major, + sys.version_info.minor) + system = platform.system() + if system == 'Linux': + platform = 'x86_64-linux-gnu' + else: + raise Exception('This lib is only supporting Linux for now.') + download_url = url_template.format(tag=version_tag, + py_ver=py_version, + platform=platform) + dist = os.path.join(self.build_lib, 'py_sourcemap/py_sourcemap.so') + if not local_build: + with open(dist, 'wb') as f: + built_lib = urlopen(download_url).read() + f.write(built_lib) install.run(self) -install_requires = [] + +install_requires = ['wheel'] tests_require = install_requires + ['nose'] setup( - name='py-sourcemap', - version='0.1', - packages=['py_sourcemap'], - classifiers=[ - 'Development Status :: 4 - Beta', - 'Environment :: Console', - 'Environment :: Web Environment', - 'Intended Audience :: Developers', - 'Operating System :: MacOS :: MacOS X', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'Programming Language :: Python', - 'Programming Language :: Rust', - ], - install_requires=install_requires, - tests_require=tests_require, - test_suite='nose.collector', - cmdclass={ - 'install': PostInstallCommand, - }, - # rust extensions are not zip safe, just like C-extensions. - zip_safe=False -) + name='py-sourcemap', + version=version, + packages=['py_sourcemap'], + description='A tiny source-map-mappings bindings for python using PyO3', + long_description=long_description, + url='https://github.com/LeetCode-OpenSource/py-sourcemap', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Environment :: Web Environment', + 'Intended Audience :: Developers', + 'Operating System :: MacOS :: MacOS X', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Programming Language :: Python', + 'Programming Language :: Rust', + 'License :: OSI Approved :: MIT License', + ], + install_requires=install_requires, + tests_require=tests_require, + test_suite='nose.collector', + cmdclass={ + 'install': PostInstallCommand, + }, + # rust extensions are not zip safe, just like C-extensions. + zip_safe=False) diff --git a/tests/test_parse.py b/tests/test_parse.py index 8ae9d40..634480b 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -4,12 +4,12 @@ class TestParser(TestCase): - def setUp(self): - self.sourcemap = SourcemapParser("./tests/index.js.map") - - def test_parse_trace(self): - result = self.sourcemap.original_location_for(0, 195302) - self.assertEqual(result[0], 22) - self.assertEqual(result[1], 41) - self.assertEqual(result[2][-13:], 'TopicList.jsx') - self.assertEqual(result[3], 'edges') + def setUp(self): + self.sourcemap = SourcemapParser("./tests/index.js.map") + + def test_parse_trace(self): + result = self.sourcemap.original_location_for(0, 195302) + self.assertEqual(result[0], 22) + self.assertEqual(result[1], 41) + self.assertEqual(result[2][-13:], 'TopicList.jsx') + self.assertEqual(result[3], 'edges')