diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..42ce786 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,36 @@ +name: Publish Release + +on: + release: + types: [published] + +jobs: + build-and-publish: + name: Build and publish dash-bootstrap-templates to PyPI and TestPyPI + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Python 3.9 + uses: actions/setup-python@v1 + with: + python-version: 3.9 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install . build + + - name: Build package + run: python -m build --sdist --wheel --outdir dist/ + + # - name: Publish dash-bootstrap-templates to TestPyPI + # uses: pypa/gh-action-pypi-publish@v1.4.2 + # with: + # password: ${{ secrets.TEST_PYPI_API_TOKEN }} + # repository_url: https://test.pypi.org/legacy/ + + # - name: Publish dash-bootstrap-templates to PyPI + # uses: pypa/gh-action-pypi-publish@v1.4.2 + # with: + # password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a408548 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# python build artifacts +__pycache__ +*.egg-info +.ipynb_checkpoints +build +dist +venv +.idea \ No newline at end of file diff --git a/_create_templates.py b/_create_templates.py index ccd504c..710c9db 100644 --- a/_create_templates.py +++ b/_create_templates.py @@ -430,10 +430,9 @@ def try_build_plotly_template_from_bootstrap_css_path(css_url): Generate Templates """ - # set relative path PATH = pathlib.Path(__file__).parent -TEMPLATES_PATH = PATH.joinpath("./templates").resolve() +TEMPLATES_PATH = PATH.joinpath("./src/dash_bootstrap_templates/templates").resolve() # Creates all templates and save them as json files diff --git a/dash_bootstrap_templates.py b/dash_bootstrap_templates.py deleted file mode 100644 index e80b4ad..0000000 --- a/dash_bootstrap_templates.py +++ /dev/null @@ -1,44 +0,0 @@ -""" -Use this function to make the bootstrap figure templates available in your Dash app - -""" - - -def load_figure_template(themes='bootstrap'): - """Add figure template to plotly.io and sets the default template - - Keyword arguments: - themes -- may be a string or list of strings. (Default "bootstrap") - The string is the lowercase name of a Bootstrap theme - built in _create_templates.py - - The plotly.io.templates.default will be the first theme if - themes is a list. If the themes attribute is invalid, the - "bootstrap" theme will be used. - """ - - import json - import pathlib - import plotly.io as pio - - # set relative path - PATH = pathlib.Path(__file__).parent - TEMPLATES_PATH = PATH.joinpath("./templates").resolve() - - def read_template(theme): - try: - with open(TEMPLATES_PATH.joinpath(f"{theme}.json"), "r") as f: - template = json.load(f) - except IOError: - with open(TEMPLATES_PATH.joinpath("bootstrap.json"), "r") as f: - template = json.load(f) - pio.templates[theme] = template - - if type(themes) is list: - for theme in themes: - read_template(theme) - pio.templates.default = themes[0] - - else: - read_template(themes) - pio.templates.default = themes diff --git a/demo_quickstart.py b/examples/demo_quickstart.py similarity index 100% rename from demo_quickstart.py rename to examples/demo_quickstart.py diff --git a/demo_template_vs_default.py b/examples/demo_template_vs_default.py similarity index 100% rename from demo_template_vs_default.py rename to examples/demo_template_vs_default.py diff --git a/dl_demo_4figures.py b/examples/dl_demo_4figures.py similarity index 100% rename from dl_demo_4figures.py rename to examples/dl_demo_4figures.py diff --git a/img.png b/img.png deleted file mode 100644 index cfdfaaf..0000000 Binary files a/img.png and /dev/null differ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cac5c98 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[build-system] +build-backend = "setuptools.build_meta" +requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"] + +[tool.setuptools_scm] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..7d1fbd3 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,41 @@ + +[metadata] +name = dash-bootstrap-templates +description = A collection of Plotly figure templates with a Bootstrap theme +long_description = file: README.md +long_description_content_type = text/markdown +license = MIT +author = AnnMarieW +# author_email = +url = https://github.com/AnnMarieW/dash-bootstrap-templates +classifiers = + Development Status :: 3 - Alpha + Framework :: Dash + License :: OSI Approved :: MIT License + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Topic :: Scientific/Engineering :: Visualization + +[options] +package_dir= + =src +packages=find: +include_package_data = True +install_requires = + dash + dash-bootstrap-components + importlib_metadata>=3.4.0,<4.0.0; python_version == "3.7" + importlib_resources>=5.1.0,<6.0.0; python_version < "3.9" + numpy + +[options.packages.find] +where = src + +[options.package_data] +dash_bootstrap_templates = templates/*.json + +[options.extras_require] +dev = + tinycss2 + spectra diff --git a/src/dash_bootstrap_templates/__init__.py b/src/dash_bootstrap_templates/__init__.py new file mode 100644 index 0000000..215806c --- /dev/null +++ b/src/dash_bootstrap_templates/__init__.py @@ -0,0 +1,66 @@ +import json + +import plotly.io as pio + +try: + from importlib.resources import files +except ImportError: + # if using Python 3.8 or lower import from the backport + from importlib_resources import files + +try: + from importlib.metadata import ( + PackageNotFoundError, + version, + ) +except ModuleNotFoundError: + # if using Python 3.7, import from the backport + from importlib_metadata import ( + PackageNotFoundError, + version, + ) + +try: + __version__ = version("dash_bootstrap_templates") +except PackageNotFoundError: + # package is not installed + pass +""" +Use this function to make the bootstrap figure templates available in your Dash app +""" + + +def read_template(theme): + try: + with ( + files("dash_bootstrap_templates") / "templates" / f"{theme}.json" + ).open() as f: + template = json.load(f) + except IOError: + with ( + files("dash_bootstrap_templates") / "templates" / "bootstrap.json" + ).open() as f: + template = json.load(f) + pio.templates[theme] = template + + +def load_figure_template(themes="bootstrap"): + """Add figure template to plotly.io and sets the default template + + Keyword arguments: + themes -- may be a string or list of strings. (Default "bootstrap") + The string is the lowercase name of a Bootstrap theme + built in _create_templates.py + + The plotly.io.templates.default will be the first theme if + themes is a list. If the themes attribute is invalid, the + "bootstrap" theme will be used. + """ + if type(themes) is list: + for theme in themes: + read_template(theme) + pio.templates.default = themes[0] + + else: + read_template(themes) + pio.templates.default = themes diff --git a/templates/bootstrap.json b/src/dash_bootstrap_templates/templates/bootstrap.json similarity index 100% rename from templates/bootstrap.json rename to src/dash_bootstrap_templates/templates/bootstrap.json diff --git a/templates/cerulean.json b/src/dash_bootstrap_templates/templates/cerulean.json similarity index 100% rename from templates/cerulean.json rename to src/dash_bootstrap_templates/templates/cerulean.json diff --git a/templates/cosmo.json b/src/dash_bootstrap_templates/templates/cosmo.json similarity index 100% rename from templates/cosmo.json rename to src/dash_bootstrap_templates/templates/cosmo.json diff --git a/templates/cyborg.json b/src/dash_bootstrap_templates/templates/cyborg.json similarity index 100% rename from templates/cyborg.json rename to src/dash_bootstrap_templates/templates/cyborg.json diff --git a/templates/darkly.json b/src/dash_bootstrap_templates/templates/darkly.json similarity index 100% rename from templates/darkly.json rename to src/dash_bootstrap_templates/templates/darkly.json diff --git a/templates/flatly.json b/src/dash_bootstrap_templates/templates/flatly.json similarity index 100% rename from templates/flatly.json rename to src/dash_bootstrap_templates/templates/flatly.json diff --git a/templates/journal.json b/src/dash_bootstrap_templates/templates/journal.json similarity index 100% rename from templates/journal.json rename to src/dash_bootstrap_templates/templates/journal.json diff --git a/templates/litera.json b/src/dash_bootstrap_templates/templates/litera.json similarity index 100% rename from templates/litera.json rename to src/dash_bootstrap_templates/templates/litera.json diff --git a/templates/lumen.json b/src/dash_bootstrap_templates/templates/lumen.json similarity index 100% rename from templates/lumen.json rename to src/dash_bootstrap_templates/templates/lumen.json diff --git a/templates/lux.json b/src/dash_bootstrap_templates/templates/lux.json similarity index 100% rename from templates/lux.json rename to src/dash_bootstrap_templates/templates/lux.json diff --git a/templates/materia.json b/src/dash_bootstrap_templates/templates/materia.json similarity index 100% rename from templates/materia.json rename to src/dash_bootstrap_templates/templates/materia.json diff --git a/templates/minty.json b/src/dash_bootstrap_templates/templates/minty.json similarity index 100% rename from templates/minty.json rename to src/dash_bootstrap_templates/templates/minty.json diff --git a/templates/pulse.json b/src/dash_bootstrap_templates/templates/pulse.json similarity index 100% rename from templates/pulse.json rename to src/dash_bootstrap_templates/templates/pulse.json diff --git a/templates/sandstone.json b/src/dash_bootstrap_templates/templates/sandstone.json similarity index 100% rename from templates/sandstone.json rename to src/dash_bootstrap_templates/templates/sandstone.json diff --git a/templates/simplex.json b/src/dash_bootstrap_templates/templates/simplex.json similarity index 100% rename from templates/simplex.json rename to src/dash_bootstrap_templates/templates/simplex.json diff --git a/templates/sketchy.json b/src/dash_bootstrap_templates/templates/sketchy.json similarity index 100% rename from templates/sketchy.json rename to src/dash_bootstrap_templates/templates/sketchy.json diff --git a/templates/slate.json b/src/dash_bootstrap_templates/templates/slate.json similarity index 100% rename from templates/slate.json rename to src/dash_bootstrap_templates/templates/slate.json diff --git a/templates/solar.json b/src/dash_bootstrap_templates/templates/solar.json similarity index 100% rename from templates/solar.json rename to src/dash_bootstrap_templates/templates/solar.json diff --git a/templates/spacelab.json b/src/dash_bootstrap_templates/templates/spacelab.json similarity index 100% rename from templates/spacelab.json rename to src/dash_bootstrap_templates/templates/spacelab.json diff --git a/templates/superhero.json b/src/dash_bootstrap_templates/templates/superhero.json similarity index 100% rename from templates/superhero.json rename to src/dash_bootstrap_templates/templates/superhero.json diff --git a/templates/united.json b/src/dash_bootstrap_templates/templates/united.json similarity index 100% rename from templates/united.json rename to src/dash_bootstrap_templates/templates/united.json diff --git a/templates/yeti.json b/src/dash_bootstrap_templates/templates/yeti.json similarity index 100% rename from templates/yeti.json rename to src/dash_bootstrap_templates/templates/yeti.json