Skip to content

Commit 26bd492

Browse files
authored
README: Extract Python code example to 'example.py' and run it
readme: move example to 'example.py' and update it
2 parents af76c62 + 893619c commit 26bd492

File tree

3 files changed

+113
-28
lines changed

3 files changed

+113
-28
lines changed

.github/workflows/Pipeline.yml

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -222,31 +222,84 @@ jobs:
222222
run: |
223223
twine upload dist/*
224224
225+
VerifyDocs:
226+
name: 📓 Verify that example(s) is/are runnable
227+
runs-on: ubuntu-latest
228+
steps:
229+
230+
- name: 📥 Checkout repository
231+
uses: actions/checkout@v2
232+
233+
- name: '⚙️ Setup GHDL'
234+
uses: ghdl/setup-ghdl-ci@master
235+
236+
- name: '🐍 Setup Python'
237+
uses: actions/setup-python@v2
238+
with:
239+
python-version: 3.9
240+
241+
- name: '🐍 Install dependencies'
242+
run: |
243+
pip3 install pytest
244+
pip3 install git+https://github.com/ghdl/ghdl.git@$(ghdl version hash)
245+
246+
- name: 'Extract example from README'
247+
shell: python
248+
run: |
249+
from pathlib import Path
250+
import re
251+
252+
ROOT = Path('.')
253+
254+
with (ROOT / 'README.md').open('r') as rptr:
255+
content = rptr.read()
256+
257+
m = re.search(r"```py(thon)?(?P<code>.*?)```", content, re.MULTILINE|re.DOTALL)
258+
259+
if m is None:
260+
raise Exception("Regular expression did not find the example in the README!")
261+
262+
with (ROOT / 'tests/docs/example.py').open('w') as wptr:
263+
wptr.write(m["code"])
264+
265+
- name: 'Print example.py'
266+
run: cat tests/docs/example.py
267+
268+
- name: 'Run example.py'
269+
run: |
270+
cd tests/docs
271+
python3 example.py
272+
273+
225274
BuildTheDocs:
226275
name: 📓 Run BuildTheDocs and publish to GH-Pages
227276
runs-on: ubuntu-latest
277+
278+
needs:
279+
- VerifyDocs
280+
228281
steps:
229282

230-
- name: Checkout repository
231-
uses: actions/checkout@v2
283+
- name: Checkout repository
284+
uses: actions/checkout@v2
232285

233-
- name: 🚢 Build documentation in 'pyVHDLModel/doc'
234-
run: |
235-
docker build -t vhdl/doc - <<-EOF
236-
FROM btdi/sphinx:featured
237-
RUN apk add -U --no-cache graphviz
238-
EOF
286+
- name: 🚢 Build container image 'vhdl/doc'
287+
run: |
288+
docker build -t vhdl/doc - <<-EOF
289+
FROM btdi/sphinx:featured
290+
RUN apk add -U --no-cache graphviz
291+
EOF
239292
240-
- name: 🛳️ Unknown
241-
uses: buildthedocs/btd@v0
242-
with:
243-
token: ${{ github.token }}
293+
- name: 🛳️ Build documentation in 'pyVHDLModel/doc'
294+
uses: buildthedocs/btd@v0
295+
with:
296+
token: ${{ github.token }}
244297

245-
- name: Upload artifacts to GitHub Pages
246-
uses: actions/upload-artifact@master
247-
with:
248-
name: doc
249-
path: doc/_build/html
298+
- name: Upload artifacts to GitHub Pages
299+
uses: actions/upload-artifact@master
300+
with:
301+
name: doc
302+
path: doc/_build/html
250303

251304
ArtifactCleanUp:
252305
name: 🗑️ Artifact Cleanup
@@ -260,8 +313,8 @@ jobs:
260313
ARTIFACT: ${{ needs.Package.outputs.artifact }}
261314

262315
steps:
263-
- name: 🗑️ Delete all Artifacts
264-
uses: geekyeggo/delete-artifact@v1
265-
with:
266-
name: |
267-
${{ env.ARTIFACT }}
316+
- name: 🗑️ Delete all Artifacts
317+
uses: geekyeggo/delete-artifact@v1
318+
with:
319+
name: |
320+
${{ env.ARTIFACT }}

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ from pyGHDL.dom.NonStandard import Design, Document
5757
sourceFile = Path("example.vhdl")
5858

5959
design = Design()
60-
library = Design.GetLibrary("lib")
60+
library = design.GetLibrary("lib")
6161
document = Document(sourceFile)
6262
design.AddDocument(document, library)
6363

6464
for entity in document.Entities:
65-
print("{}".format(entity.Name))
65+
print("{}".format(entity.Identifier))
6666
print(" generics:")
67-
for generic in entity.Generics:
67+
for generic in entity.GenericItems:
6868
print(" - {} : {!s} {}".format(
69-
generic.Identifier, generic.Mode, generic.SubTypeIndication)
69+
generic.Identifier, generic.Mode, generic.Subtype)
7070
)
7171
print(" ports:")
72-
for port in entity.Ports:
72+
for port in entity.PortItems:
7373
print(" - {} : {!s} {}".format(
74-
port.Identifier, port.Mode, port.SubTypeIndication)
74+
port.Identifier, port.Mode, port.Subtype)
7575
)
7676
```
7777

tests/docs/example.vhdl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
library ieee;
2+
use ieee.std_logic_1164.all;
3+
use ieee.numeric_std.all;
4+
5+
entity entity_1 is
6+
generic (
7+
FREQ : real := (100.0 * 1024.0 * 1024.0);
8+
BITS : positive := 8
9+
);
10+
port (
11+
Clock: in std_logic;
12+
Reset: in std_logic := '0';
13+
Q: out std_logic_vector(BITS - 1 downto 0)
14+
);
15+
end entity entity_1;
16+
17+
architecture behav of entity_1 is
18+
signal Reset_n : std_logic;
19+
begin
20+
Reset_n <= (not Reset);
21+
22+
process(Clock)
23+
begin
24+
if rising_edge(Clock) then
25+
if Reset_n = '0' then
26+
Q <= (others => '0');
27+
else
28+
Q <= std_logic_vector(unsigned(Q) + 1);
29+
end if;
30+
end if;
31+
end process;
32+
end architecture behav;

0 commit comments

Comments
 (0)