Skip to content

Commit baa6dd9

Browse files
committed
add and apply pre-commit
1 parent f78da21 commit baa6dd9

File tree

4 files changed

+121
-82
lines changed

4 files changed

+121
-82
lines changed

.circleci/config.yml

+40-40
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
tag_filter: &tag_filter
23
filters:
34
tags:
@@ -9,55 +10,54 @@ version: 2.1
910
jobs:
1011
build:
1112
machine:
12-
image: circleci/classic:latest
13+
image: ubuntu-2204:2022.10.2
1314
steps:
14-
- checkout
15-
- run:
16-
name: Build Docker image
17-
command: bash build_docker.sh
18-
no_output_timeout: 30m # MCR is a large download
19-
- persist_to_workspace:
20-
root: /home/circleci
21-
paths:
22-
- docker/image.tar
15+
- checkout
16+
- run:
17+
name: Build Docker image
18+
command: bash build_docker.sh
19+
no_output_timeout: 30m # MCR is a large download
20+
- persist_to_workspace:
21+
root: /home/circleci
22+
paths:
23+
- docker/image.tar
2324
test:
2425
machine:
25-
image: circleci/classic:latest
26+
image: ubuntu-2204:2022.10.2
2627
steps:
27-
- attach_workspace:
28-
at: /tmp/workspace
29-
- run:
30-
name: Test Docker image
31-
command: |
32-
docker load -i /tmp/workspace/docker/image.tar
33-
# figure out a better test
34-
docker run -ti --rm --read-only \
35-
--entrypoint /bin/sh bids/${CIRCLE_PROJECT_REPONAME,,} \
36-
-c 'test -d ${MCR_HOME}/runtime/glnxa64'
28+
- attach_workspace:
29+
at: /tmp/workspace
30+
- run:
31+
name: Test Docker image
32+
command: |
33+
docker load -i /tmp/workspace/docker/image.tar
34+
# figure out a better test
35+
docker run -ti --rm --read-only \
36+
--entrypoint /bin/sh bids/${CIRCLE_PROJECT_REPONAME,,} \
37+
-c 'test -d ${MCR_HOME}/runtime/glnxa64'
3738
deploy:
3839
docker:
39-
- image: circleci/buildpack-deps:stretch
40+
- image: circleci/buildpack-deps:stretch
4041
steps:
41-
- attach_workspace:
42-
at: /tmp/workspace
43-
- setup_remote_docker
44-
- run: docker load -i /tmp/workspace/docker/image.tar
45-
- run:
46-
name: Publish Docker image
47-
command: push_docker.sh
42+
- attach_workspace:
43+
at: /tmp/workspace
44+
- setup_remote_docker
45+
- run: docker load -i /tmp/workspace/docker/image.tar
46+
- run:
47+
name: Publish Docker image
48+
command: push_docker.sh
4849

4950
workflows:
5051
build-test-deploy:
5152
jobs:
52-
- build:
53-
<<: *tag_filter
54-
- test:
55-
requires:
56-
- build
57-
<<: *tag_filter
58-
- deploy:
59-
requires:
60-
- test
61-
<<: *tag_filter
62-
53+
- build:
54+
<<: *tag_filter
55+
- test:
56+
requires:
57+
- build
58+
<<: *tag_filter
59+
- deploy:
60+
requires:
61+
- test
62+
<<: *tag_filter
6363
# VS Code Extension Version: 1.5.1

.pre-commit-config.yaml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
# See https://pre-commit.com for more information
3+
# See https://pre-commit.com/hooks.html for more hooks
4+
5+
repos:
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v4.3.0
8+
hooks:
9+
- id: trailing-whitespace
10+
- id: end-of-file-fixer
11+
- id: check-yaml
12+
- id: check-json
13+
- id: check-added-large-files
14+
- id: check-case-conflict
15+
- id: check-merge-conflict
16+
17+
18+
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
19+
rev: 0.2.2
20+
hooks:
21+
- id: yamlfmt
22+
args: [--mapping, '2', --sequence, '2', --offset, '0']
23+
24+
25+
- repo: https://github.com/hadolint/hadolint
26+
rev: v2.12.0
27+
hooks:
28+
- id: hadolint-docker
29+
name: Lint Dockerfiles
30+
description: Runs hadolint Docker image to lint Dockerfiles
31+
language: docker_image
32+
types: [dockerfile]
33+
entry: ghcr.io/hadolint/hadolint hadolint
34+
35+
- repo: https://github.com/psf/black
36+
rev: 22.12.0
37+
hooks:
38+
- id: black
39+
40+
ci:
41+
skip: [hadolint-docker]

push_docker.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ if [[ -n "${CIRCLE_TAG}" ]]; then
2121
docker tag "bids/${CIRCLE_PROJECT_REPONAME,,}" "bids/${CIRCLE_PROJECT_REPONAME,,}:${MAJOR_TAG}"
2222
docker push "bids/${CIRCLE_PROJECT_REPONAME,,}:${MAJOR_TAG}"
2323
fi
24-
24+
2525
fi

update.py

+39-41
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
from packaging import version
3232
from bs4 import BeautifulSoup
3333

34-
REL_URL = 'https://www.mathworks.com/products/compiler/matlab-runtime.html'
35-
VER_LIMIT = '9.3' # release URLs get weird before that..
34+
REL_URL = "https://www.mathworks.com/products/compiler/matlab-runtime.html"
35+
VER_LIMIT = "9.3" # release URLs get weird before that..
36+
3637

3738
def call(cmd, split=True):
3839
if split:
@@ -43,16 +44,16 @@ def call(cmd, split=True):
4344

4445
with request.urlopen(REL_URL) as res:
4546
if res.status != 200:
46-
raise RuntimeError('Could not open matlab release URL')
47+
raise RuntimeError("Could not open matlab release URL")
4748
html = res.read()
4849

49-
soup = BeautifulSoup(html, 'html.parser')
50-
ver_re = re.compile(r'(R2\d{3}.) \((\d\.\d)\)')
51-
rel_re = re.compile(r'Release/(\d+)/')
50+
soup = BeautifulSoup(html, "html.parser")
51+
ver_re = re.compile(r"(R2\d{3}.) \((\d\.\d)\)")
52+
rel_re = re.compile(r"Release/(\d+)/")
5253

5354
dockers = []
54-
for row in soup.find_all('table')[0].find_all('tr'):
55-
tds = row.find_all('td')
55+
for row in soup.find_all("table")[0].find_all("tr"):
56+
tds = row.find_all("td")
5657
if len(tds) >= 4:
5758
name = tds[0].text
5859
match = ver_re.match(name)
@@ -62,55 +63,52 @@ def call(cmd, split=True):
6263
if version.parse(mcr_ver) <= version.parse(VER_LIMIT):
6364
continue
6465
try:
65-
link = tds[2].a.get('href')
66+
link = tds[2].a.get("href")
6667
except (KeyError, ValueError):
67-
raise RuntimeError('Error parsing matlab release page')
68-
if 'glnxa64' not in link:
69-
raise RuntimeError('Error parsing matlab release page link')
68+
raise RuntimeError("Error parsing matlab release page")
69+
if "glnxa64" not in link:
70+
raise RuntimeError("Error parsing matlab release page link")
7071
match = rel_re.search(link)
7172
if match:
72-
mcr_ver = '{}.{}'.format(mcr_ver, match.groups()[0])
73+
mcr_ver = "{}.{}".format(mcr_ver, match.groups()[0])
7374
dockers.append((mcr_name, mcr_ver, link))
7475

7576

76-
variants = [
77-
('Dockerfile-full.template', ''),
78-
('Dockerfile-core.template', '-core')
79-
]
77+
variants = [("Dockerfile-full.template", ""), ("Dockerfile-core.template", "-core")]
8078
new_tags = []
8179

8280
for docker in dockers:
8381
mcr_name, mcr_ver, link = docker
84-
if len(mcr_ver.split('.')) == 2:
85-
mcr_ver = mcr_ver + '.0'
86-
mcr_ver_maj = '.'.join(mcr_ver.split('.')[0:2])
87-
mcr_ver_dir = 'v{}'.format(mcr_ver_maj.replace('.', ''))
88-
if not call('git checkout {}'.format(mcr_name)):
89-
call('git checkout -b {}'.format(mcr_name))
82+
if len(mcr_ver.split(".")) == 2:
83+
mcr_ver = mcr_ver + ".0"
84+
mcr_ver_maj = ".".join(mcr_ver.split(".")[0:2])
85+
mcr_ver_dir = "v{}".format(mcr_ver_maj.replace(".", ""))
86+
if not call("git checkout {}".format(mcr_name)):
87+
call("git checkout -b {}".format(mcr_name))
9088
for (template, suffix) in variants:
91-
tag = '{}{}'.format(mcr_ver, suffix)
92-
if call('git rev-parse --verify {}'.format(tag)):
93-
print('Skipping {}/{}, already present'.format(mcr_name, tag))
89+
tag = "{}{}".format(mcr_ver, suffix)
90+
if call("git rev-parse --verify {}".format(tag)):
91+
print("Skipping {}/{}, already present".format(mcr_name, tag))
9492
continue
95-
print('Adding {}/{}'.format(mcr_name, tag))
96-
if not call('git merge master'):
97-
raise RuntimeError('Merging master failed, will not continue')
93+
print("Adding {}/{}".format(mcr_name, tag))
94+
if not call("git merge master"):
95+
raise RuntimeError("Merging master failed, will not continue")
9896
with open(template) as f:
9997
lines = f.read()
100-
lines = lines.replace('%%MATLAB_VERSION%%', mcr_name)
101-
lines = lines.replace('%%MCR_VERSION%%', mcr_ver_dir)
102-
lines = lines.replace('%%MCR_LINK%%', link)
103-
with open('Dockerfile', 'w+') as f2:
98+
lines = lines.replace("%%MATLAB_VERSION%%", mcr_name)
99+
lines = lines.replace("%%MCR_VERSION%%", mcr_ver_dir)
100+
lines = lines.replace("%%MCR_LINK%%", link)
101+
with open("Dockerfile", "w+") as f2:
104102
f2.write(lines)
105-
call('git add Dockerfile')
106-
# Tag X.Y.Z[-variant] - see circle CI for shared tag X.Y[-variant]
107-
call(['git', 'commit', '-m', 'Auto-Update'], split=False)
108-
call('git tag {}'.format(tag))
103+
call("git add Dockerfile")
104+
# Tag X.Y.Z[-variant] - see circle CI for shared tag X.Y[-variant]
105+
call(["git", "commit", "-m", "Auto-Update"], split=False)
106+
call("git tag {}".format(tag))
109107
new_tags.append(tag)
110-
call('git checkout master')
108+
call("git checkout master")
111109

112110
if new_tags:
113-
print('New tags have been added, verify and update to git with:')
114-
print('git push --all')
111+
print("New tags have been added, verify and update to git with:")
112+
print("git push --all")
115113
for tag in reversed(new_tags):
116-
print('git push origin {}'.format(tag))
114+
print("git push origin {}".format(tag))

0 commit comments

Comments
 (0)