Skip to content

Commit 0549bb4

Browse files
committed
Decouple peakrdl CLI installer from official plugins
1 parent 289729f commit 0549bb4

31 files changed

+164
-124
lines changed

.github/workflows/build.yml

+55-54
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,36 @@ on:
1515
workflow_dispatch:
1616

1717
jobs:
18+
build:
19+
name: Build distributions
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v3
23+
24+
- uses: actions/setup-python@v4
25+
name: Install Python
26+
with:
27+
python-version: "3.11"
28+
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install build
32+
33+
- name: Build
34+
run: |
35+
python -m build peakrdl-cli -o dist/
36+
python -m build peakrdl -o dist/
37+
38+
- uses: actions/upload-artifact@v4
39+
with:
40+
name: dist
41+
path: |
42+
dist/*.tar.gz
43+
dist/*.whl
44+
#-------------------------------------------------------------------------------
1845
test:
46+
needs:
47+
- build
1948
strategy:
2049
matrix:
2150
python-version:
@@ -38,35 +67,24 @@ jobs:
3867
steps:
3968
- uses: actions/checkout@v3
4069

41-
- name: Set up Python 3.7 to bootstrap py3.6
42-
if: ${{ matrix.python-version == '3.6' }}
43-
uses: actions/setup-python@v4
44-
with:
45-
python-version: 3.7
46-
4770
- name: Set up Python ${{ matrix.python-version }}
4871
uses: actions/setup-python@v4
4972
with:
5073
python-version: ${{ matrix.python-version }}
5174

52-
- name: Install dependencies
53-
run: |
54-
python -m pip install -U -r test/requirements.txt
75+
- uses: actions/download-artifact@v4
76+
with:
77+
name: dist
78+
path: dist
5579

56-
# Python 3.6 cannot install directly from a pyproject.toml
57-
# Instead, build a wheel from py3.7 and then install it
58-
- name: Install via wheel
59-
if: ${{ matrix.python-version == '3.6' }}
80+
- name: Install dependencies
6081
run: |
61-
python3.7 -m pip install build
62-
python3.7 -m build
63-
python --version
64-
python -m pip install ./dist/*.whl
82+
python -m pip install -r test/requirements.txt
6583
6684
- name: Install
67-
if: ${{ matrix.python-version != '3.6' }}
6885
run: |
69-
python -m pip install .
86+
python -m pip install dist/peakrdl_cli-*.whl
87+
python -m pip install dist/peakrdl-*.whl
7088
7189
- name: Test
7290
run: |
@@ -100,28 +118,37 @@ jobs:
100118
101119
#-------------------------------------------------------------------------------
102120
lint:
121+
needs:
122+
- build
103123
runs-on: ubuntu-latest
104124
steps:
105125
- uses: actions/checkout@v3
106126
- name: Set up Python
107127
uses: actions/setup-python@v4
108128
with:
109-
python-version: "3.10"
129+
python-version: "3.11"
130+
131+
- uses: actions/download-artifact@v4
132+
with:
133+
name: dist
134+
path: dist
110135

111136
- name: Install dependencies
112137
run: |
113-
python -m pip install -U pylint
138+
python -m pip install -r test/requirements.txt
114139
115140
- name: Install
116141
run: |
117-
python -m pip install .
142+
python -m pip install dist/peakrdl_cli-*.whl
118143
119144
- name: Run Lint
120145
run: |
121-
pylint --rcfile test/pylint.rc peakrdl
146+
pylint --rcfile test/pylint.rc peakrdl-cli/src/peakrdl
122147
123148
#-------------------------------------------------------------------------------
124149
mypy:
150+
needs:
151+
- build
125152
runs-on: ubuntu-latest
126153
steps:
127154
- uses: actions/checkout@v3
@@ -132,41 +159,15 @@ jobs:
132159

133160
- name: Install dependencies
134161
run: |
135-
python -m pip install -U mypy
162+
python -m pip install -r test/requirements.txt
136163
137-
- name: Type Check
164+
- name: Install
138165
run: |
139-
mypy --config-file test/mypy.ini src/peakrdl
166+
python -m pip install dist/peakrdl_cli-*.whl
140167
141-
#-------------------------------------------------------------------------------
142-
build:
143-
needs:
144-
- test
145-
- lint
146-
- mypy
147-
name: Build distributions
148-
runs-on: ubuntu-latest
149-
steps:
150-
- uses: actions/checkout@v3
151-
152-
- uses: actions/setup-python@v4
153-
name: Install Python
154-
with:
155-
python-version: "3.10"
156-
157-
- name: Install dependencies
168+
- name: Type Check
158169
run: |
159-
python -m pip install -U build
160-
161-
- name: Build
162-
run: python -m build
163-
164-
- uses: actions/upload-artifact@v4
165-
with:
166-
name: dist
167-
path: |
168-
dist/*.tar.gz
169-
dist/*.whl
170+
mypy --config-file test/mypy.ini peakrdl-cli/src/peakrdl
170171
171172
#-------------------------------------------------------------------------------
172173
deploy:

.readthedocs.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ python:
1414
install:
1515
- requirements: docs/requirements.txt
1616
- method: pip
17-
path: .
17+
path: peakrdl-cli/

peakrdl-cli/LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE

peakrdl-cli/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# PeakRDL command-line interface
2+
This package implements the command-line interface for the PeakRDL toolchain.
3+
4+
## Documentation
5+
See the [PeakRDL Documentation](http://peakrdl.readthedocs.io) for more details.

pyproject.toml peakrdl-cli/pyproject.toml

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,11 @@ requires = ["setuptools", "setuptools-scm"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
6-
name = "peakrdl"
6+
name = "peakrdl-cli"
77
dynamic = ["version"]
88
requires-python = ">=3.6"
99
dependencies = [
1010
"systemrdl-compiler >= 1.27.1, < 2",
11-
"peakrdl-html >= 2.10.1, < 3",
12-
"peakrdl-ipxact >= 3.4.1, < 4",
13-
"peakrdl-regblock >= 0.19.0, < 2",
14-
"peakrdl-systemrdl >= 0.3.0, < 2",
15-
"peakrdl-uvm >= 2.3.0, < 3",
16-
"peakrdl-cheader >= 1.0.0, < 2",
1711
"tomli;python_version<'3.11'",
1812
]
1913

peakrdl-cli/src/peakrdl/__about__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "1.2.0"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/peakrdl/config/loader.py peakrdl-cli/src/peakrdl/config/loader.py

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def load_cfg(argv: List[str]) -> AppConfig:
100100
if path is None:
101101
# Nope. Still no config file. Provide empty data
102102
raw_data = {}
103+
path = ""
103104
else:
104105
if not os.path.isfile(path):
105106
print(f"error: invalid config file path: {path}", file=sys.stderr)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/peakrdl/plugins/entry_points.py peakrdl-cli/src/peakrdl/plugins/entry_points.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import sys
2-
from typing import List, Tuple, TYPE_CHECKING
2+
from typing import List, Tuple, TYPE_CHECKING, Optional
33

44
if TYPE_CHECKING:
55
from importlib.metadata import EntryPoint, Distribution
66

77
if sys.version_info >= (3,10,0):
88
from importlib import metadata
99

10-
def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', 'Distribution']]:
10+
def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', Optional['Distribution']]]:
1111
eps = []
1212
for ep in metadata.entry_points().select(group=group_name):
1313
eps.append((ep, ep.dist))
@@ -19,8 +19,8 @@ def _get_name_from_dist(dist: 'Distribution') -> str:
1919
elif sys.version_info >= (3,8,0): # pragma: no cover
2020
from importlib import metadata
2121

22-
def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', 'Distribution']]:
23-
eps = []
22+
def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', Optional['Distribution']]]:
23+
eps = [] # type: List[Tuple[EntryPoint, Optional[Distribution]]]
2424
dist_names = set()
2525
for dist in metadata.distributions():
2626
# Due to a bug in importlib.metadata's distributions iterator, in
@@ -42,7 +42,7 @@ def _get_name_from_dist(dist: 'Distribution') -> str:
4242
else: # pragma: no cover
4343
import pkg_resources # type: ignore
4444

45-
def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', 'Distribution']]:
45+
def _get_entry_points(group_name: str) -> List[Tuple['EntryPoint', Optional['Distribution']]]:
4646
eps = []
4747
for ep in pkg_resources.iter_entry_points(group_name):
4848
eps.append((ep, ep.dist))
@@ -52,7 +52,7 @@ def _get_name_from_dist(dist: 'Distribution') -> str:
5252
return dist.project_name # type: ignore
5353

5454

55-
def get_entry_points(group_name: str) -> List[Tuple['EntryPoint', 'Distribution']]:
55+
def get_entry_points(group_name: str) -> List[Tuple['EntryPoint', Optional['Distribution']]]:
5656
return _get_entry_points(group_name)
5757

5858
def get_name_from_dist(dist: 'Distribution') -> str:

src/peakrdl/plugins/exporter.py peakrdl-cli/src/peakrdl/plugins/exporter.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ def get_exporter_plugins(cfg: 'AppConfig') -> List[ExporterSubcommandPlugin]:
4242
# Get exporter plugins from entry-points
4343
for ep, dist in get_entry_points("peakrdl.exporters"):
4444
cls = ep.load()
45-
dist_name = get_name_from_dist(dist)
45+
if dist:
46+
dist_name = get_name_from_dist(dist)
47+
dist_version = dist.version
48+
else:
49+
dist_name = None
50+
dist_version = None
4651

4752
if issubclass(cls, ExporterSubcommandPlugin):
4853
# Override name - always use entry point's name
4954
cls.name = ep.name
50-
exporter = cls(dist_name=dist_name, dist_version=dist.version)
55+
exporter = cls(dist_name=dist_name, dist_version=dist_version)
5156
else:
5257
raise RuntimeError(f"Exporter class {cls} is expected to be extended from peakrdl.plugins.exporter.ExporterSubcommandPlugin")
5358
exporters.append(exporter)

src/peakrdl/plugins/importer.py peakrdl-cli/src/peakrdl/plugins/importer.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ def get_importer_plugins(cfg: 'AppConfig') -> List[ImporterPlugin]:
4242
# Get importer plugins from entry-points
4343
for ep, dist in get_entry_points("peakrdl.importers"):
4444
cls = ep.load()
45-
dist_name = get_name_from_dist(dist)
45+
if dist:
46+
dist_name = get_name_from_dist(dist)
47+
dist_version = dist.version
48+
else:
49+
dist_name = None
50+
dist_version = None
4651

4752
if issubclass(cls, ImporterPlugin):
4853
# Override name - always use entry point's name
4954
cls.name = ep.name
50-
importer = cls(dist_name=dist_name, dist_version=dist.version)
55+
importer = cls(dist_name=dist_name, dist_version=dist_version)
5156
else:
5257
raise RuntimeError(f"Importer class {cls} is expected to be extended from peakrdl.plugins.importer.ImporterPlugin")
5358
importers.append(importer)

src/peakrdl/process_input.py peakrdl-cli/src/peakrdl/process_input.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
if TYPE_CHECKING:
88
import argparse
9-
from typing import Sequence
9+
from typing import Sequence, Optional
1010
from systemrdl import RDLCompiler, AddrmapNode
1111
from .importer import Importer
1212

@@ -73,6 +73,7 @@ def parse_parameters(rdlc: 'RDLCompiler', parameter_options: List[str]) -> Dict[
7373
m = re.fullmatch(r"(\w+)=(.+)", raw_param)
7474
if not m:
7575
rdlc.msg.fatal(f"Invalid parameter argument: {raw_param}")
76+
raise ValueError
7677

7778
p_name = m.group(1)
7879
try:
@@ -89,6 +90,7 @@ def parse_defines(rdlc: 'RDLCompiler', define_options: List[str]) -> Dict[str, s
8990
m = re.fullmatch(r"(\w+)(?:=(.+))?", raw_def)
9091
if not m:
9192
rdlc.msg.fatal(f"Invalid define argument: {raw_def}")
93+
raise ValueError
9294

9395
k = m.group(1)
9496
v = m.group(2) or ""
@@ -116,12 +118,11 @@ def process_input(rdlc: 'RDLCompiler', importers: 'Sequence[Importer]', input_fi
116118

117119
# Search which importer to use by extension first
118120
importer_candidates = [] # type: List[Importer]
119-
for importer in importers:
120-
if ext in importer.file_extensions:
121-
importer_candidates.append(importer)
121+
for imp in importers:
122+
if ext in imp.file_extensions:
123+
importer_candidates.append(imp)
122124

123125
# Do 2nd pass if needed
124-
importer = None
125126
if len(importer_candidates) == 1:
126127
importer = importer_candidates[0]
127128
elif len(importer_candidates) > 1:
@@ -131,12 +132,17 @@ def process_input(rdlc: 'RDLCompiler', importers: 'Sequence[Importer]', input_fi
131132
if importer_candidate.is_compatible(file):
132133
importer = importer_candidate
133134
break
135+
else:
136+
importer = None
137+
else:
138+
importer = None
134139

135140
if not importer:
136141
rdlc.msg.fatal(
137142
"Unknown file type. Could not find any importers capable of reading this file.",
138143
FileSourceRef(file)
139144
)
145+
raise ValueError
140146

141147
importer.do_import(rdlc, options, file)
142148

File renamed without changes.
File renamed without changes.

peakrdl/LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE

peakrdl/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md

peakrdl/peakrdl_toolchain.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../peakrdl-cli/src/peakrdl/__about__.py

0 commit comments

Comments
 (0)