Skip to content

Commit d620997

Browse files
committed
Merge pull request #56 from ntucllab/chkoar-pep8
Chkoar pep8
2 parents 7ccee86 + 47dc55a commit d620997

32 files changed

+535
-551
lines changed

.pylintrc

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
[REPORTS]
2+
3+
# Set the output format. Available formats are text, parseable, colorized, msvs
4+
# (visual studio) and html.
5+
output-format=colorized
6+
7+
# Tells whether to display a full report or only the messages
8+
reports=yes
9+
10+
# Python expression which should return a note less than 10 (10 is the highest
11+
# note). You have access to the variables errors warning, statement which
12+
# respectively contain the number of errors / warnings messages and the total
13+
# number of statements analyzed. This is used by the global evaluation report
14+
# (RP0004).
15+
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
16+
17+
18+
[VARIABLES]
19+
20+
# List of additional names supposed to be defined in builtins. Remember that
21+
# you should avoid to define new builtins when possible.
22+
additional-builtins=zip
23+
24+
# List of strings which can identify a callback function by name. A callback
25+
# name must start or end with one of those strings.
26+
callbacks=cb_,_cb
27+
28+
29+
[BASIC]
30+
31+
# List of builtins function names that should not be used, separated by a comma
32+
bad-functions=map,filter
33+
34+
# Good variable names which should always be accepted, separated by a comma
35+
# x, y, X, Y - vector maxtrix of features and labels.
36+
# P, p - probability distribution
37+
# qs - query strategry
38+
# w, W - weight vector
39+
# N - number of instances
40+
# T, K - number of iterations
41+
good-names=i,j,k,_,X,Y,x,y,P,p,qs,w,W,N,T,K
42+
43+
# Regular expression matching correct attribute names
44+
attr-rgx=[a-z_][a-z0-9_]{2,30}$
45+
46+
# Naming hint for attribute names
47+
attr-name-hint=[a-z_][a-z0-9_]{2,30}$
48+
49+
# Regular expression matching correct variable names
50+
# start with X imply its a matrix for features
51+
variable-rgx=[a-z_X][a-z0-9_]{2,30}$
52+
53+
# Naming hint for variable names
54+
variable-name-hint=[a-z_X][a-z0-9_]{2,30}$
55+
56+
# Regular expression which should only match function or class names that do
57+
# not require a docstring.
58+
no-docstring-rgx=^_
59+
60+
# Minimum line length for functions/classes that require docstrings, shorter
61+
# ones are exempt.
62+
docstring-min-length=-1
63+
64+
65+
[TYPECHECK]
66+
67+
# List of module names for which member attributes should not be checked
68+
# (useful for modules/projects where namespaces are manipulated during runtime
69+
# and thus existing member attributes cannot be deduced by static analysis. It
70+
# supports qualified module names, as well as Unix pattern matching.
71+
ignored-modules=numpy,matplotlib,future_builtins
72+
73+
# List of classes names for which member attributes should not be checked
74+
# (useful for classes with attributes dynamically set). This supports can work
75+
# with qualified names.
76+
ignored-classes=
77+
78+
# List of members which are set dynamically and missed by pylint inference
79+
# system, and so shouldn't trigger E1101 when accessed. Python regular
80+
# expressions are accepted.
81+
generated-members=
82+
83+
84+
[FORMAT]
85+
86+
# Maximum number of characters on a single line.
87+
max-line-length=79
88+
89+
# List of optional constructs for which whitespace checking is disabled. `dict-
90+
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
91+
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
92+
# `empty-line` allows space-only lines.
93+
no-space-check=trailing-comma,dict-separator
94+
95+
# Maximum number of lines in a module
96+
max-module-lines=1000
97+
98+
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
99+
# tab).
100+
indent-string=' '
101+
102+
# Number of spaces of indent required inside a hanging or continued line.
103+
indent-after-paren=4
104+
105+
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
106+
expected-line-ending-format=LF
107+
108+
109+
[DESIGN]
110+
111+
# Maximum number of arguments for function / method
112+
max-args=15
113+
114+
# sometimes more locals can handle computation more efficiently
115+
max-locals=30
116+
117+
# Maximum number of attributes for a class (see R0902).
118+
max-attributes=15
119+
120+
121+
[MESSAGES CONTROL]
122+
123+
# R0903 - Not enough public methods
124+
# E0611 - No name %r in module %r (countless false-positives)
125+
# E1101, E1103 - %s %r has no %r member (countless false-positives)
126+
# F0401 - Unable to import %r (error for c extensions)
127+
disable=R0903,E0611,E1101,E1103,F0401
128+
129+
130+
[CLASSES]
131+
132+
# List of method names used to declare (i.e. assign) instance attributes.
133+
defining-attr-methods=__init__,__new__,setUp
134+
135+
# List of valid names for the first argument in a class method.
136+
valid-classmethod-first-arg=cls
137+
138+
# List of valid names for the first argument in a metaclass class method.
139+
valid-metaclass-classmethod-first-arg=mcs

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ before_install:
3434
- travis_wait 20 pip install -r requirements.txt
3535
- pip install coverage
3636
- pip install codecov
37+
- pip install pylint
3738
install:
3839
- ./setup.py build_ext --inplace
3940
script:
4041
- python -m unittest -v
4142
- coverage run --source libact --omit */tests/* setup.py test
4243
- coverage report
4344
after_success:
45+
- pylint libact
4446
- codecov

README.md

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,58 +26,51 @@ Documentation for the latest release is hosted [here](http://libact.readthedocs.
2626

2727
# Basic Dependencies
2828

29-
Python3 dependencies
29+
* Python 2.7, 3.3, 3.4, 3.5
30+
31+
* Python dependencies
3032
```
31-
pip3 install -r requirements.txt
33+
pip install -r requirements.txt
3234
```
3335

34-
Debian (>= 7) / Ubuntu (>= 14.04)
36+
* Debian (>= 7) / Ubuntu (>= 14.04)
3537
```
3638
sudo apt-get install build-essential gfortran libatlas-base-dev liblapacke-dev python3-dev
3739
```
3840

39-
MacOS
41+
* MacOS
4042
```
4143
brew tap homebrew/science
4244
brew install openblas
4345
```
4446

4547
# Installation
4648

47-
One of the query strategies (`hintsvm`) depends on the HintSVM package that requires special installation. If you are not using the strategy, please simply follow the section on general installation. Otherwise please follow the section on HintSVM.
48-
49-
## General Installation
50-
After resolving the dependencies, it should be fairly simple to install the package in your home directory:
51-
49+
After resolving the dependencies, you may install the package via pip (for all users):
5250
```
53-
python setup.py install --user
51+
sudo pip install libact
5452
```
5553

56-
To install for all users on Unix/Linux:
54+
or pip install in home directory:
5755
```
58-
python setup.py build
59-
sudo python setup.py install
56+
pip install --user libact
6057
```
6158

62-
Or via pip: (for all users):
59+
or pip install from github repository for latest source:
6360
```
64-
sudo pip install libact
61+
pip install git+https://github.com/ntucllab/libact.git
6562
```
6663

67-
Pip install in home directory:
64+
To build and install from souce in your home directory:
6865
```
69-
pip install --user libact
66+
python setup.py install --user
7067
```
7168

72-
## Special Installation for HintSVM
73-
74-
For HintSVM, you would have to install the [hintsvm package](https://github.com/ntucllab/hintsvm) first.
75-
76-
Before running, you need to make sure the path to the library and
77-
python code of `hintsvm` are set in the environment variables:
78-
79-
export LD_LIBRARY_PATH=/path/to/hintsvm:$LD_LIBRARY_PATH
80-
export PYTHONPATH=/path/to/hintsvm/python:$PYTHONPATH
69+
To build and install from souce for all users on Unix/Linux:
70+
```
71+
python setup.py build
72+
sudo python setup.py install
73+
```
8174

8275
# Usage
8376

@@ -103,6 +96,27 @@ Available examples:
10396
- `examples/label_digits.py`: This example shows how to use libact in the case
10497
that you want a human to label the selected sample for your algorithm.
10598

99+
# Running tests
100+
101+
To run the test suite:
102+
103+
```
104+
python setup.py test
105+
```
106+
107+
To run pylint, install pylint through ```pip install pylint``` and run the following command in root directory:
108+
109+
```
110+
pylint libact
111+
```
112+
113+
To measure the test code coverage, install coverage through ```pip install coverage``` and run the following commands in root directory:
114+
115+
```
116+
coverage run --source libact --omit */tests/* setup.py test
117+
coverage report
118+
```
119+
106120
# Acknowledgments
107121

108122
The authors thank Chih-Wei Chang and other members of the [Computational Learning Lab](https://learner.csie.ntu.edu.tw/) at National Taiwan University for valuable discussions and various contributions to making this package better.

docs/conf.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import sys
2020
from unittest.mock import MagicMock
2121

22+
2223
class Mock(MagicMock):
24+
2325
@classmethod
2426
def __getattr__(cls, name):
2527
return Mock()
@@ -239,25 +241,25 @@ def __getattr__(cls, name):
239241
# -- Options for LaTeX output ---------------------------------------------
240242

241243
latex_elements = {
242-
# The paper size ('letterpaper' or 'a4paper').
243-
#'papersize': 'letterpaper',
244+
# The paper size ('letterpaper' or 'a4paper').
245+
#'papersize': 'letterpaper',
244246

245-
# The font size ('10pt', '11pt' or '12pt').
246-
#'pointsize': '10pt',
247+
# The font size ('10pt', '11pt' or '12pt').
248+
#'pointsize': '10pt',
247249

248-
# Additional stuff for the LaTeX preamble.
249-
#'preamble': '',
250+
# Additional stuff for the LaTeX preamble.
251+
#'preamble': '',
250252

251-
# Latex figure (float) alignment
252-
#'figure_align': 'htbp',
253+
# Latex figure (float) alignment
254+
#'figure_align': 'htbp',
253255
}
254256

255257
# Grouping the document tree into LaTeX files. List of tuples
256258
# (source start file, target name, title,
257259
# author, documentclass [howto, manual, or own class]).
258260
latex_documents = [
259-
(master_doc, 'libact.tex', 'libact Documentation',
260-
'Y.-A. Chung, S.-C. Lee, T.-E. Wu, Y.-Y. Yang, H.-T. Lin', 'manual'),
261+
(master_doc, 'libact.tex', 'libact Documentation',
262+
'Y.-A. Chung, S.-C. Lee, T.-E. Wu, Y.-Y. Yang, H.-T. Lin', 'manual'),
261263
]
262264

263265
# The name of an image file (relative to this directory) to place at the top of
@@ -300,9 +302,9 @@ def __getattr__(cls, name):
300302
# (source start file, target name, title, author,
301303
# dir menu entry, description, category)
302304
texinfo_documents = [
303-
(master_doc, 'libact', 'libact Documentation',
304-
author, 'libact', 'One line description of project.',
305-
'Miscellaneous'),
305+
(master_doc, 'libact', 'libact Documentation',
306+
author, 'libact', 'One line description of project.',
307+
'Miscellaneous'),
306308
]
307309

308310
# Documents to append as an appendix to all manuals.

examples/label_digits.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ def split_train_test(n_classes):
2929
from sklearn.datasets import load_digits
3030

3131
n_labeled = 5
32-
digits = load_digits(n_class=n_classes) # consider binary case
32+
digits = load_digits(n_class=n_classes) # consider binary case
3333
X = digits.data
3434
y = digits.target
3535
print(np.shape(X))
3636

3737
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)
3838
while len(np.unique(y_train[:n_labeled])) < n_classes:
39-
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)
39+
X_train, X_test, y_train, y_test = train_test_split(
40+
X, y, test_size=0.33)
4041

4142
trn_ds = Dataset(X_train, np.concatenate(
4243
[y_train[:n_labeled], [None] * (len(y_train) - n_labeled)]))
@@ -98,9 +99,9 @@ def main():
9899
model.train(trn_ds2)
99100
E_out2 = np.append(E_out2, 1 - model.score(tst_ds))
100101

101-
ax.set_xlim((0, i+1))
102+
ax.set_xlim((0, i + 1))
102103
ax.set_ylim((0, max(max(E_out1), max(E_out2)) + 0.2))
103-
query_num = np.arange(0, i+2)
104+
query_num = np.arange(0, i + 2)
104105
p1.set_xdata(query_num)
105106
p1.set_ydata(E_out1)
106107
p2.set_xdata(query_num)

examples/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def main():
5555
dataset_filepath = os.path.join(
5656
os.path.dirname(os.path.realpath(__file__)), 'diabetes.txt')
5757
test_size = 0.33 # the percentage of samples in the dataset that will be
58-
# randomly selected and assigned to the test set
58+
# randomly selected and assigned to the test set
5959
n_labeled = 10 # number of samples that are initially labeled
6060

6161
# Load dataset

libact/base/dataset.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414

1515
class Dataset(object):
16+
1617
"""libact dataset object
1718
1819
Parameters
@@ -31,7 +32,9 @@ class Dataset(object):
3132
3233
"""
3334

34-
def __init__(self, X=[], y=[]):
35+
def __init__(self, X=None, y=None):
36+
if X is None: X = []
37+
if y is None: y = []
3538
self.data = list(zip(X, y))
3639
self.modified = True
3740
self._update_callback = set()
@@ -176,7 +179,7 @@ def get_unlabeled_entries(self):
176179
return [
177180
(idx, entry[0]) for idx, entry in enumerate(self.data)
178181
if entry[1] is None
179-
]
182+
]
180183

181184
def labeled_uniform_sample(self, sample_size, replace=True):
182185
"""Returns a Dataset object with labeled data only, which is
@@ -191,7 +194,7 @@ def labeled_uniform_sample(self, sample_size, replace=True):
191194
samples = [
192195
random.choice(self.get_labeled_entries())
193196
for _ in range(sample_size)
194-
]
197+
]
195198
else:
196199
samples = random.sample(self.get_labeled_entries(), sample_size)
197200
return Dataset(*zip(*samples))

0 commit comments

Comments
 (0)