Skip to content

Commit

Permalink
Merge pull request #103 from andrew-hossack/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
andrew-hossack committed Feb 2, 2023
2 parents c6013ee + 7b8043d commit c10c645
Show file tree
Hide file tree
Showing 45 changed files with 24,172 additions and 307 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ __pycache__
*.egg-info
.pytest_cache

deleteme.py
deleteme.py

/cache/
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ global-include *.html
global-include *.ini
global-include *.ico
global-include *.css
global-include *.svg
global-include *.csv
global-include *.eot
global-include *.tff
Expand All @@ -16,9 +17,11 @@ global-include *.c
global-include *.h
global-include *.sh
global-include *.so
global-include *.jpeg
global-include *.map
global-include *.js
global-include *.ts
global-include *.py
global-include *.template
global-include packages.txt
global-include src/dashtools/assets/*
15 changes: 15 additions & 0 deletions docs/source/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

All notable changes to this project will be documented in this file.

## [1.11.0] - 2023-2-01

### Added & Changed

- Added create page, and the ability to explore between different template previews
- Create templated apps using the `dashtools gui`
- Lots of style changes
- Added links to bottom of screen
- Added github star link
- Fixed some issues with os path not being normalized
- Added `--no-update-check` flag to `dashtools init` to skip PyPi version checking
- Silenced output for gui
- Removed gui threading, seems like this is no longer needed since the start script is fixed (does not run twice)
- Confetti and success notifications

## [1.10.8] - 2023-1-29

### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -- Project information

__version__ = '1.10.8'
__version__ = '1.11.0'

project = 'DashTools'
author = 'Andrew Hossack'
Expand Down
76 changes: 56 additions & 20 deletions src/dashtools/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
# Thanks to https://mike.depalatis.net/blog/simplifying-argparse.html
'''
import argparse
import logging
import os
import sys
import threading
import webbrowser
from contextlib import contextmanager, nullcontext, redirect_stderr, redirect_stdout

from dashtools.cli import update
from dashtools.dashboard import dashboard
Expand All @@ -18,6 +19,21 @@
from dashtools.version import __version__


@contextmanager
def silent_stdout_stderr():
# Set above max level, even failures will not be logged here
logging.getLogger(__name__).disabled = True
old_stdout = sys.stdout
old_stderr = sys.stderr
try:
with open(os.devnull, "w") as fnull:
with redirect_stderr(fnull) as err, redirect_stdout(fnull) as out:
yield (err,out)
finally:
sys.stdout = old_stdout
sys.stderr = old_stderr


class MyArgumentParser(argparse.ArgumentParser):
"""Override default help message"""

Expand All @@ -39,6 +55,8 @@ def print_help(self, file=None):
{'init <app name> [template]':<29}Create a new app
{'--dir, -d':<25}Specify alternative create location
{'--no-update-check':<25}Do not check for PyPi updates on create
{'--silent':<25}Do not display anything to console
{'run':<29}Run the app (experimental)
{'--set-py-cmd <command>':<25}Set the python shell command
Expand Down Expand Up @@ -119,14 +137,15 @@ def docker(args):
cwd=os.getcwd())
else:
print('dashtools: docker: error: Too few arguments')
exit('dashtools: Available docker options: --init [--dir, -d]')
print('dashtools: Available docker options: --init [--dir, -d]')
exit(1)


@ subcommand()
def gui(args):
"""Initialize a new app."""
print('dashtools: Dashboard started on http://127.0.0.1:8050/\ndashtools: Press Ctrl+C to stop')
threading.Thread(target=dashboard.start_dashboard).start()
dashboard.start_dashboard(cwd=os.getcwd())


@ subcommand(
Expand All @@ -142,20 +161,32 @@ def gui(args):
help='Specify the directory to create the app in. Args: REQUIRED: <directory>',
default=os.getcwd(),
metavar='<directory>',
nargs='?')
nargs='?'),
argument(
'--no-update-check',
help='Do not check for PyPi updates if this flag is used.',
default=False,
action="store_true"),
argument(
'--silent',
help='Do not check for PyPi updates if this flag is used.',
default=False,
action="store_true"),
])
def init(args):
"""Initialize a new app."""
if args.dir is None:
print('dashtools: init: No directory specified. Usage Example: dashtools init MyDashApp -d ~/Desktop')
exit('dashtools: init: Failed')
buildApp.create_app(
target_dir=args.dir,
app_name=args.init[0],
template=buildAppUtils.get_template_from_args(args))
print(
f'dashtools: Run your app using the "python {os.path.join(args.init[0], "src", "app.py")}" command')
print(f'dashtools: For an in-depth guide on configuring your app, see https://dash.plotly.com/layout')
with silent_stdout_stderr() if args.silent else nullcontext():
if args.dir is None:
print('dashtools: init: No directory specified. Usage Example: dashtools init MyDashApp -d ~/Desktop')
print('dashtools: init: Failed')
exit(1)
buildApp.create_app(
target_dir=args.dir,
app_name=args.init[0],
template=buildAppUtils.get_template_from_args(args))
print(
f'dashtools: Run your app using the "python {os.path.join(args.init[0], "src", "app.py")}" command')
print(f'dashtools: For an in-depth guide on configuring your app, see https://dash.plotly.com/layout')


@ subcommand(
Expand All @@ -180,7 +211,8 @@ def templates(args):
createTemplate.create_template(src=args.init[0], dest=os.getcwd())
else:
print('dashtools: templates error: too few arguments')
exit('dashtools: Available templates options: --list, --init')
print('dashtools: Available templates options: --list, --init')
exit(1)


@ subcommand(
Expand All @@ -206,8 +238,8 @@ def heroku(args):
deployHeroku.update_heroku_app(os.getcwd(), remote=args.update)
else:
print('dashtools: heroku error: too few arguments')
exit('dashtools: Available heroku options: --deploy, --update')

print('dashtools: Available heroku options: --deploy, --update')
exit(1)

@ subcommand(
[
Expand All @@ -230,8 +262,8 @@ def run(args):
runtimeUtils.run_app(os.getcwd())
except RuntimeError as e:
print(e)
exit('dashtools: run: Failed')

print('dashtools: run: Failed')
exit(1)

def main():
"""
Expand All @@ -247,4 +279,8 @@ def main():
'https://github.com/andrew-hossack/dash-tools/issues/new/choose')
else:
parser.print_help()
update.check_for_updates()
try:
if not args.no_update_check:
update.check_for_updates()
except AttributeError: # --no-update-check not found, this is a workaround
update.check_for_updates()
29 changes: 28 additions & 1 deletion src/dashtools/dashboard/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# NOTIFICATION_DURATION_SECONDS = 8


def render(key: str):
def render(key: str, props: any=None) -> dmc.Notification:
if key == 'FileNotFoundError':
return dmc.Notification(
message="The file path you provided does not exist. Please check your filepath and try again.",
Expand Down Expand Up @@ -59,3 +59,30 @@ def render(key: str):
action='show',
id='error-permissions'
)
elif key == 'ModuleNotFound':
return dmc.Notification(
message=f"You must install module '{props.needs_module}' to preview this app!",
title="Warning",
color='red',
icon=[DashIconify(icon="ep:warning")],
action='show',
id='error-permissions',
)
elif key == 'FileAlreadyExists':
return dmc.Notification(
message=f"File {props.filepath} already exists at this location! Please change app name or create location and try again.",
title="Warning",
color='red',
icon=[DashIconify(icon="ep:warning")],
action='show',
id='error-permissions',
)
elif key == 'AppCreateSuccess':
return dmc.Notification(
message=f"App created successfully!",
title="Success",
color='green',
icon=[DashIconify(icon="ep:success-filled")],
action='show',
id='error-permissions',
)
11 changes: 11 additions & 0 deletions src/dashtools/dashboard/assets/advanced-banner.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/dashtools/dashboard/assets/code.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ code {
.white-link a{
color: white;
}

.padded-bottom p{
padding-bottom: 4px
}
20 changes: 20 additions & 0 deletions src/dashtools/dashboard/assets/confetti_effect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
window.dash_clientside = window.dash_clientside || {};
window.dash_clientside.my_clientside_library = {
confetti_onclick: function (n_clicks) {
confetti({
particleCount: 50,
startVelocity: 25,
spread: 360,
origin: {
x: 0.5,
// since they fall down, start a bit higher than random
y: 0.3,
},
});
// Reset confetti after 5 seconds
setTimeout(() => {
confetti.reset();
}, 5000);
return "foo doesnt matter";
},
};
Loading

0 comments on commit c10c645

Please sign in to comment.