Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SASS for CSS styling + UI improvements #1644

Merged
merged 15 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ docs/env-options.rst
.editorconfig
__pycache__
.pytest_cache
.sass-cache/
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ build_docs:

changelog:
python3 generate_changelog.py

sass_watch:
sass --watch locust/static/sass:locust/static/css

sass_build:
sass --update locust/static/sass:locust/static/css
66 changes: 66 additions & 0 deletions docs/developing-locust-itself.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
=======================================
Developing Locust itself
=======================================

Here's useful information on making changes to Locust.


Running tests
=============

To be able to run Locust's test on different Python versions we use `tox <https://tox.readthedocs.io/en/latest/>`_.
You can install tox by running:

.. code-block:: console

pip install tox

Then you can run the tests by just invoking tox in the Locust project root directory:

.. code-block:: console

tox


Build documentation
===================

To build the documentation you first need to install the required PyPI packages. You can do that by running
the following command in the Locust project's root directory:

.. code-block:: console

pip install -r docs/requirements.txt

Then you can build the documentation locally using:

.. code-block:: console

make build_docs

Then the documentation should be build and available at ``docs/_build/index.html``



Making changes to Locust's Web UI
=================================

The CSS styling for Locust's user interface is written in `SASS <https://sass-lang.com/>`_.
In order to make changes to the CSS rules, you need to have SASS `installed <https://sass-lang.com/install>`_
and available on your ``PATH``.

Once you have SASS installed you can have the command line sass program compile the Locust ``.sass`` files
by running the following in the locust project's root path:

.. code-block:: console

make sass_build


Or you can make sass watch for changes to the ``.sass`` files and automatically generate new CSS files by running:

.. code-block:: console

make sass_watch

The CSS files that are generated by SASS should be checked into version control.
20 changes: 11 additions & 9 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,25 @@ Other functionalities
use-as-lib


API
---
.. toctree ::
:maxdepth: 4

api


Further reading / knowledgebase
-------------------------------

.. toctree ::
:maxdepth: 1


developing-locust-itself
further-reading


API
---
.. toctree ::
:maxdepth: 4

api



Changelog
---------

Expand Down
24 changes: 17 additions & 7 deletions locust/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def render_template(file, **kwargs):
return template.render(**kwargs)


def get_html_report(environment):
def get_html_report(environment, show_download_link=True):
stats = environment.runner.stats

start_ts = stats.start_time
Expand Down Expand Up @@ -42,15 +42,23 @@ def get_html_report(environment):

history = stats.history

static_js = ""
static_js = []
js_files = ["jquery-1.11.3.min.js", "echarts.common.min.js", "vintage.js", "chart.js"]
for js_file in js_files:
path = os.path.join(os.path.dirname(__file__), "static", js_file)
static_js.append("// " + js_file)
with open(path, encoding="utf8") as f:
content = f.read()
static_js += "// " + js_file + "\n"
static_js += content
static_js += "\n\n\n"
static_js.append(f.read())
static_js.extend(["", ""])

static_css = []
css_files = ["tables.css"]
for css_file in css_files:
path = os.path.join(os.path.dirname(__file__), "static", "css", css_file)
static_css.append("/* " + css_file + " */")
with open(path, encoding="utf8") as f:
static_css.append(f.read())
static_css.extend(["", ""])

res = render_template(
"report.html",
Expand All @@ -63,7 +71,9 @@ def get_html_report(environment):
end_time=end_time,
host=host,
history=history,
static_js=static_js,
static_js="\n".join(static_js),
static_css="\n".join(static_css),
show_download_link=show_download_link,
)

return res
2 changes: 1 addition & 1 deletion locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def sig_term_handler():
logger.info("Starting Locust %s" % version)
main_greenlet.join()
if options.html_file:
html_report = get_html_report(environment)
html_report = get_html_report(environment, show_download_link=False)
with open(options.html_file, "w+") as file:
file.write(html_report)
shutdown()
Expand Down
Loading