[tor-commits] [bridgedb] 02/66: Create the build process for the lektor frontend

gitolite role git at cupani.torproject.org
Wed Jul 27 18:32:07 UTC 2022


This is an automated email from the git hooks/post-receive script.

meskio pushed a commit to branch main
in repository bridgedb.

commit fa14423adc207b3cb696da33e754e72fd09c193e
Author: kez <kez at torproject.org>
AuthorDate: Wed Jan 12 13:35:07 2022 -0800

    Create the build process for the lektor frontend
---
 requirements.txt             |  1 +
 scripts/install-dependencies |  2 +-
 setup.py                     | 51 ++++++++++++++++++++++++++++++++++----------
 3 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/requirements.txt b/requirements.txt
index ab12803..5471a17 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -13,3 +13,4 @@ service_identity==21.1.0
 stem==1.8.0
 zope.interface==5.4.0
 numpy==1.20.3
+Lektor==3.3.1
diff --git a/scripts/install-dependencies b/scripts/install-dependencies
index f4a7ab0..f3a0333 100755
--- a/scripts/install-dependencies
+++ b/scripts/install-dependencies
@@ -8,7 +8,7 @@ APT_FLAGS='-q --no-install-suggests --no-install-recommends'
 PIP=$(which pip)
 PIP_FLAGS='--no-binary :all'
 
-DEPENDS="build-essential openssl sqlite3 python3-dev python3-setuptools"
+DEPENDS="build-essential openssl sqlite3 python3-dev python3-setuptools gettext"
 DEPENDS="${DEPENDS} libgeoip-dev tor-geoipdb libjpeg-dev"
 HERE=$(dirname $0)
 
diff --git a/setup.py b/setup.py
index 74b6254..fa5621a 100644
--- a/setup.py
+++ b/setup.py
@@ -17,6 +17,7 @@ from __future__ import print_function
 import os
 import setuptools
 import sys
+from subprocess import Popen
 
 from glob import glob
 
@@ -157,6 +158,39 @@ def get_supported_langs():
 
     return lang_dirs, lang_files
 
+def build_lektor_frontend() -> None:
+    """Build the lektor project, and copy the files to the template directory.
+
+    :rtype: None
+    """
+
+    # the lektor frontend was already built, we don't need to waste cycles
+    if sys.argv[1] == 'install':
+        return
+
+    frontend_build = Popen(
+        ['/usr/bin/env', 'bash', 'frontend/build.sh', 'prod'],
+    )
+    frontend_build.wait()
+    template_path = os.path.join(
+        'bridgedb',
+        'distributors',
+        'https',
+        'templates',
+    )
+
+    public_path_prefix = os.path.join('frontend', 'public')
+
+    for root, dirs, files in os.walk(public_path_prefix):
+        stripped_root = root.lstrip(public_path_prefix)
+        os.makedirs(os.path.join(template_path, stripped_root), exist_ok=True)
+        for file_name in files:
+            file_path = os.path.join(root, file_name)
+            os.replace(
+                file_path,
+                os.path.join(template_path, stripped_root, file_name),
+            )
+
 def get_template_files():
     """Return the paths to any web resource files to include in the package.
 
@@ -164,21 +198,16 @@ def get_template_files():
     :returns: Any files in :attr:`repo_templates` which match one of the glob
         patterns in :ivar:`include_patterns`.
     """
+    build_lektor_frontend()
+
     include_patterns = ['*.html',
                         '*.txt',
-                        '*.asc',
-                        'assets/*.png',
-                        'assets/*.svg',
-                        'assets/css/*.css',
-                        'assets/font/*.woff',
-                        'assets/font/*.ttf',
-                        'assets/font/*.svg',
-                        'assets/font/*.eot',
-                        'assets/js/*.js',
-                        'assets/images/*.svg',
-                        'assets/images/*.ico']
+                        '*.asc']
     template_files = []
 
+    for root, _, files in os.walk(os.path.join(repo_templates, 'assets')):
+        template_files.extend(os.path.join(root, filename) for filename in files)
+
     for include_pattern in include_patterns:
         pattern = os.path.join(repo_templates, include_pattern)
         matches = glob(pattern)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tor-commits mailing list