The user interface template module for LitePolis
Project description
Building a LitePolis UI Module with a React Frontend and Automated Deployment
This tutorial will guide you through the process of creating a LitePolis UI module that utilizes a React.js frontend. We'll also demonstrate how to use GitHub Actions to automate the build and publishing process.
Prerequisites
- Basic understanding of Python and React.js.
- Node.js and npm (or yarn) installed on your development machine.
- A GitHub account.
Step 1: Setting Up the Project Structure
This template provides the basic structure for your LitePolis UI module. Here's a quick overview of the key files and directories:
setup.py: Contains metadata about your Python package.litepolis_ui_template/: This directory will be renamed to your actual package name (e.g.,litepolis_ui_my_awesome_ui).core.py: Contains the core logic for serving your UI's static files and defines theDEFAULT_CONFIG.static/: This directory will hold the static files of your React application.
tests/: Contains tests for your module.app/: This directory contains the source code for your React.js frontend.package.json: Defines the dependencies and build scripts for your React app.src/: Contains the React application's source code (e.g.,index.js).public/: Contains theindex.html.
Step 2: Developing Your React Frontend
The frontend for this LitePolis UI module is built using React. You can find the source code in the app/ directory.
app/package.json: This file lists the necessary dependencies for your React application, includingreact,react-dom, andreact-scripts. It also defines thestartandbuildscripts.app/src/index.js: This is the entry point for your React application. In this example, it renders a simple "Hello, world" message.
You can develop your React application as you normally would within the app/ directory. To start a development server (if needed), you can navigate to the app/ directory in your terminal and run:
cd app
npm start
Step 3: Building Your React Frontend for Production
Before deploying your LitePolis UI module, you need to build your React application into static files. To do this, navigate to the app/ directory in your terminal and run:
cd app
npm run build
Step 4: Integrating the React Frontend into the LitePolis UI Module
Now, you need to integrate the built React application into your LitePolis UI module so that it can be served.
-
Copy the
builddirectory contents: After runningnpm run buildin theapp/directory, copy the entire contents of theapp/builddirectory into thelitepolis_ui_template/static/directory (or your renamed package'sstatic/directory).Your directory structure should now look something like this:
litepolis-ui-my-awesome-ui/ ├── litepolis_ui_my_awesome_ui/ │ ├── core.py │ └── static/ │ ├── index.html │ ├── asset-manifest.json │ ├── favicon.ico │ ├── robots.txt │ ├── static/ │ │ ├── css/ │ │ └── js/ │ └── ... (other built assets) ├── app/ │ ├── ... ├── tests/ │ └── test_core.py └── setup.py -
Ensure
core.pyis configured to serve static files: Thecore.pyfile in your package should already be set up to serve static files from thestatic/directory. Verify that it looks similar to this:from fastapi import FastAPI from fastapi.staticfiles import StaticFiles app = FastAPI() app.mount("/static", StaticFiles(directory="static"), name="static")
Step 5: Configuring Your Python Package (setup.py)
Make sure to update the setup.py file with the correct information for your UI module, including the name (remember the litepolis-ui- prefix), version, description, etc.
Step 6: Automating Build and Publish with GitHub Actions
This template includes a GitHub Actions workflow (python-publish.yml) to automate the process of building your React application and publishing your LitePolis UI module to PyPI when you create a new release on GitHub.
name: Build: Navigates to theapp/directory and builds the React app usingnpm run build. The output will be in theapp/builddirectory we will move it to<litepolis_package_name>/static.
By following these steps, you can effectively build a LitePolis UI module with a React frontend and leverage GitHub Actions for automated build and deployment. Remember to replace placeholders with your actual project details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file litepolis_ui_example-0.0.1.tar.gz.
File metadata
- Download URL: litepolis_ui_example-0.0.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
894c2047b519d6fc1d2587a15d5acfc83aa9335f86349aaf887f19f2496263d4
|
|
| MD5 |
16e5fd5f70e5c79965386f0d5cac2f48
|
|
| BLAKE2b-256 |
74e55b8e09cb23de51c6e39228a514715cea507ecf5d144efc019ec9e4294f99
|
Provenance
The following attestation bundles were made for litepolis_ui_example-0.0.1.tar.gz:
Publisher:
python-publish.yml on NewJerseyStyle/LitePolis-ui-example
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litepolis_ui_example-0.0.1.tar.gz -
Subject digest:
894c2047b519d6fc1d2587a15d5acfc83aa9335f86349aaf887f19f2496263d4 - Sigstore transparency entry: 191357648
- Sigstore integration time:
-
Permalink:
NewJerseyStyle/LitePolis-ui-example@89cff9bc5d0e04b0febf9353e3a9693b0c582633 -
Branch / Tag:
refs/tags/example - Owner: https://github.com/NewJerseyStyle
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@89cff9bc5d0e04b0febf9353e3a9693b0c582633 -
Trigger Event:
release
-
Statement type:
File details
Details for the file litepolis_ui_example-0.0.1-py3-none-any.whl.
File metadata
- Download URL: litepolis_ui_example-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b14feb2123448477e1588902c37a54229da829b8aaaaa8ad6ea217409aacdbd
|
|
| MD5 |
e42e0e495a5b82f0bbe9d7e336993ed9
|
|
| BLAKE2b-256 |
7722797e76e84d47a0994bb2f74bd09c9188d4417675bbf2863004852773ba51
|
Provenance
The following attestation bundles were made for litepolis_ui_example-0.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on NewJerseyStyle/LitePolis-ui-example
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litepolis_ui_example-0.0.1-py3-none-any.whl -
Subject digest:
7b14feb2123448477e1588902c37a54229da829b8aaaaa8ad6ea217409aacdbd - Sigstore transparency entry: 191357653
- Sigstore integration time:
-
Permalink:
NewJerseyStyle/LitePolis-ui-example@89cff9bc5d0e04b0febf9353e3a9693b0c582633 -
Branch / Tag:
refs/tags/example - Owner: https://github.com/NewJerseyStyle
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@89cff9bc5d0e04b0febf9353e3a9693b0c582633 -
Trigger Event:
release
-
Statement type: