Skip to content

Commit 4e545d7

Browse files
authored
Merge pull request #177 from man-group/prettier-formatting
Apply Black formatting to Python and Prettier formatting to JS code.
2 parents fe423c9 + a9a68c7 commit 4e545d7

24 files changed

+368
-387
lines changed

.circleci/config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ commands:
8989
command: |
9090
pushd $YARN_STATIC_DIR
9191
yarn run lint
92+
yarn run format
9293
- run:
9394
name: Check for JS Formatting Diffs
9495
command: |
@@ -109,7 +110,7 @@ commands:
109110
command: |
110111
virtualenv ci
111112
. ci/bin/activate
112-
pip install six lxml flake8 tox pytest black .[test]
113+
pip install six lxml flake8 tox pytest black==22.8.0 .[test]
113114
pip install --editable .
114115
# Save dependency cache
115116
- save_cache:
@@ -130,7 +131,8 @@ commands:
130131
then
131132
echo "Black worked fine."
132133
else
133-
echo "Black found differences!"; exit $?
134+
echo "Black found differences!"
135+
exit 1
134136
fi
135137
# Test
136138
- run:

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
0.6.1 (2023-02-26)
1+
0.6.2 (2024-05-xx)
2+
------------------
3+
* Chore: Applying & enforcing Black and Prettier to Python and JS code, respectively. Setting Black version to 22.8.0 for CircleCI.
4+
5+
0.6.1 (2024-02-26)
26
------------------
37
* Feature: GridFS document storage in Mongo-backed instances is now sharded if the mongo server supports it.
48
* Bugfix: None will stop appearing at the top of reports with nbconvert>7.0.0

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ In pull requests please:
1010
* update the changelog (create a new version if there is no release candidate)
1111

1212
Please make sure that you have
13-
run [Black](https://black.readthedocs.io/en/stable/), [mypy](http://mypy-lang.org/),
14-
and [flake8](https://flake8.pycqa.org/en/latest/) before you submit your changes.
15-
The build will fail for flake8 and Black changes.
13+
run [Black](https://black.readthedocs.io/en/stable/) with `-l 120`, [mypy](http://mypy-lang.org/),
14+
and [flake8](https://flake8.pycqa.org/en/latest/) before you submit your changes. Please run `yarn format` to format the javascript code.
15+
The build will fail for flake8, Black, and Prettier changes.
1616
PRs without a test will almost certainly be rejected.
1717
Do also make sure to run the webapp and make sure you haven't broken anything.
1818

notebooker/execute_notebook.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ def run_report(
169169
mailfrom=None,
170170
is_slideshow=False,
171171
):
172-
173172
job_id = job_id or str(uuid.uuid4())
174173
stop_execution = os.getenv("NOTEBOOKER_APP_STOPPING")
175174
if stop_execution:

notebooker/serialization/mongo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ def enable_sharding(self):
116116
conn = self.get_mongo_connection()
117117
try:
118118
conn.admin.command("enableSharding", self.database_name)
119-
conn.admin.command({"shardCollection": f"{self.database_name}.notebook_data.chunks",
120-
"key": {"files_id": 1, "n": 1}})
119+
conn.admin.command(
120+
{"shardCollection": f"{self.database_name}.notebook_data.chunks", "key": {"files_id": 1, "n": 1}}
121+
)
121122
logger.info(f"Successfully sharded GridFS collection for {self.database_name}")
122123
except pymongo.errors.OperationFailure:
123124
logger.error(f"Could not shard {self.database_name}. Continuing.")

notebooker/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def copy_existing(cls, existing: "BaseConfig"):
4141

4242
@classmethod
4343
def from_superset_kwargs(cls, kwargs: dict):
44-
""" When we have too many kwargs but we want to use a subset containing the fields. """
44+
"""When we have too many kwargs but we want to use a subset containing the fields."""
4545
return cls(**{k: v for (k, v) in kwargs.items() if k in cls.__dataclass_fields__})
4646

4747

notebooker/utils/conversion.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ def ipython_to_html(
3838
template_filename = "notebooker_html_output.tpl"
3939
else:
4040
template_filename = "notebooker_html_output_deprecated.tpl"
41-
c.HTMLExporter.template_file = pkg_resources.resource_filename(
42-
__name__, f"../nbtemplates/{template_filename}"
43-
)
41+
c.HTMLExporter.template_file = pkg_resources.resource_filename(__name__, f"../nbtemplates/{template_filename}")
4442

4543
c.HTMLExporter.exclude_input = hide_code
4644
c.HTMLExporter.exclude_input_prompt = hide_code

notebooker/web/routes/serve_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _render_results(job_id: str, report_name: str, result: NotebookResultBase) -
6767
all_reports=get_all_possible_templates(),
6868
readonly_mode=current_app.config["READONLY_MODE"],
6969
scheduler_disabled=current_app.config["DISABLE_SCHEDULER"],
70-
**urls
70+
**urls,
7171
)
7272

7373

notebooker/web/static/.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"printWidth": 120,
3+
"tabWidth": 4
4+
}
Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,74 @@
11
$(document).ready(() => {
22
$.ajax({
3-
url: '/core/version',
3+
url: "/core/version",
44
success: (result) => {
5-
$('#versionTitle').text("v" + result.version);
6-
$('#versionTitle').show();
5+
$("#versionTitle").text("v" + result.version);
6+
$("#versionTitle").show();
77
},
88
error: () => {
9-
$('#versionTitle').hide();
9+
$("#versionTitle").hide();
1010
},
1111
});
1212
// Check auth is enabled on our host
1313
$.ajax({
14-
url: '/oauth/health',
14+
url: "/oauth/health",
1515
success: () => {
1616
// If enabled, then fetch our login status
1717
$.ajax({
18-
url: '/core/user_profile',
19-
dataType: 'json',
18+
url: "/core/user_profile",
19+
dataType: "json",
2020
success: (result) => {
2121
console.log(result);
2222
const user = result;
2323
if (result.username) {
24-
$('#usernameInfo').text(result.username);
25-
$('.loggedIn').fadeIn();
24+
$("#usernameInfo").text(result.username);
25+
$(".loggedIn").fadeIn();
2626
} else {
27-
$('.loggedOut').fadeIn();
27+
$(".loggedOut").fadeIn();
2828
}
2929
},
3030
error: (jqXHR, textStatus, errorThrown) => {
31-
$('.loggedOut').fadeIn();
31+
$(".loggedOut").fadeIn();
3232
},
3333
});
3434
},
3535
error: () => {
36-
$('#authArea').hide();
36+
$("#authArea").hide();
3737
},
3838
});
3939
$.ajax({
40-
url: '/scheduler/health',
40+
url: "/scheduler/health",
4141
success: () => {
4242
// Show the status at some point
4343
},
4444
error: () => {
45-
$('#schedulerButton').hide();
45+
$("#schedulerButton").hide();
4646
},
4747
});
4848

49-
const sb = $('.ui.left.sidebar');
49+
const sb = $(".ui.left.sidebar");
5050
sb.sidebar({
51-
transition: 'overlay',
51+
transition: "overlay",
5252
});
53-
sb.sidebar('attach events', '#runReport');
54-
$('.ui .dropdown').dropdown();
53+
sb.sidebar("attach events", "#runReport");
54+
$(".ui .dropdown").dropdown();
5555

56-
$('.message .close')
57-
.on('click', function () {
58-
$(this)
59-
.closest('.message')
60-
.hide();
61-
});
56+
$(".message .close").on("click", function () {
57+
$(this).closest(".message").hide();
58+
});
6259
});
6360

6461
function rerunReport(jobId, rerunUrl) {
6562
$.ajax({
66-
type: 'POST',
63+
type: "POST",
6764
url: rerunUrl,
68-
dataType: 'json',
65+
dataType: "json",
6966
success(data, status, request) {
7067
window.location.href = data.results_url;
7168
},
7269
error(xhr, textStatus, errorThrown) {
73-
$('#errorMsg').text(`${xhr.status} ${textStatus} ${errorThrown}`);
74-
$('#errorPopup').show();
70+
$("#errorMsg").text(`${xhr.status} ${textStatus} ${errorThrown}`);
71+
$("#errorPopup").show();
7572
},
7673
});
7774
}
@@ -81,32 +78,34 @@ function cloneReport(cloneUrl) {
8178
}
8279

8380
function viewStdout(stdoutUrl) {
84-
stdoutContent = document.getElementById('stdoutContent')
81+
stdoutContent = document.getElementById("stdoutContent");
8582

8683
if (!stdoutContent.textContent) {
8784
$.ajax({
88-
type: 'GET',
85+
type: "GET",
8986
url: stdoutUrl,
90-
dataType: 'json',
87+
dataType: "json",
9188
success(data, status, request) {
92-
stdoutContent.textContent = data.join("")
89+
stdoutContent.textContent = data.join("");
9390
},
9491
error(xhr, textStatus, errorThrown) {
95-
$('#errorMsg').text(`${xhr.status} ${textStatus} ${errorThrown}`);
96-
$('#errorPopup').show();
92+
$("#errorMsg").text(`${xhr.status} ${textStatus} ${errorThrown}`);
93+
$("#errorPopup").show();
9794
},
9895
});
9996
}
10097

101-
$('#stdoutModal').modal({
102-
onDeny() {
103-
return true;
104-
},
105-
onApprove() {
106-
copy(stdoutContent.textContent)
107-
return false;
108-
},
109-
}).modal('show');
98+
$("#stdoutModal")
99+
.modal({
100+
onDeny() {
101+
return true;
102+
},
103+
onApprove() {
104+
copy(stdoutContent.textContent);
105+
return false;
106+
},
107+
})
108+
.modal("show");
110109
}
111110

112111
function copy(text) {
@@ -118,18 +117,18 @@ function copy(text) {
118117
textArea.value = text;
119118

120119
textArea.style.position = "absolute";
121-
textArea.style.opacity = 0
120+
textArea.style.opacity = 0;
122121
document.body.appendChild(textArea);
123122
textArea.focus();
124123
textArea.select();
125124

126125
new Promise((res, rej) => {
127-
document.execCommand('copy') ? res() : rej();
126+
document.execCommand("copy") ? res() : rej();
128127
textArea.remove();
129128
});
130129
}
131130
}
132131

133132
function viewFullscreen(fullscreenUrl) {
134133
window.location.href = fullscreenUrl;
135-
}
134+
}

0 commit comments

Comments
 (0)