Skip to content

Commit 6774550

Browse files
committed
Add setup.py documentation (#868)
(cherry picked from commit 47caeeb)
1 parent 37d0000 commit 6774550

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

docs/deployments/python-packages.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,66 @@ You can install your required PyPI packages and import them in your Python files
1414

1515
Note that some packages are pre-installed by default (see "pre-installed packages" for your Predictor type in the [Predictor documentation](predictors.md)).
1616

17+
## `setup.py`
18+
19+
It is also possible to reference Python libraries that are packaged using `setup.py`.
20+
21+
Here is an example directory structure:
22+
23+
```text
24+
./iris-classifier/
25+
├── cortex.yaml
26+
├── predictor.py
27+
├── ...
28+
├── mypkg
29+
│   └── __init__.py
30+
├── requirements.txt
31+
└── setup.py
32+
```
33+
34+
In this case, `requirements.txt` can include a single `.`:
35+
36+
```python
37+
# requirements.txt
38+
39+
.
40+
```
41+
42+
If this is the contents `setup.py`:
43+
44+
```python
45+
# setup.py
46+
47+
from distutils.core import setup
48+
49+
setup(
50+
name="mypkg",
51+
version="0.0.1",
52+
packages=["mypkg"],
53+
)
54+
```
55+
56+
And `__init__.py` looks like this:
57+
58+
```python
59+
# mypkg/__init__.py
60+
61+
def hello():
62+
print("hello")
63+
```
64+
65+
You can reference your package in `predictor.py`:
66+
67+
```python
68+
# predictor.py
69+
70+
import mypkg
71+
72+
class PythonPredictor:
73+
def predict(self, payload):
74+
mypkg.hello()
75+
```
76+
1777
## Private packages on GitHub
1878

1979
You can also install private packages hosed on GitHub by adding them to `requirements.txt` using this syntax:

0 commit comments

Comments
 (0)