Skip to content

Commit 47caeeb

Browse files
authored
Add setup.py documentation (#868)
1 parent da6324b commit 47caeeb

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
@@ -16,6 +16,66 @@ You can install your required PyPI packages and import them in your Python files
1616

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

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

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

0 commit comments

Comments
 (0)