Skip to content

Commit

Permalink
Add fallback to npm-less installs
Browse files Browse the repository at this point in the history
Most of the times, we don't care about the CSS and JavaScript.
When launching author-mode, if the minified scripts are not found and
the user does not have the npm modules installed, propose to fetch from
the latest release and patch the repo with the minified scripts.

Signed-off-by: Jorge Marques <[email protected]>
  • Loading branch information
gastmaier committed May 31, 2024
1 parent 119e61f commit 7ed1732
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 21 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ reinstalling.
Also extends Author Mode to watch changes on the webpage source code
(use `--dev`/`-r` option to enable this).

Before getting started, install `npm`.
It is required due to the web scripts (`js modules`) and style sheets (`sass`).
### Install the web compiler

If you care about the web scripts (`js modules`) and style sheets (`sass`),
install `npm` first, if not, just skip this section.

> **_NOTE:_** If the ``npm`` provided by your package manager is too old and
> updating with `npm install npm -g` fails, consider installing with
> [NodeSource](https://github.com/nodesource/distributions).
At this path, install the `npm` dependencies locally:
At the repository root, install the `npm` dependencies locally:
```
npm install rollup \
@rollup/plugin-terser \
Expand All @@ -74,11 +76,15 @@ npm install rollup \
--save-dev
```

### Fetch third-party resources

Fetch third-party fonts:
```
./ci/fetch-fonts.sh
```

### Install the repository

Finally, do a symbolic install of this repo:
```
pip install -e . --upgrade
Expand Down
73 changes: 60 additions & 13 deletions adi_doctools/cli/author_mode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from os import path, listdir, remove
from os import path, listdir, remove, mkdir
from os import pardir, killpg, getpgid
from shutil import copy
import click
Expand All @@ -11,8 +11,12 @@
'inv_bdir': "Could not find BUILDDIR {}.",
'inv_srcdir': "Could not find SOURCEDIR {}.",
'no_selenium': "Package 'selenium' is not installed, pooling enabled.",
'rollup': "Couldn't find {}, ensure this a symbolic install",
'node': "Couldn't find {}, please you install the npm tools locally."
'rollup': "Couldn't find {}, ensure this a symbolic install.",
'node': "Couldn't find {}, please install the npm tools locally.",
'comp': "Couldn't find the minified web files ",
'no_npm': "and the npm tools are not installed.",
'with_npm': "run with the --just-regen flag (npm detected).",
'fetch': "Do you want to fetch from the release?"
}

# Hall of shame of poorly managed artifacts
Expand Down Expand Up @@ -41,7 +45,7 @@
'-r',
is_flag=True,
default=False,
help="Watch source code (requires symbolic install)."
help="Watch web source code (requires symbolic install)."
)
@click.option(
'--no-selenium',
Expand All @@ -54,7 +58,7 @@
'-g',
is_flag=True,
default=False,
help="Just regenerate minified files and exit."
help="Just regenerate the web minified files and exit."
)
def author_mode(directory, port, dev, no_selenium, just_regen):
"""
Expand Down Expand Up @@ -91,17 +95,61 @@ def dir_assert(file, msg):
else:
return False

source_files = {'app.umd.js', 'app.umd.js.map', 'style.min.css',
'style.min.css.map'}

def fetch_compiled(path_):
req = path.join(path_, 'docs', 'requirements.txt')
dist = path.join(path_, '.dist')
file = "adi_doctools.tar.gz"

f = open(req, 'r')
for line in f:
if 'adi-doctools' in line:
break
f.close()

from urllib.request import urlretrieve
from shutil import rmtree
if not path.isdir(dist):
mkdir(dist)
urlretrieve(line, path.join(dist, file))
subprocess.call(f"tar -xf {file}",
shell=True, cwd=dist)
remove(path.join(dist, file))
for d in listdir(dist):
break
base = path.join('adi_doctools', 'theme', 'cosmic', 'static')
for f in source_files:
src = path.join(dist, d, base, f)
dest = path.join(path_, base, f)
copy(src, dest)
rmtree(dist)
click.echo("Success fetching the pre-compiled files!")

src_dir = path.abspath(path.join(path.dirname(__file__), pardir))
par_dir = path.abspath(path.join(src_dir, pardir))
rollup_bin = path.join(par_dir, 'node_modules', '.bin', 'rollup')
rollup_conf = path.join(par_dir, 'ci', 'rollup.config.app.mjs')
if just_regen or dev:
src_dir = path.join(path.dirname(path.abspath(__file__)), pardir)
par_dir = path.abspath(path.join(src_dir, pardir))

rollup_conf = path.join(par_dir, 'ci', 'rollup.config.app.mjs')
rollup_bin = path.join(par_dir, 'node_modules', '.bin', 'rollup')

if symbolic_assert(rollup_conf, log['rollup'].format(rollup_conf)):
return
if symbolic_assert(rollup_bin, log['node'].format(rollup_bin)):
return
else:
compiled = path.join(src_dir, 'theme', 'cosmic', 'static')
compiled = path.abspath(path.join(compiled, 'app.umd.js'))
if not path.isfile(compiled):
if symbolic_assert(rollup_bin, log['comp'] + log['no_npm']):
pass
else:
click.echo(log['comp'] + log['with_npm'])
return
if click.confirm(log['fetch']):
if fetch_compiled(par_dir):
return
else:
return

if just_regen:
subprocess.call(f"{rollup_bin} -c {rollup_conf}",
Expand Down Expand Up @@ -144,8 +192,7 @@ def dir_assert(file, msg):
watch_file_src = {}
watch_file_rst = {}
if dev:
source_files = ['app.umd.js', 'app.umd.js.map', 'style.min.css',
'style.min.css.map', 'icons.svg']
source_files.add('icons.svg')
w_files = []
# Check if minified files exists, if not, run rollup once
rollup_cache = True
Expand Down
3 changes: 0 additions & 3 deletions adi_doctools/cli/hdl_gen.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import TypedDict, Dict, List

import click
import subprocess
import re
Expand All @@ -10,7 +8,6 @@
from ..parser.hdl import resolve_hdl_regmap
from ..parser.hdl import expand_hdl_regmap
from ..parser.hdl import parse_hdl_vendor
from ..parser.hdl import parse_hdl_library
from ..writer.hdl import write_hdl_regmap


Expand Down
11 changes: 9 additions & 2 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ reinstalling.
Also extends Author Mode to watch changes on the webpage source code
(use `--dev`/`-r` option to enable this).

Before getting started, install `npm`.
It is required due to the web scripts (`js modules`) and style sheets (`sass`).
Install the web compiler
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you care about the web scripts (`js modules`) and style sheets (`sass`),
install ``npm`` first, if not, just skip this section.

.. note::

Expand All @@ -84,13 +87,17 @@ At the repository root, install the `npm` dependencies locally:
sass \
--save-dev
Fetch third-party resources
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fetch third-party fonts:

.. code::
./ci/fetch-fonts.sh
Install the repository
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Finally, do a symbolic install of this repo:

Expand Down

0 comments on commit 7ed1732

Please sign in to comment.