forked from rpm-software-management/tito
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HACKING
139 lines (96 loc) · 3.84 KB
/
HACKING
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
Hacking
=======
This is the developer documentation for
https://github.com/dgoodwin/tito
Python versions
---------------
Tito supports Python versions 2.4 (RHEL 5) and up.
See http://docs.python.org/dev/howto/pyporting.html
and http://python3porting.com/differences.html
and https://docs.python.org/3.0/whatsnew/3.0.html
for tips on writing portable Python code.
In particular, you must capture exceptions in a way that's
compatible with both python 2.4 and 3.x. For example:
try:
raise Exception()
except Exception:
import sys
exc = sys.exc_info()[1]
# Current exception is 'exc'.
pass
Tests
-----
### Docker test harness
To run all tests on all supported platforms:
yum -y install docker
systemctl enable --now docker.service
usermod -aG docker <your-username>
Log out and log in to refresh your secondary group.
Then run from the root of the project:
hacking/runtests.sh
If any test fails, the script exits non-zero.
To get a zero exit status, all tests must pass
or be skipped.
The above script runs a test harness based on
docker containers and takes several minutes to run
on the first build (or if you remove the images).
Expected output resembles:
-snip copious output-
=====================
Summary
/tmp/titotest-centos-6-python.out : OK (SKIP=1)
/tmp/titotest-fedora-25-python3.out : OK
You can then review the output, such as:
$ grep SKIP: /tmp/titotest-*.out
/tmp/titotest-centos-6-python.out:... SKIP: git-annex '3.20120522 ' is too old
After you run the test harness the first time,
you can optionally create and enter a container like so:
.--- remove container when done (not image)
|
| .--- interactive
| | .--- tty
| | | .---- mount current workdir into container
| | | | .---- name of image
| | | | | .-- get a shell
| | | | | |
docker run --rm -i -t -v $PWD:/home/sandbox titotest-centos-6 /bin/bash
Note about the sandbox: By default, the docker container is a
read-only execution environment to protect your source from changes.
If you are comfortable with LXC, you can override it to provide
an authoring environment, too.
### Workstation tests
To run all tests, install these packages:
* python-nose, python-pep8, python-mock (for epl-6 and fedora) and rpm-python
* python3-nose, python3-pep8, python3-mock (for epl-6 and fedora) , and rpm-python3
* createrepo_c
* git-annex
For epel-5:
There is also a need to install additional library via pip (pip install mock)
for python 2.4 - 2.7 (in case you don't have pip, install via yum python-pip package)
* mock
Then from the root of the project:
python ./runtests.py -vv
python3 ./runtests.py -vv
### Advanced
When developing code for tito there are a couple ways you can test:
"bin/tito-dev" is a script that will run code from the local checkout
rather than what is installed on the system.
And of course, you can always use the installed tito to replace
itself with a test build of the latest *committed* code in your
git HEAD.
tito build --rpm --test -i
If you screw anything up inside tito itself, you can just:
rpm -e tito
yum install tito
Code style
----------
Python3 does not allow mixing tabs and spaces for indentation.
http://docs.python.org/3.3/reference/lexical_analysis.html
You can force your editor to do the right thing by installing
a plugin for your editor from http://editorconfig.org/#download
For example, add the EditorConfig plugin for vim like this:
cd /tmp/
wget https://github.com/editorconfig/editorconfig-vim/archive/master.zip
unzip master.zip
mkdir ~/.vim
cp -r editorconfig-vim-master/* ~/.vim/