Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a0d497b

Browse files
committed
Add and run pretty-format-yaml
1 parent 459e5bf commit a0d497b

File tree

6 files changed

+121
-108
lines changed

6 files changed

+121
-108
lines changed

.github/workflows/build.yml

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
11
name: Build
22

33
on:
4-
push:
5-
branches: main
6-
pull_request:
7-
branches: '*'
4+
push: # Only run on merges into master that modify files under pyscriptjs/
5+
branches: main
6+
paths:
7+
- pyscriptjs/**
8+
- .github/workflows/** # Test that workflows work when changed
9+
10+
pull_request: # Run on any PR that modifies files in pyscriptjs/
11+
paths:
12+
- pyscriptjs/**
13+
- .github/workflows/**
814

915
jobs:
10-
build:
11-
runs-on: ubuntu-latest
12-
steps:
13-
- name: Checkout
14-
uses: actions/checkout@v3
15-
- name: Install node
16-
uses: actions/setup-node@v3
17-
with:
18-
node-version: '12.x'
19-
- name: Cache node modules
20-
uses: actions/cache@v3
21-
env:
22-
cache-name: cache-node-modules
23-
with:
16+
build:
17+
runs-on: ubuntu-latest # Will be self hosted soon
18+
defaults:
19+
run:
20+
working-directory: ./pyscriptjs
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
- name: Install node
26+
uses: actions/setup-node@v3
27+
with:
28+
node-version: 12.x
29+
- name: Cache node modules
30+
uses: actions/cache@v3
31+
env:
32+
cache-name: cache-node-modules
33+
with:
2434
# npm cache files are stored in `~/.npm` on Linux/macOS
25-
path: ~/.npm
26-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
27-
restore-keys: |
28-
${{ runner.os }}-build-${{ env.cache-name }}-
29-
${{ runner.os }}-build-
30-
${{ runner.os }}-
31-
- name: Install dependencies
32-
run: |
33-
cd pyscriptjs
34-
npm install
35-
- name: Build pyscript
36-
run: |
37-
cd pyscriptjs
38-
npm run build
35+
path: ~/.npm
36+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
37+
restore-keys: |
38+
${{ runner.os }}-build-${{ env.cache-name }}-
39+
${{ runner.os }}-build-
40+
${{ runner.os }}-
41+
- name: Install dependencies
42+
run: |
43+
npm install
44+
- name: Build pyscript
45+
run: |
46+
npm run build

.github/workflows/lint.yml

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,40 @@ name: Lint
22

33
on:
44

5-
push: # Only run on merges into master that modify files under pyscriptjs/
6-
branches:
7-
- main
5+
push: # Only run on merges into master that modify files under pyscriptjs/
6+
branches:
7+
- main
88

9-
pull_request: # Run on any PR that modifies files in pyscriptjs/
9+
pull_request: # Run on any PR that modifies files in pyscriptjs/
1010

1111
jobs:
12-
build:
13-
runs-on: ubuntu-latest
14-
defaults:
15-
run:
16-
working-directory: ./pyscriptjs
17-
steps:
18-
- name: Checkout
19-
uses: actions/checkout@v3
20-
- name: Install node
21-
uses: actions/setup-node@v3
22-
with:
23-
node-version: '12.x'
24-
- name: Cache node modules
25-
uses: actions/cache@v3
26-
env:
27-
cache-name: cache-node-modules
28-
with:
12+
build:
13+
runs-on: ubuntu-latest
14+
defaults:
15+
run:
16+
working-directory: ./pyscriptjs
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
- name: Install node
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: 12.x
24+
- name: Cache node modules
25+
uses: actions/cache@v3
26+
env:
27+
cache-name: cache-node-modules
28+
with:
2929
# npm cache files are stored in `~/.npm` on Linux/macOS
30-
path: ~/.npm
31-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
32-
restore-keys: |
33-
${{ runner.os }}-build-${{ env.cache-name }}-
34-
${{ runner.os }}-build-
35-
${{ runner.os }}-
36-
- name: Install dependencies
37-
run: |
38-
npm install
39-
- name: Run linter
40-
run: |
41-
npm run lint
30+
path: ~/.npm
31+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
32+
restore-keys: |
33+
${{ runner.os }}-build-${{ env.cache-name }}-
34+
${{ runner.os }}-build-
35+
${{ runner.os }}-
36+
- name: Install dependencies
37+
run: |
38+
npm install
39+
- name: Run linter
40+
run: |
41+
npm run lint

.pre-commit-config.yaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@
33

44
default_stages: [commit]
55
repos:
6-
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
77
rev: v4.2.0
88
hooks:
99
- id: end-of-file-fixer
10-
exclude: ".*.min.js"
10+
exclude: .*.min.js
1111
- id: trailing-whitespace
1212
- id: check-json
1313
exclude: .*/tsconfig.json
1414
- id: check-yaml
15-
- repo: https://github.com/psf/black
15+
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
16+
rev: v2.3.0
17+
hooks:
18+
- id: pretty-format-yaml
19+
args: [--autofix, --indent, '4']
20+
- repo: https://github.com/psf/black
1621
rev: 22.3.0
1722
hooks:
18-
- id: black
19-
- repo: https://github.com/pycqa/isort
23+
- id: black
24+
- repo: https://github.com/pycqa/isort
2025
rev: 5.10.1
2126
hooks:
22-
- id: isort
27+
- id: isort
2328
name: isort (python)
2429
args: [--profile, black]

pyscriptjs/environment.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
channels:
2-
- defaults
3-
- conda-forge
2+
- defaults
3+
- conda-forge
44
dependencies:
5-
- python=3.9
6-
- pip=20.2.2
7-
- pytest=7
8-
- nodejs=16
9-
- black
10-
- isort
11-
- codespell
5+
- python=3.9
6+
- pip=20.2.2
7+
- pytest=7
8+
- nodejs=16
9+
- black
10+
- isort
11+
- codespell

pyscriptjs/examples/micrograd_ai.html

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,39 @@
88

99
<link rel="stylesheet" href="../build/pyscript.css" />
1010
<script defer src="../build/pyscript.js"></script>
11-
11+
1212
<py-env>
1313
- micrograd
1414
- numpy
1515
- matplotlib
1616
</py-env>
17-
17+
1818
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
1919
</head>
2020

2121
<body style="padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px">
2222
<h1>Micrograd - A tiny Autograd engine (with a bite! :))</h1><br>
2323
<div>
2424
<p>
25-
<a href="https://github.com/karpathy/micrograd">Micrograd</a> is a tiny Autograd engine created
26-
by <a href="https://twitter.com/karpathy">Andrej Karpathy</a>. This app recreates the
27-
<a href="https://github.com/karpathy/micrograd/blob/master/demo.ipynb">demo</a>
28-
he prepared for this package using pyscript to train a basic model, written in Python, natively in
25+
<a href="https://github.com/karpathy/micrograd">Micrograd</a> is a tiny Autograd engine created
26+
by <a href="https://twitter.com/karpathy">Andrej Karpathy</a>. This app recreates the
27+
<a href="https://github.com/karpathy/micrograd/blob/master/demo.ipynb">demo</a>
28+
he prepared for this package using pyscript to train a basic model, written in Python, natively in
2929
the browser. <br>
3030
</p>
3131
</div>
3232
<div>
3333
<p>
34-
You may run each Python REPL cell interactively by pressing (Shift + Enter) or (Ctrl + Enter).
34+
You may run each Python REPL cell interactively by pressing (Shift + Enter) or (Ctrl + Enter).
3535
You can also modify the code directly as you wish. If you want to run all the code at once,
36-
not each cell individually, you may instead click the 'Run All' button. Training the model
36+
not each cell individually, you may instead click the 'Run All' button. Training the model
3737
takes between 1-2 min if you decide to 'Run All' at once. 'Run All' is your only option if
38-
you are running this on a mobile device where you cannot press (Shift + Enter). After the
39-
model is trained, a plot image should be displayed depicting the model's ability to
38+
you are running this on a mobile device where you cannot press (Shift + Enter). After the
39+
model is trained, a plot image should be displayed depicting the model's ability to
4040
classify the data. <br>
4141
</p>
4242
<p>
43-
Currently the <code>&gt;</code> symbol is being imported incorrectly as <code>&ampgt;</code> into the REPL's.
43+
Currently the <code>&gt;</code> symbol is being imported incorrectly as <code>&ampgt;</code> into the REPL's.
4444
In this app the <code>&gt;</code> symbol has been replaced with <code>().__gt__()</code> so you can run the code
4545
without issue. Ex: intead of <code>a &gt; b</code>, you will see <code>(a).__gt__(b)</code> instead. <br>
4646
</p>
@@ -99,7 +99,7 @@ <h1>Micrograd - A tiny Autograd engine (with a bite! :))</h1><br>
9999
</py-repl><br>
100100

101101
<div>
102-
Line 24 has been changed from: <br>
102+
Line 24 has been changed from: <br>
103103
<code>accuracy = [(yi &gt; 0) == (scorei.data &gt; 0) for yi, scorei in zip(yb, scores)]</code><br>
104104
to: <br>
105105
<code>accuracy = [((yi).__gt__(0)) == ((scorei.data).__gt__(0)) for yi, scorei in zip(yb, scores)]</code><br>
@@ -108,26 +108,26 @@ <h1>Micrograd - A tiny Autograd engine (with a bite! :))</h1><br>
108108
<py-repl auto-generate="true">
109109
# loss function
110110
def loss(batch_size=None):
111-
111+
112112
# inline DataLoader :)
113113
if batch_size is None:
114114
Xb, yb = X, y
115115
else:
116116
ri = np.random.permutation(X.shape[0])[:batch_size]
117117
Xb, yb = X[ri], y[ri]
118118
inputs = [list(map(Value, xrow)) for xrow in Xb]
119-
119+
120120
# forward the model to get scores
121121
scores = list(map(model, inputs))
122-
122+
123123
# svm "max-margin" loss
124124
losses = [(1 + -yi*scorei).relu() for yi, scorei in zip(yb, scores)]
125125
data_loss = sum(losses) * (1.0 / len(losses))
126126
# L2 regularization
127127
alpha = 1e-4
128128
reg_loss = alpha * sum((p*p for p in model.parameters()))
129129
total_loss = data_loss + reg_loss
130-
130+
131131
# also get accuracy
132132
accuracy = [((yi).__gt__(0)) == ((scorei.data).__gt__(0)) for yi, scorei in zip(yb, scores)]
133133
return total_loss, sum(accuracy) / len(accuracy)
@@ -138,25 +138,25 @@ <h1>Micrograd - A tiny Autograd engine (with a bite! :))</h1><br>
138138
<py-repl auto-generate="true">
139139
# optimization
140140
for k in range(20): #was 100. Accuracy can be further improved w/ more epochs (to 100%).
141-
141+
142142
# forward
143143
total_loss, acc = loss()
144-
144+
145145
# backward
146146
model.zero_grad()
147147
total_loss.backward()
148-
148+
149149
# update (sgd)
150150
learning_rate = 1.0 - 0.9*k/100
151151
for p in model.parameters():
152152
p.data -= learning_rate * p.grad
153-
153+
154154
if k % 1 == 0:
155155
print(f"step {k} loss {total_loss.data}, accuracy {acc*100}%")
156156
</py-repl><br>
157157
<div>
158158
<p>
159-
Please wait for the training loop above to complete. It will not print out stats until it
159+
Please wait for the training loop above to complete. It will not print out stats until it
160160
has completely finished. This typically takes 1-2 min. <br><br>
161161

162162
Line 9 has been changed from: <br>

pyscriptjs/examples/simple_bioinformatics_tool.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<div class="hero-body">
1717
<p class="title is-3">PyScript — Simple Bioinformatics Example <span class="tag is-white">v.1</span></p>
1818
<p class="subtitle is-6">
19-
Demonstrates the simple use of <a href="https://pyscript.net/" target="_blank"><code>PyScript</code></a>
19+
Demonstrates the simple use of <a href="https://pyscript.net/" target="_blank"><code>PyScript</code></a>
2020
in <strong>Bioinformatics/Computational Biology</strong> fields!
2121
</p>
2222
</div>
@@ -58,7 +58,7 @@
5858
<!--- DNA Sequence Output -->
5959
<label class="label">Output for the <code id="operation_name_output">given operation</code></label>
6060
<div id="output"></div>
61-
</div>
61+
</div>
6262

6363
<br><br>
6464
<!-- Footer -->
@@ -84,15 +84,15 @@
8484
operation_name_output_element = Element("operation_name_output")
8585

8686
# DNA Sequene Operations
87-
def return_reverse(dna_seq):
87+
def return_reverse(dna_seq):
8888
return dna_seq[::-1]
89-
def return_complement(dna_seq):
89+
def return_complement(dna_seq):
9090
return dna_seq.translate(str.maketrans("ATCG", "TAGC"))
91-
def return_reverse_complement(dna_seq):
91+
def return_reverse_complement(dna_seq):
9292
return dna_seq.translate(str.maketrans("ATCG", "TAGC"))[::-1]
9393

9494
# Check DNA seq is valid
95-
def check_dna_seq(dna_seq):
95+
def check_dna_seq(dna_seq):
9696
return all(letter in dna_alphabet for letter in dna_seq.upper())
9797

9898
# Clear the form and output
@@ -115,7 +115,7 @@
115115
output_dna_seq = return_complement(dna_seq)
116116
elif operation_name == "ReverseComplement":
117117
output_dna_seq = return_reverse_complement(dna_seq)
118-
118+
119119
# Output the result
120120
output.write(output_dna_seq)
121121
elif (dna_seq.strip() == "") or (dna_seq is None):

0 commit comments

Comments
 (0)