Skip to content

Commit 0be5334

Browse files
committed
Decouple peakrdl CLI installer from official plugins
1 parent 289729f commit 0be5334

31 files changed

+181
-131
lines changed

.github/workflows/build.yml

+72-61
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,44 @@ on:
1111
types:
1212
- published
1313

14-
# Allows you to run this workflow manually from the Actions tab
15-
workflow_dispatch:
16-
1714
jobs:
15+
build:
16+
name: Build
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- uses: actions/setup-python@v4
22+
name: Install Python
23+
with:
24+
python-version: "3.11"
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install build
29+
30+
- name: Build
31+
run: |
32+
python -m build peakrdl-cli -o dist/
33+
python -m build peakrdl -o dist/
34+
35+
- uses: actions/upload-artifact@v4
36+
with:
37+
name: dist
38+
path: |
39+
dist/*.tar.gz
40+
dist/*.whl
41+
#-------------------------------------------------------------------------------
1842
test:
43+
needs:
44+
- build
1945
strategy:
2046
matrix:
2147
python-version:
22-
- 3.6
23-
- 3.7
24-
- 3.8
25-
- 3.9
48+
- "3.6"
49+
- "3.7"
50+
- "3.8"
51+
- "3.9"
2652
- "3.10"
2753
- "3.11"
2854
- "3.12"
@@ -33,40 +59,35 @@ jobs:
3359
- python-version: 3.6
3460
os: ubuntu-20.04
3561

62+
- python-version: "3.7"
63+
os: ubuntu-22.04
64+
65+
- python-version: "3.8"
66+
os: ubuntu-22.04
67+
3668
runs-on: ${{ matrix.os }}
3769

3870
steps:
3971
- uses: actions/checkout@v3
4072

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-
4773
- name: Set up Python ${{ matrix.python-version }}
4874
uses: actions/setup-python@v4
4975
with:
5076
python-version: ${{ matrix.python-version }}
5177

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

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' }}
83+
- name: Install dependencies
6084
run: |
61-
python3.7 -m pip install build
62-
python3.7 -m build
63-
python --version
64-
python -m pip install ./dist/*.whl
85+
python -m pip install -r test/requirements.txt
6586
6687
- name: Install
67-
if: ${{ matrix.python-version != '3.6' }}
6888
run: |
69-
python -m pip install .
89+
python -m pip install dist/peakrdl_cli-*.whl
90+
python -m pip install dist/peakrdl-*.whl
7091
7192
- name: Test
7293
run: |
@@ -100,28 +121,37 @@ jobs:
100121
101122
#-------------------------------------------------------------------------------
102123
lint:
124+
needs:
125+
- build
103126
runs-on: ubuntu-latest
104127
steps:
105128
- uses: actions/checkout@v3
106129
- name: Set up Python
107130
uses: actions/setup-python@v4
108131
with:
109-
python-version: "3.10"
132+
python-version: "3.11"
133+
134+
- uses: actions/download-artifact@v4
135+
with:
136+
name: dist
137+
path: dist
110138

111139
- name: Install dependencies
112140
run: |
113-
python -m pip install -U pylint
141+
python -m pip install -r test/requirements.txt
114142
115143
- name: Install
116144
run: |
117-
python -m pip install .
145+
python -m pip install dist/peakrdl_cli-*.whl
118146
119147
- name: Run Lint
120148
run: |
121-
pylint --rcfile test/pylint.rc peakrdl
149+
pylint --rcfile test/pylint.rc peakrdl-cli/src/peakrdl
122150
123151
#-------------------------------------------------------------------------------
124152
mypy:
153+
needs:
154+
- build
125155
runs-on: ubuntu-latest
126156
steps:
127157
- uses: actions/checkout@v3
@@ -130,48 +160,29 @@ jobs:
130160
with:
131161
python-version: "3.10"
132162

163+
- uses: actions/download-artifact@v4
164+
with:
165+
name: dist
166+
path: dist
167+
133168
- name: Install dependencies
134169
run: |
135-
python -m pip install -U mypy
170+
python -m pip install -r test/requirements.txt
171+
172+
- name: Install
173+
run: |
174+
python -m pip install dist/peakrdl_cli-*.whl
136175
137176
- name: Type Check
138177
run: |
139-
mypy --config-file test/mypy.ini src/peakrdl
178+
mypy --config-file test/mypy.ini peakrdl-cli/src/peakrdl
140179
141180
#-------------------------------------------------------------------------------
142-
build:
181+
deploy:
143182
needs:
144183
- test
145184
- lint
146185
- 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
158-
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-
171-
#-------------------------------------------------------------------------------
172-
deploy:
173-
needs:
174-
- build
175186

176187
runs-on: ubuntu-latest
177188
environment: release

.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.

0 commit comments

Comments
 (0)