Skip to content

Commit a8b81a9

Browse files
feat: disable some code sections if we are doing local development
1 parent c44c4cb commit a8b81a9

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

ai4papi/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
Manage configurations of the API.
33
"""
44

5+
import os
56
from pathlib import Path
67
from string import Template
78
import subprocess
89

910
import yaml
1011

1112

13+
# Check if we are developing from local, to disable parts of the code that are compute
14+
# intensive (eg. disables calls to Github API)
15+
# The variables 'FORWARDED_ALLOW_IPS' serves as proxy for this, as it is only defined
16+
# when running from the Docker container
17+
IS_DEV = False if os.getenv('FORWARDED_ALLOW_IPS') else True
18+
1219
# Paths
1320
main_path = Path(__file__).parent.absolute()
1421
paths = {

ai4papi/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from fastapi import HTTPException
1010
import requests
1111

12+
import ai4papi.conf as papiconf
13+
1214

1315
# Persistent requests session for faster requests
1416
session = requests.Session()
@@ -191,6 +193,12 @@ def get_github_info(owner, repo):
191193
"""
192194
Retrieve information from a Github repo
193195
"""
196+
# Avoid running this function if were are doing local development, because
197+
# repeatedly calling the Github API will otherwise get you blocked
198+
if papiconf.IS_DEV:
199+
print('[info] Skipping Github API info fetching (development).')
200+
return {}
201+
194202
# Retrieve information from Github API
195203
url = f"https://api.github.com/repos/{owner}/{repo}"
196204
headers = {'Authorization': f'token {github_token}'} if github_token else {}

tests/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
#TODO: move to proper testing package
1111
#TODO: rename test script: modules --> test_modules
1212

13+
import ai4papi.conf as papiconf
14+
15+
16+
# We want to test full functionality, without disabling any parts
17+
papiconf.IS_DEV = False
18+
19+
1320
import catalog.modules
1421
import catalog.tools
1522
import deployments.modules

0 commit comments

Comments
 (0)