Skip to content

Commit ccf04e3

Browse files
authored
Merge pull request #1 from LeetCode-OpenSource/unittest
write a unit test and update configs
2 parents c01d3f7 + 267161e commit ccf04e3

File tree

10 files changed

+308
-12
lines changed

10 files changed

+308
-12
lines changed

.circleci/config.yml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
version: 2
2+
jobs:
3+
cargo_fetch:
4+
docker:
5+
- image: broooooklyn/rust-python:latest
6+
working_directory: /mnt/crate
7+
steps:
8+
- checkout
9+
- restore_cache:
10+
keys:
11+
- cargo-v1-{{ checksum "Cargo.toml" }}-
12+
- cargo-v1-
13+
- run:
14+
name: fetch and update
15+
command: |
16+
cargo update && \
17+
cargo fetch
18+
- persist_to_workspace:
19+
root: "."
20+
paths:
21+
- Cargo.lock
22+
- save_cache:
23+
key: cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
24+
paths:
25+
- /usr/local/cargo/registry
26+
- /usr/local/cargo/git
27+
build35:
28+
docker:
29+
- image: broooooklyn/rust-python:3.5
30+
working_directory: /mnt/crate
31+
steps:
32+
- checkout
33+
- attach_workspace:
34+
at: "."
35+
- restore_cache:
36+
keys:
37+
- cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
38+
- run:
39+
name: Print version information
40+
command: rustc --version; cargo --version
41+
- run:
42+
name: Build 35
43+
command: |
44+
python compile.py build
45+
- run:
46+
name: Upload binary
47+
command: |
48+
ghr $CIRCLE_TAG build/lib/py_sourcemap/*.so
49+
- run:
50+
name: Prune the output files
51+
command: |
52+
for file in target/release/* target/release/.??*; do
53+
[ -d $file -o ! -x $file ] && rm -r $file
54+
done
55+
- persist_to_workspace:
56+
root: "."
57+
paths:
58+
- target/release/*
59+
build36:
60+
docker:
61+
- image: broooooklyn/rust-python:3.6
62+
working_directory: /mnt/crate
63+
steps:
64+
- checkout
65+
- attach_workspace:
66+
at: "."
67+
- restore_cache:
68+
keys:
69+
- cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
70+
- run:
71+
name: Print version information
72+
command: rustc --version; cargo --version
73+
- run:
74+
name: Build 36
75+
command: |
76+
python compile.py build
77+
- run:
78+
name: Upload binary
79+
command: |
80+
ghr $CIRCLE_TAG build/lib/py_sourcemap/*.so
81+
- run:
82+
name: Prune the output files
83+
command: |
84+
for file in target/release/* target/release/.??*; do
85+
[ -d $file -o ! -x $file ] && rm -r $file
86+
done
87+
- persist_to_workspace:
88+
root: "."
89+
paths:
90+
- target/release/*
91+
build37:
92+
docker:
93+
- image: broooooklyn/rust-python:3.7
94+
working_directory: /mnt/crate
95+
steps:
96+
- checkout
97+
- attach_workspace:
98+
at: "."
99+
- restore_cache:
100+
keys:
101+
- cargo-v1-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}
102+
- run:
103+
name: Print version information
104+
command: rustc --version; cargo --version
105+
- run:
106+
name: Build 37
107+
command: |
108+
python compile.py build
109+
- run:
110+
name: Upload binary
111+
command: |
112+
ghr $CIRCLE_TAG build/lib/py_sourcemap/*.so
113+
- run:
114+
name: Prune the output files
115+
command: |
116+
for file in target/release/* target/release/.??*; do
117+
[ -d $file -o ! -x $file ] && rm -r $file
118+
done
119+
- persist_to_workspace:
120+
root: "."
121+
paths:
122+
- target/release/*
123+
124+
nightly:
125+
machine: true
126+
triggers:
127+
- schedule:
128+
cron: "0 0 * * *"
129+
filters:
130+
branches:
131+
only:
132+
- master
133+
steps:
134+
- checkout
135+
- run: docker login -u $DOCKER_USER -p $DOCKER_PASS
136+
- run: docker build . -t broooooklyn/rust-python:3.5 --build-arg PYTHON_VERSION=3.5
137+
- run: docker push broooooklyn/rust-python:3.5
138+
- run: docker build . -t broooooklyn/rust-python:3.6 --build-arg PYTHON_VERSION=3.6
139+
- run: docker push broooooklyn/rust-python:3.6
140+
- run: docker build . -t broooooklyn/rust-python:3.7 --build-arg PYTHON_VERSION=3.7
141+
- run: docker tag broooooklyn/rust-python:3.7 broooooklyn/rust-python:latest
142+
- run: docker push broooooklyn/rust-python:3.7
143+
- run: docker push broooooklyn/rust-python:latest
144+
workflows:
145+
version: 2
146+
build_all_versions:
147+
jobs:
148+
- cargo_fetch
149+
- build35:
150+
requires:
151+
- cargo_fetch
152+
- build36:
153+
requires:
154+
- cargo_fetch
155+
- build37:
156+
requires:
157+
- cargo_fetch

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ Cargo.lock
44
*.pyc
55
build
66
*.so
7+
.eggs
8+
*.egg-info
9+
10+
# editor related
11+
.vscode

.travis.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
language: python
2+
python:
3+
- "3.5"
4+
- "3.6"
5+
- "3.7"
6+
os: osx
7+
cache: cargo
8+
before_install:
9+
- brew update
10+
- brew install rust
11+
- rustup default nightly
12+
13+
install:
14+
- pip install -r requirements-dev.txt
15+
16+
script: |
17+
python compile.py build
18+
19+
deploy:
20+
provider: releases
21+
api_key:
22+
secure: $GITHUB_TOKEN
23+
file: build/lib/py_sourcemap/py_sourcemap.so
24+
skip_cleanup: true
25+
on:
26+
tags: true

Dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM ubuntu:16.04
2+
3+
ENV GHR_VERSION="0.9.0"
4+
5+
ARG PYTHON_VERSION=3.6
6+
7+
ENV RUSTUP_HOME=/usr/local/rustup \
8+
CARGO_HOME=/usr/local/cargo \
9+
PATH=/usr/local/cargo/bin:$PATH \
10+
RUST_VERSION=1.28.0
11+
12+
RUN apt-get update && \
13+
apt-get install software-properties-common python-software-properties -y && \
14+
add-apt-repository ppa:deadsnakes/ppa -y && \
15+
apt-get update && \
16+
apt-get install python${PYTHON_VERSION} python3-pip wget git curl -y && \
17+
apt-get upgrade -y && \
18+
apt-get autoremove -y && \
19+
ln -sf /usr/bin/python${PYTHON_VERSION} /usr/bin/python && \
20+
curl -fSL -o ghr.tar.gz "https://github.com/tcnksm/ghr/releases/download/v${GHR_VERSION}/ghr_v${GHR_VERSION}_linux_amd64.tar.gz" && \
21+
tar -xvzf ghr.tar.gz && \
22+
mv ghr_v0.9.0_linux_amd64/ghr /usr/local/bin && \
23+
chown root:root /usr/local/bin/ghr && \
24+
rm -r \
25+
ghr.tar.gz \
26+
ghr_v0.9.0_linux_amd64
27+
28+
RUN set -eux; \
29+
dpkgArch="$(dpkg --print-architecture)"; \
30+
case "${dpkgArch##*-}" in \
31+
amd64) rustArch='x86_64-unknown-linux-gnu'; rustupSha256='f69dafcca62fe70d7882113e21bb96a2cbdf4fc4636d25337d6de9191bdec8da' ;; \
32+
armhf) rustArch='armv7-unknown-linux-gnueabihf'; rustupSha256='eee969b9fd128e8dc9b4ec44acde46735cf8e612d06495e9d022517849aba2d6' ;; \
33+
arm64) rustArch='aarch64-unknown-linux-gnu'; rustupSha256='cdc48b7882582fd8475107a406dd86df85c7d72e5deea99ff8940c8e11531285' ;; \
34+
i386) rustArch='i686-unknown-linux-gnu'; rustupSha256='3bad3945452509ac28ba4113e198323daab57488d6885bb31ac30c9eecd88825' ;; \
35+
*) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \
36+
esac; \
37+
url="https://static.rust-lang.org/rustup/archive/1.13.0/${rustArch}/rustup-init"; \
38+
wget "$url"; \
39+
echo "${rustupSha256} *rustup-init" | sha256sum -c -; \
40+
chmod +x rustup-init; \
41+
./rustup-init -y --no-modify-path --default-toolchain $RUST_VERSION; \
42+
rm rustup-init; \
43+
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
44+
rustup default nightly && \
45+
rustup --version; \
46+
cargo --version; \
47+
rustc --version;

compile.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
3+
from setuptools import setup
4+
from setuptools_rust import Binding, RustExtension
5+
6+
try:
7+
from setuptools_rust import RustExtension
8+
except ImportError:
9+
import subprocess
10+
11+
errno = subprocess.call([sys.executable, "-m", "pip", "install", "setuptools-rust"])
12+
if errno:
13+
print("Please install setuptools-rust package")
14+
raise SystemExit(errno)
15+
else:
16+
from setuptools_rust import RustExtension
17+
18+
setup(name='py-sourcemap',
19+
version='0.1',
20+
rust_extensions=[RustExtension('py_sourcemap.py_sourcemap',
21+
'Cargo.toml', binding=Binding.PyO3)],
22+
packages=['py_sourcemap'],
23+
setup_requires=['setuptools_rust>=0.10.2'],
24+
# rust extensions are not zip safe, just like C-extensions.
25+
zip_safe=False
26+
)

requirements-dev.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

setup.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
from setuptools import setup
2-
from setuptools_rust import Binding, RustExtension
2+
from setuptools.command.install import install
33

4-
setup(name='py-sourcemap',
4+
class PostInstallCommand(install):
5+
"""Post-installation for installation mode."""
6+
def run(self):
7+
'''
8+
Write downloading process here
9+
mv target .so file into `py_sourcemap/py_sourcemap.so`
10+
'''
11+
install.run(self)
12+
13+
install_requires = []
14+
tests_require = install_requires + ['nose']
15+
16+
setup(
17+
name='py-sourcemap',
518
version='0.1',
6-
rust_extensions=[RustExtension('py_sourcemap.py_sourcemap',
7-
'Cargo.toml', binding=Binding.PyO3)],
819
packages=['py_sourcemap'],
20+
classifiers=[
21+
'Development Status :: 4 - Beta',
22+
'Environment :: Console',
23+
'Environment :: Web Environment',
24+
'Intended Audience :: Developers',
25+
'Operating System :: MacOS :: MacOS X',
26+
'Operating System :: Microsoft :: Windows',
27+
'Operating System :: POSIX',
28+
'Programming Language :: Python',
29+
'Programming Language :: Rust',
30+
],
31+
install_requires=install_requires,
32+
tests_require=tests_require,
33+
test_suite='nose.collector',
34+
cmdclass={
35+
'install': PostInstallCommand,
36+
},
937
# rust extensions are not zip safe, just like C-extensions.
1038
zip_safe=False
1139
)

tests/__init__.py

Whitespace-only changes.

tests/lookup.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/test_parse.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from unittest import TestCase
2+
3+
from py_sourcemap import SourcemapParser
4+
5+
6+
class TestParser(TestCase):
7+
def setUp(self):
8+
self.sourcemap = SourcemapParser("./tests/index.js.map")
9+
10+
def test_parse_trace(self):
11+
result = self.sourcemap.original_location_for(0, 195302)
12+
self.assertEqual(result[0], 22)
13+
self.assertEqual(result[1], 41)
14+
self.assertEqual(result[2][-13:], 'TopicList.jsx')
15+
self.assertEqual(result[3], 'edges')

0 commit comments

Comments
 (0)