Skip to content

Commit f638619

Browse files
committed
Merge branch 'main' of github.com:roboflow-ai/roboflow-python into feature/sequenced_uploads_support
2 parents fb18045 + 9246b1a commit f638619

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2476
-306
lines changed

.DS_Store

-6 KB
Binary file not shown.

.env-example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ROBOFLOW_API_KEY=your-roboflow-private-api-key
2+
PROJECT_NAME=your-project-name
3+
PROJECT_VERSION=1

.github/workflows/publish.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Publish WorkFlow
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
python-version: [3.8]
13+
steps:
14+
- name: 🛎️ Checkout
15+
uses: actions/checkout@v3
16+
with:
17+
ref: ${{ github.head_ref }}
18+
- name: 🐍 Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: 🦾 Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install ".[dev]"
26+
- name: 🚀 Publish to PyPi
27+
env:
28+
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
29+
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
30+
PYPI_TEST_PASSWORD: ${{ secrets.PYPI_TEST_PASSWORD }}
31+
run: |
32+
make publish -e PYPI_USERNAME=$PYPI_USERNAME -e PYPI_PASSWORD=$PYPI_PASSWORD -e PYPI_TEST_PASSWORD=$PYPI_TEST_PASSWORD

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
name: Test WorkFlow
22

33
on:
4+
push:
5+
branches: [main]
46
pull_request:
5-
branches: [master]
7+
branches: [main]
68

79
jobs:
810
build:
@@ -15,7 +17,8 @@ jobs:
1517
- name: 🛎️ Checkout
1618
uses: actions/checkout@v3
1719
with:
18-
ref: ${{ github.head_ref }}
20+
ref: ${{ github.event.pull_request.head.ref }}
21+
repository: ${{ github.event.pull_request.head.repo.full_name }}
1922
- name: 🐍 Set up Python ${{ matrix.python-version }}
2023
uses: actions/setup-python@v2
2124
with:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,5 @@ train/
150150
valid/
151151
data.yaml
152152
README.roboflow.txt
153-
*.zip
153+
*.zip
154+
.DS_Store

Dockerfile.dev

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG PYTHON_VERSION=3.8
2+
FROM python:$PYTHON_VERSION-slim
3+
RUN apt-get update && apt-get install make && rm -rf /var/lib/apt/lists/*
4+
WORKDIR /workspace
5+
COPY . .
6+
RUN pip install -e ".[dev]"
7+
ENTRYPOINT [ "/bin/bash" ]

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ check_code_quality:
1414
flake8 $(check_dirs) --count --select=E9,F63,F7,F82 --show-source --statistics
1515
# exit-zero treats all errors as warnings. E203 for black, E501 for docstring, W503 for line breaks before logical operators
1616
flake8 $(check_dirs) --count --max-line-length=88 --exit-zero --ignore=D --extend-ignore=E203,E501,W503 --statistics
17-
17+
18+
publish:
19+
python setup.py sdist bdist_wheel
20+
twine upload -r testpypi dist/* -u ${PYPI_USERNAME} -p ${PYPI_TEST_PASSWORD} --verbose
21+
twine check dist/*
22+
twine upload dist/* -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD} --verbose

README.md

Lines changed: 91 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,32 @@
1111
the official Roboflow python package that interfaces with the [Roboflow API](https://docs.roboflow.com). Key features of
1212
Roboflow:
1313

14-
- Import and Export image datasets into any supported [formats](https://roboflow.com/formats)
14+
- Import and Export image datasets into any supported [format](https://roboflow.com/formats)
1515
- [Preprocess](https://docs.roboflow.com/image-transformations/image-preprocessing)
1616
and [augment](https://docs.roboflow.com/image-transformations/image-augmentation) data using Roboflow's dataset
1717
management tools
1818
- Train computer vision models using [Roboflow Train](https://docs.roboflow.com/train) and deploy
1919
to [production](https://docs.roboflow.com/inference)
2020
- Use [community curated projects](https://universe.roboflow.com/) to start building your own vision-powered products
2121

22-
## Installation:
22+
## Installation
2323

2424
To install this package, please use `Python 3.6` or higher. We provide three different ways to install the Roboflow
2525
package to use within your own projects.
2626

2727
Install from PyPi (Recommended):
2828

29-
```
29+
```bash
3030
pip install roboflow
3131
```
3232

3333
Install from Source:
3434

35-
```
35+
```bash
3636
git clone https://github.com/roboflow-ai/roboflow-python.git
3737
cd roboflow-python
3838
python3 -m venv env
39-
source env/bin/activate
39+
source env/bin/activate
4040
pip3 install -r requirements.txt
4141
```
4242

@@ -51,7 +51,7 @@ rf = roboflow.Roboflow(api_key=YOUR_API_KEY_HERE)
5151
# List all projects for your workspace
5252
workspace = rf.workspace()
5353

54-
# Load a certain project, workspace url is optional
54+
# Load a certain project (workspace url is optional)
5555
project = rf.project("PROJECT_ID")
5656

5757
# List all versions of a specific project
@@ -61,7 +61,7 @@ project.versions()
6161
project.upload("UPLOAD_IMAGE.jpg")
6262

6363
# Retrieve the model of a specific project
64-
project.version("1").model
64+
model = project.version("1").model
6565

6666
# predict on a local image
6767
prediction = model.predict("YOUR_IMAGE.jpg")
@@ -79,49 +79,109 @@ prediction.json()
7979
prediction.save(output_path='predictions.jpg')
8080
```
8181

82-
## Using this package for a specifc project
82+
## Using this package for a specific project
8383

84-
If you have a specific project from your workspace you'd like to run in a notebook follow along on this tutorial [Downloading Datasets from Roboflow for Training (Python)](https://www.youtube.com/watch?v=76E6esnez8E)
84+
If you have a specific project from your workspace you'd like to run in a notebook, follow along with this tutorial: [Downloading Datasets from Roboflow for Training (Python)](https://www.youtube.com/watch?v=76E6esnez8E).
8585

8686
Selecting the format you'd like your project to be exported as while choosing the `show download code` option will display code snippets you can use in either Jupyter or your terminal. These code snippets will include your `api_key`, project, and workspace names.
8787

8888
![Alt Text](https://media.giphy.com/media/I5g06mUnVzdX7iT2Gf/giphy.gif)
8989

90-
## Deving locally
91-
1. clone repo
92-
2. create a virtual env: `virtualenv local_dev`
93-
3. activate virtual env: `source local_dev/bin/activate`
94-
4. install packages from repo: `pip3 install -e ".[dev]"`
95-
5. create script on top level of `ROBOFLOW-PYTHON` and reference local `roboflow` directory: `from roboflow import Roboflow`
96-
6. when done, uptick the pip package minor version number in `setup.py`
97-
7. manually add any new dependencies to the `requirements.txt` and list of dependencies in `setup.py` (careful not to overwrite any packages that might screw up backwards dependencies for object detection, etc.)
90+
## Developing locally
9891

99-
### Code Quality
92+
### Using Docker
10093

101-
We provide a `Makefile` to format and ensure code quality. **Be sure to run them before creating a PR**.
94+
To set the Docker container up for the first time:
10295

96+
```bash
97+
# Clone this repo
98+
git clone [email protected]:roboflow-ai/roboflow-python.git && cd roboflow-python
99+
100+
# Copy the environment variables template
101+
# Be sure to update the values with your account's information
102+
103+
# Build our development image
104+
docker build -t roboflow-python -f Dockerfile.dev .
105+
106+
# Run container and map current folder in it
107+
docker run --rm -it \
108+
-v $(pwd)/:/workspace/ \
109+
--env-file .env \
110+
roboflow-python
111+
112+
# Run tests
113+
python -m unittest
103114
```
104-
# format your code with `black` and `isort` run
105-
make style
106-
# check code with flake8
107-
make check_code_quality
115+
116+
#### Change Python version
117+
118+
You can pass the build arg `PYTHON_VERSION` to dynamically change python version at build time
119+
120+
```bash
121+
docker build -t roboflow-python --build-arg PYTHON_VERSION=3.9 -f Dockerfile.dev .
122+
```
123+
124+
Will use `python:3.9-slim`
125+
126+
**Note** If you are using [VSCode](https://code.visualstudio.com/) we recommend you read the ["Developing inside a Container"](https://code.visualstudio.com/docs/remote/containers) tutorial.
127+
128+
### Using Virtualenv
129+
130+
```bash
131+
# Clone this repo
132+
git clone [email protected]:roboflow-ai/roboflow-python.git && cd roboflow-python
133+
134+
# create virtual env
135+
virtualenv local_dev
136+
137+
# activate virtual env
138+
source local_dev/bin/activate
139+
140+
# install dependencies
141+
pip3 install -e ".[dev]"
108142
```
109143

110-
**Note** This tests will be run automatically when you commit thanks to git hooks.
144+
### Testing
111145

112-
### Tests
146+
Make sure you have your `virtualenv` spun up before running tests. Execute the `unittest` command at the `/root` level directory.
113147

114-
You need to have the following `env` variables,
148+
Run tests:
115149

150+
```bash
151+
python -m unittest
116152
```
117-
ROBOFLOW_API_KEY="<YOUR_ROBOFLOW_API>"
118-
PROJECT_NAME="<YOUR_PROJECT_NAME>"
119-
PROJECT_VERSION="" # by default "1"
153+
154+
### Contributing
155+
156+
1. Increment the pip package minor version number in `setup.py`
157+
1. Manually add any new dependencies to `requirements.txt` with a version such as `chardet==4.0.0` and list of dependencies in `setup.py` (Be careful not to overwrite any packages that might screw up backwards dependencies for object detection, etc.)
158+
159+
### Code Quality
160+
161+
When creating new functions, please follow the [Google style Python docstrings](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html). See example below:
162+
163+
```python
164+
def example_function(param1: int, param2: str) -> bool:
165+
"""Example function that does something.
166+
167+
Args:
168+
param1: The first parameter.
169+
param2: The second parameter.
170+
171+
Returns:
172+
The return value. True for success, False otherwise.
173+
174+
"""
120175
```
121176

122-
Then, assuming you have installed the `dev` packages (`pip install -e ".[dev]`), you can run the tests
177+
We provide a `Makefile` to format and ensure code quality. **Be sure to run them before creating a PR**.
123178

124179
```bash
180+
# format code with `black` and `isort`
181+
make style
125182

126-
python -m unittest
183+
# check code with flake8
184+
make check_code_quality
127185
```
186+
187+
**Note** These tests will be run automatically when you commit thanks to git hooks.

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
certifi==2021.5.30
1+
certifi==2022.12.7
22
chardet==4.0.0
33
cycler==0.10.0
44
idna==2.10
5-
kiwisolver==1.3.1
5+
kiwisolver>=1.3.1
66
matplotlib
77
numpy>=1.18.5
88
opencv-python>=4.1.2
@@ -12,9 +12,9 @@ python-dateutil
1212
python-dotenv
1313
requests
1414
six
15-
urllib3==1.26.6
15+
urllib3>=1.26.6
1616
wget
1717
tqdm>=4.41.0
1818
PyYAML>=5.3.1
1919
wget
20-
requests_toolbelt
20+
requests_toolbelt

roboflow/__init__.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import json
22
import sys
3+
import time
34

45
import requests
56

67
from roboflow.config import API_URL, APP_URL, DEMO_KEYS
78
from roboflow.core.project import Project
89
from roboflow.core.workspace import Workspace
910

11+
__version__ = "0.2.29"
1012

11-
def check_key(api_key, model, notebook):
13+
14+
def check_key(api_key, model, notebook, num_retries=0):
1215
if type(api_key) is not str:
1316
raise RuntimeError(
1417
"API Key is of Incorrect Type \n Expected Type: "
@@ -26,11 +29,23 @@ def check_key(api_key, model, notebook):
2629
else:
2730
# validate key normally
2831
response = requests.post(API_URL + "/?api_key=" + api_key)
29-
r = response.json()
3032

31-
if "error" in r or response.status_code != 200:
33+
if response.status_code == 401:
3234
raise RuntimeError(response.text)
35+
36+
if response.status_code != 200:
37+
# retry 5 times
38+
if num_retries < 5:
39+
print("retrying...")
40+
time.sleep(1)
41+
num_retries += 1
42+
return check_key(api_key, model, notebook, num_retries)
43+
else:
44+
raise RuntimeError(
45+
"There was an error validating the api key with Roboflow server."
46+
)
3347
else:
48+
r = response.json()
3449
return r
3550
else: # then you're using a dummy key
3651
sys.stdout.write(

0 commit comments

Comments
 (0)