Skip to content

Commit

Permalink
Render .gitignore, black py files (#1206)
Browse files Browse the repository at this point in the history
* Render .gitignore

* Render clean .gitignore

* Add unit test

* Upgrade black

* Upgrade black

* black format

* exclude qhub/_version.py from black

* Black what needs blackening

* Fix

* Fix
  • Loading branch information
iameskild authored Mar 29, 2022
1 parent ee5fee7 commit 56ffa7b
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand Down
8 changes: 5 additions & 3 deletions docs/ext/substitute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
2 changes: 1 addition & 1 deletion environment-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- python-kubernetes
# dev dependencies
- flake8 ==3.8.4
- black ==20.8b1
- black ==22.3.0
- twine
- pytest
- diagrams
Expand Down
23 changes: 23 additions & 0 deletions qhub/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qhub/stages/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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]})
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/scripts/minikube-loadbalancer-ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
32 changes: 31 additions & 1 deletion tests/test_render.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion tests_deployment/test_jupyterhub_ssh.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import re
import uuid

Expand Down

0 comments on commit 56ffa7b

Please sign in to comment.