diff --git a/.gitignore b/.gitignore index 0c9b6f55651c..d133ed2bfc9f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ *.vi *.zip *~ +*.pyc # OS or Editor folders ._* @@ -41,3 +42,5 @@ Thumbs.db /dist-sass/ /js/coverage/ /node_modules/ +build/lib/ +*.egg-info/ \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 000000000000..ba28c7fdf616 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-include dist * \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000000..aaf912b0145e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,26 @@ +[build-system] +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "bootstrap" +dynamic = ["version"] +description = "A wrapper to distribute Bootstrap via a python package" +readme = "README.md" +requires-python = ">=3.7" +license = { text = "MIT" } +authors = [ + { name = "Mark Otto", email = "markdotto@gmail.com" }, + { name = "Jacob Thornton", email = "jacobthornton@gmail.com" } +] + +[tool.setuptools.dynamic] +version = { attr = "bootstrap.__version__" } + +[project.urls] +Homepage = "https://github.com/twbs/bootstrap" + +[tool.setuptools] +packages = ["bootstrap", "bootstrap.dist"] +package-dir = { "bootstrap" = "python", "bootstrap.dist" = "dist" } +include-package-data = true diff --git a/python/__init__.py b/python/__init__.py new file mode 100644 index 000000000000..10b446c1d7da --- /dev/null +++ b/python/__init__.py @@ -0,0 +1,17 @@ +""" +Load the package.json to get the current version of the package for the installer +""" + +import json +from pathlib import Path + +try: + # Loading package.json + package_json_path = Path(__file__).parent.parent / "package.json" + with package_json_path.open(encoding="utf-8") as f: + data = json.load(f) + + # to get current version + __version__ = data["version"] +except Exception as e: # pylint: disable=broad-exception-caught + __version__ = "0.0.0" diff --git a/site/content/docs/5.3/getting-started/download.md b/site/content/docs/5.3/getting-started/download.md index e15cb9860c84..79518a04bdaa 100644 --- a/site/content/docs/5.3/getting-started/download.md +++ b/site/content/docs/5.3/getting-started/download.md @@ -146,3 +146,32 @@ Install-Package bootstrap ```powershell Install-Package bootstrap.sass ``` + +### Python + +Bootstrap is now installable as a Python package, allowing you to integrate the compiled Bootstrap assets directly into your Python projects. Installation via pip is now supported: + +```sh +pip install git+https://github.com/twbs/bootstrap.git +``` + +After installation, the Bootstrap assets (CSS and JS files) are embedded as package data and can be served directly in your Python web application. For example, in a FastAPI app you can serve these static assets under the `/bootstrap` URL path: + +```python +from fastapi import FastAPI +from fastapi.staticfiles import StaticFiles +from pathlib import Path +import importlib.metadata + +app = FastAPI() + +# Retrieve the distribution information for the 'bootstrap' package. +dist = importlib.metadata.distribution("bootstrap") + +# Locate the static assets installed as package data. +static_path = Path(dist.locate_file("bootstrap/dist")) + +app.mount("/bootstrap", StaticFiles(directory=str(static_path)), name="bootstrap") +``` + +In this configuration, you can access Bootstrap's CSS at `/bootstrap/css/bootstrap.min.css` and JavaScript at `/bootstrap/js/bootstrap.bundle.min.js` in your application.