-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdemo.sh
executable file
·217 lines (174 loc) · 3.83 KB
/
demo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
#
# This script will create a new venv and install pypackage inside it.
# It then creates a bunch of example packages, all inside a new example
# directory. The hello-world package should be installed, the tested_mod and
# detected_pkg packages should only be tested and built. The has_data package
# should also be installed and should have a script entry point of `read_data`
# which should dump 100B of static random data to stdout.
#
# Make sure to re-activate the venv after running this script with:
#
# $ source example/bin/activate
#
# then you can inspect the installed state of the demo packages
#
#
# cleanup and setup
#
rm -rf example
virtualenv --python=python2.7 --no-site-packages example
source example/bin/activate
pip install pypackage
cd example
#
# Create hello-world
#
mkdir hello-world
cd hello-world
cat <<EOF > my_module.py
def my_function():
return "my_module is correctly installed"
EOF
#
# Install hello-world
#
py-install
# verify the install
cd ..
python -c 'import my_module; print(my_module.my_function())'
#
# Create tested_mod
#
mkdir tested_mod
cd tested_mod
# make the tests
mkdir tests
cd tests
cat <<EOF > test_tested_mod.py
import pytest
import tested_mod
def test_returns_true():
assert tested_mod.returns_true()
def test_returns_false():
assert tested_mod.returns_false() is False
EOF
cd ..
# make the module
cat <<EOF > tested_mod.py
def returns_true():
return True
def returns_false():
return False
EOF
# inform pypackage
cat <<EOF > pypackage.meta
{"test_runner": "pytest"}
EOF
# run the tests
py-test
# build a release
py-build
# show results
ls -lh dist
cd ..
#
# Create detected_pkg
#
# create the directories
mkdir detected_pkg
cd detected_pkg
mkdir detected_pkg
mkdir tests
# write the package files
cd detected_pkg
cat <<EOF > __init__.py
# coding: utf-8
from __future__ import unicode_literals
__version__ = "0.0.1"
__author__ = "joe blow"
__email__ = "jð[email protected]"
EOF
cat <<EOF > some_mod.py
def is_true():
return True
def is_none():
return None
EOF
cd ..
# write the test file
cd tests
cat <<EOF > test_some_mod.py
import pytest
from detected_pkg import some_mod
def test_is_true():
assert some_mod.is_true()
def test_is_none():
assert some_mod.is_none() is None
EOF
cd ..
# write the pypackage.meta
cat <<EOF > pypackage.meta
{"test_runner": "pytest"}
EOF
# run tests
py-test
# create releases
py-build
# save a copy of the setup.py in the src
py-build -s
cd ..
#
# pure binary project
#
mkdir pure_binary
cd pure_binary
dd if=/dev/random of=binary_blob.bin bs=10 count=10
py-build
pip install dist/*.tar.gz
cd /
python -c 'from pkg_resources import Requirement, resource_filename; print(resource_filename(Requirement.parse("pure_binary"), "binary_blob.bin"))'
cd -
cd ..
#
# data project
#
mkdir -p has_data/has_data/data
cd has_data/has_data
touch __init__.py
# create data
dd if=/dev/random of=data/file bs=10 count=10
# create python module to read and display data
cat <<EOF > read_data.py
import os
def to_stdout():
random_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
"data", "file")
print("your random data is:")
with open(random_file) as random_data:
print(random_data.read())
EOF
cd ..
# make a script, (you could use an entry point but this shows the auto pickup)
mkdir bin
cat <<EOF > bin/random_data
#!/usr/bin/env python
from has_data import read_data
if __name__ == "__main__":
read_data.to_stdout()
EOF
chmod +x bin/random_data
cat <<EOF > pypackage.meta
{
"version": "1.0.0",
"packages": "has_data",
"source_label": "some long git commit hash",
"source_url": "https://yourgitserver/a_shorter_hash"
}
EOF
py-install
py-info has-data
random_data
echo "example packages created! use"
echo " source example/bin/activate"
echo "to activate the example virtualenv"