Skip to content

Commit

Permalink
Merge pull request #24 from usegalaxy-au/dev
Browse files Browse the repository at this point in the history
Fix pip install cli module
  • Loading branch information
neoformit authored Jan 4, 2025
2 parents 5ee2b32 + 4f79290 commit bd34aa8
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 8 deletions.
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
recursive-include app *
recursive-include labs *
recursive-include utils *
1 change: 1 addition & 0 deletions app/app/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def main():
sys.path.insert(0, str(BASE_DIR))
if len(sys.argv) > 2:
os.environ["LAB_CONTENT_ENTRYPOINT"] = sys.argv[2]
execute_from_command_line(["manage.py", "collectstatic", "--noinput"])
execute_from_command_line(["manage.py", "runserver"])
else:
print(f"Unknown command: {sys.argv[1]}")
Expand Down
16 changes: 16 additions & 0 deletions app/app/settings/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@
f"http://{HOSTNAME}/static/local/{LAB_CONTENT_ENTRYPOINT}")

INSTALLED_APPS.remove('django_light')

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
}

class DisableMigrations:
def __contains__(self, item):
return True

def __getitem__(self, item):
return None

MIGRATION_MODULES = DisableMigrations()
8 changes: 8 additions & 0 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('labs.urls')),
]

if settings.CLI_DEV:
urlpatterns += static(
settings.STATIC_URL,
document_root=settings.STATIC_ROOT,
)

handler400 = 'labs.views.custom_400'
12 changes: 11 additions & 1 deletion app/labs/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
class LabCache:
@classmethod
def get(cls, request):
if request.GET.get('cache', '').lower() == 'false':
if (
request.GET.get('cache', '').lower() == 'false'
or settings.CLI_DEV
):
return

cache_key = cls._generate_cache_key(request)
Expand All @@ -33,12 +36,15 @@ def get(cls, request):

@classmethod
def put(cls, request, body):
if settings.CLI_DEV:
return HttpResponse(body)
logger.debug(
f"Cache PUT for {request.GET.get('content_root', 'root')}")
cache_key = cls._generate_cache_key(request)
timeout = (settings.CACHE_TIMEOUT
if request.GET.get('content_root')
else None) # No timeout for default "Docs Lab" page

cache.set(cache_key, body, timeout=timeout)
response = HttpResponse(body)
response['X-Cache-Status'] = 'MISS'
Expand All @@ -63,13 +69,17 @@ class WebCache:

@classmethod
def get(cls, url):
if settings.CLI_DEV:
return
cache_key = cls._generate_cache_key(url)
data = cache.get(cache_key)
if data:
return data

@classmethod
def put(cls, url, data, timeout=3600):
if settings.CLI_DEV:
return
cache_key = cls._generate_cache_key(url)
cache.set(cache_key, data, timeout=timeout)

Expand Down
8 changes: 5 additions & 3 deletions app/labs/lab_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,16 @@ def html_tags(value: str) -> str:
if "<" not in value:
return value
# Remove self closing tags
value = (
value_stripped = (
re.sub(r'(<.*?/>)|(<img.*?>)', '', value, flags=re.MULTILINE)
.replace('<br>', '')
.replace('<hr>', '')
)
# Enumerate open/close tags
open_tags = re.findall(r'<[^/][\s\S]*?>', value, flags=re.MULTILINE)
close_tags = re.findall(r'</[\s\S]*?>', value, flags=re.MULTILINE)
open_tags = re.findall(
r'<[^/][\s\S]*?>', value_stripped, flags=re.MULTILINE)
close_tags = re.findall(
r'</[\s\S]*?>', value_stripped, flags=re.MULTILINE)
assert len(open_tags) == len(close_tags), (
f'Unclosed HTML tag in section content:\n{value}')
return value
6 changes: 2 additions & 4 deletions app/labs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ def export_lab(request):
an ad hoc basis, where the content would typically be hosted in a GitHub
repo with a YAML file root which is specified as a GET parameter.
"""

if not settings.CLI_DEV:
if response := LabCache.get(request):
return response
if response := LabCache.get(request):
return response

template = 'labs/exported.html'

Expand Down

0 comments on commit bd34aa8

Please sign in to comment.