diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index acc0d369fe..d4b6109cf2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -46,8 +46,8 @@ jobs: - name: Black Formatting run: | black --version - black qhub --diff - black --check qhub + black qhub --diff --exclude "qhub/_version.py" + black --check qhub --exclude "qhub/_version.py" - name: Flake8 Formatting run: | flake8 --version diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bb95cdcb3b..800cc196a7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/psf/black - rev: 20.8b1 + rev: 22.3.0 hooks: - id: black exclude: '/qhub/template/' diff --git a/docs/ext/substitute.py b/docs/ext/substitute.py index e0c22ff073..3a63bb023f 100644 --- a/docs/ext/substitute.py +++ b/docs/ext/substitute.py @@ -3,14 +3,16 @@ Simply forces replace of ||QHUB_VERSION|| with the qhub_version_string in conf.py """ + def dosubs(app, docname, source): """ Replace QHUB_VERSION with the qhub version """ - if app.config.qhub_version_string != '': + if app.config.qhub_version_string != "": src = source[0] - source[0] = src.replace('||QHUB_VERSION||', app.config.qhub_version_string) + source[0] = src.replace("||QHUB_VERSION||", app.config.qhub_version_string) + def setup(app): app.connect("source-read", dosubs) - app.add_config_value('qhub_version_string', '', 'env') + app.add_config_value("qhub_version_string", "", "env") diff --git a/environment-dev.yaml b/environment-dev.yaml index f31bdbf9bc..55f12a597a 100644 --- a/environment-dev.yaml +++ b/environment-dev.yaml @@ -11,7 +11,7 @@ dependencies: - python-kubernetes # dev dependencies - flake8 ==3.8.4 - - black ==20.8b1 + - black ==22.3.0 - twine - pytest - diagrams diff --git a/qhub/render.py b/qhub/render.py index 840300300e..4c9b0054ef 100644 --- a/qhub/render.py +++ b/qhub/render.py @@ -163,9 +163,32 @@ def render_contents(config: Dict): } ) + contents.update(gen_gitignore(config)) + return contents +def gen_gitignore(config): + """ + Generate `.gitignore` file. + Add files as needed. + """ + + from inspect import cleandoc + + filestoignore = """ + # ignore terraform state + .terraform + terraform.tfstate + terraform.tfstate.backup + .terraform.tfstate.lock.info + + # python + __pycache__ + """ + return {".gitignore": cleandoc(filestoignore)} + + def gen_cicd(config): """ Use cicd schema to generate workflow files based on the diff --git a/qhub/stages/checks.py b/qhub/stages/checks.py index 30a0e0f546..949b5c620b 100644 --- a/qhub/stages/checks.py +++ b/qhub/stages/checks.py @@ -148,7 +148,7 @@ def _attempt_dns_lookup( attempt = 0 while not _attempt_dns_lookup(domain_name, ip): - sleeptime = 60 * (2 ** attempt) + sleeptime = 60 * (2**attempt) if not disable_prompt: input( f"After attempting to poll the DNS, the record for domain={domain_name} appears not to exist, " diff --git a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/conda-store/config/conda_store_config.py b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/conda-store/config/conda_store_config.py index e47cee6e4c..d49943f1dc 100644 --- a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/conda-store/config/conda_store_config.py +++ b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/conda-store/config/conda_store_config.py @@ -13,9 +13,7 @@ c.CondaStore.default_uid = 1000 c.CondaStore.default_gid = 100 c.CondaStore.default_permissions = "775" -c.CondaStore.conda_included_packages = [ - "ipykernel" -] +c.CondaStore.conda_included_packages = ["ipykernel"] c.S3Storage.internal_endpoint = "${minio-service}:9000" c.S3Storage.internal_secure = False diff --git a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/examples/dashboard_plotly.py b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/examples/dashboard_plotly.py index 49461a1647..cd379cab6e 100644 --- a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/examples/dashboard_plotly.py +++ b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/examples/dashboard_plotly.py @@ -13,26 +13,27 @@ # assume you have a "long-form" data frame # see https://plotly.com/python/px-arguments/ for more options -df = pd.DataFrame({ - "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"], - "Amount": [4, 1, 2, 2, 4, 5], - "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"] -}) +df = pd.DataFrame( + { + "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"], + "Amount": [4, 1, 2, 2, 4, 5], + "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"], + } +) fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group") -app.layout = html.Div(children=[ - html.H1(children='Hello Dash'), - - html.Div(children=''' +app.layout = html.Div( + children=[ + html.H1(children="Hello Dash"), + html.Div( + children=""" Dash: A web application framework for your data. - '''), - - dcc.Graph( - id='example-graph', - figure=fig - ) -]) + """ + ), + dcc.Graph(id="example-graph", figure=fig), + ] +) -if __name__ == '__main__': +if __name__ == "__main__": app.run_server(debug=True) diff --git a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/examples/dashboard_streamlit.py b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/examples/dashboard_streamlit.py index cb07d8d568..b78affa76e 100644 --- a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/examples/dashboard_streamlit.py +++ b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/examples/dashboard_streamlit.py @@ -2,10 +2,9 @@ import numpy as np import pandas as pd -st.title('My first StreamLit QHub app') +st.title("My first StreamLit QHub app") st.write("Here's our first attempt at using data to create a table:") -st.write(pd.DataFrame({ - 'first column': [1, 2, 3, 4], - 'second column': [10, 20, 30, 40] -})) +st.write( + pd.DataFrame({"first column": [1, 2, 3, 4], "second column": [10, 20, 30, 40]}) +) diff --git a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/jupyterhub/02-spawner.py b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/jupyterhub/02-spawner.py index 5ab464c99e..28d19ec567 100644 --- a/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/jupyterhub/02-spawner.py +++ b/qhub/template/stages/07-kubernetes-services/modules/kubernetes/services/jupyterhub/files/jupyterhub/02-spawner.py @@ -32,7 +32,7 @@ c.CDSDashboardsConfig.spawn_default_options = False c.CDSDashboardsConfig.conda_envs = [ - environment['name'] for _, environment in conda_store_environments.items() + environment["name"] for _, environment in conda_store_environments.items() ] else: c.JupyterHub.allow_named_servers = False diff --git a/setup.cfg b/setup.cfg index 4f3e2d7825..b98c9ea1f4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -40,7 +40,7 @@ install_requires = [options.extras_require] dev = flake8==3.8.4 - black==20.8b1 + black==22.3.0 twine pytest pytest-timeout diff --git a/tests/scripts/minikube-loadbalancer-ip.py b/tests/scripts/minikube-loadbalancer-ip.py index e2e1a4ecb5..d7a00e3514 100755 --- a/tests/scripts/minikube-loadbalancer-ip.py +++ b/tests/scripts/minikube-loadbalancer-ip.py @@ -4,13 +4,13 @@ import sys import subprocess -minikube_cmd = ['minikube', 'ssh', '--', 'ip', '-j', 'a'] +minikube_cmd = ["minikube", "ssh", "--", "ip", "-j", "a"] minikube_output = subprocess.check_output(minikube_cmd, encoding="utf-8")[:-1] address = None for interface in json.loads(minikube_output): - if interface['ifname'] == 'eth0': - address = interface['addr_info'][0]['local'].split('.') + if interface["ifname"] == "eth0": + address = interface["addr_info"][0]["local"].split(".") break else: print("minikube interface eth0 not found") diff --git a/tests/test_render.py b/tests/test_render.py index ed86f5e5d6..f34efb0057 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -1,9 +1,11 @@ +import os import pytest +from pathlib import Path from ruamel.yaml import YAML from qhub.render import render_template, set_env_vars_in_config -from .conftest import render_config_partial +from .conftest import render_config_partial, PRESERVED_DIR @pytest.fixture @@ -87,3 +89,31 @@ def test_render_template(write_qhub_config_to_file): assert qhub_config_json["namespace"] == namespace assert qhub_config_json["domain"] == domain assert qhub_config_json["provider"] == cloud_provider + + +def test_exists_after_render(write_qhub_config_to_file): + items_to_check = [ + ".gitignore", + "image", + "stages", + "qhub-config.yaml", + PRESERVED_DIR, + ] + + qhub_config_loc, _ = write_qhub_config_to_file + + yaml = YAML() + qhub_config_json = yaml.load(qhub_config_loc.read_text()) + + # list of files/dirs available after `qhub render` command + ls = os.listdir(Path(qhub_config_loc).parent.resolve()) + + cicd = qhub_config_json.get("ci_cd", {}).get("type", None) + + if cicd == "github-actions": + items_to_check.append(".github") + elif cicd == "gitlab-ci": + items_to_check.append(".gitlab-ci.yml") + + for i in items_to_check: + assert i in ls diff --git a/tests_deployment/test_jupyterhub_ssh.py b/tests_deployment/test_jupyterhub_ssh.py index ecfed3f2ba..0f2e3113e5 100644 --- a/tests_deployment/test_jupyterhub_ssh.py +++ b/tests_deployment/test_jupyterhub_ssh.py @@ -1,4 +1,3 @@ - import re import uuid