diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7b5b796..c765953 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,6 +38,12 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Set up Python 3.7 to bootstrap py3.6 + if: ${{ matrix.python-version == '3.6' }} + uses: actions/setup-python@v4 + with: + python-version: 3.7 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: @@ -47,7 +53,18 @@ jobs: run: | python -m pip install -U -r tests/requirements.txt + # Python 3.6 cannot install directly from a pyproject.toml + # Instead, build a wheel from py3.7 and then install it + - name: Install via wheel + if: ${{ matrix.python-version == '3.6' }} + run: | + python3.7 -m pip install build + python3.7 -m build + python --version + python -m pip install ./dist/*.whl + - name: Install + if: ${{ matrix.python-version != '3.6' }} run: | python -m pip install . @@ -115,14 +132,14 @@ jobs: - name: Install dependencies run: | - python -m pip install -U mypy + python -m pip install -U mypy peakrdl - name: Type Check run: | mypy --config-file tests/mypy.ini src/peakrdl_cheader #------------------------------------------------------------------------------- - build_sdist: + build: needs: - test - lint @@ -137,17 +154,23 @@ jobs: with: python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install -U build + - name: Build sdist - run: python setup.py sdist + run: python -m build - uses: actions/upload-artifact@v3 with: - path: dist/*.tar.gz + path: | + dist/*.tar.gz + dist/*.whl #------------------------------------------------------------------------------- deploy: needs: - - build_sdist + - build runs-on: ubuntu-latest diff --git a/pyproject.toml b/pyproject.toml index 0686899..5abde2d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "peakrdl-cheader" dynamic = ["version"] -requires-python = ">=3.7" +requires-python = ">=3.6" dependencies = [ "systemrdl-compiler >= 1.21.0, < 2", "jinja2", @@ -23,11 +23,13 @@ classifiers = [ "Development Status :: 4 - Beta", "Programming Language :: Python", "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3 :: Only", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", diff --git a/src/peakrdl_cheader/c_standards.py b/src/peakrdl_cheader/c_standards.py index eebc276..d32b4cc 100644 --- a/src/peakrdl_cheader/c_standards.py +++ b/src/peakrdl_cheader/c_standards.py @@ -1,37 +1,49 @@ -from typing import Dict +from typing import Dict, Tuple import enum class CStandard(enum.Enum): - def __init__(self, version: int, d: Dict[str, bool]) -> None: + def __init__(self, name: str, d: Dict[str, bool]) -> None: self.anon_unions = d.get("anon_unions", False) self.static_assert = d.get("static_assert", False) self.static_assert_needs_assert_h = d.get("static_assert_needs_assert_h", False) # Prevent Enum from flattening members into aliases - self._value_ = version + self._value_ = name - gnu23 = 23, { + gnu23 = "gnu23", { "anon_unions": True, "static_assert": True, } - gnu17 = 17, { + gnu17 = "gnu17", { "anon_unions": True, "static_assert": True, "static_assert_needs_assert_h": True, } - gnu11 = 11, { + gnu11 = "gnu11", { "anon_unions": True, "static_assert": True, "static_assert_needs_assert_h": True, } - gnu99 = 99, {} + gnu99 = "gnu99", { + "anon_unions": False, + "static_assert": False, + "static_assert_needs_assert_h": False, + } - gnu90 = 90, {} + gnu90 = "gnu90", { + "anon_unions": False, + "static_assert": False, + "static_assert_needs_assert_h": False, + } - gnu89 = 89, {} + gnu89 = "gnu89", { + "anon_unions": False, + "static_assert": False, + "static_assert_needs_assert_h": False, + } latest = gnu17 # gnu23 is still unreleased diff --git a/src/peakrdl_cheader/header_generator.py b/src/peakrdl_cheader/header_generator.py index b785913..6303397 100644 --- a/src/peakrdl_cheader/header_generator.py +++ b/src/peakrdl_cheader/header_generator.py @@ -21,7 +21,7 @@ def __init__(self, ds: DesignState) -> None: self.root_node = None self.f: TextIO - self.f = None + self.f = None # type: ignore def run(self, path: str, top_nodes: List[AddrmapNode]) -> None: with open(path, "w", encoding='utf-8') as f: diff --git a/src/peakrdl_cheader/py.typed b/src/peakrdl_cheader/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/src/peakrdl_cheader/testcase_generator.py b/src/peakrdl_cheader/testcase_generator.py index 11ad96e..1515101 100644 --- a/src/peakrdl_cheader/testcase_generator.py +++ b/src/peakrdl_cheader/testcase_generator.py @@ -45,10 +45,10 @@ def __init__(self, ds: DesignState) -> None: self.root_node = None self.root_struct_name: str - self.root_struct_name = None + self.root_struct_name = "" self.f: TextIO - self.f = None + self.f = None # type: ignore self.overlap_pair_stack: List[List[str]] self.overlap_pair_stack = [] @@ -150,7 +150,7 @@ def __init__(self, ds: DesignState) -> None: self.root_node = None self.f: TextIO - self.f = None + self.f = None # type: ignore def run(self, f: TextIO, top_nodes: List[AddrmapNode]) -> None: self.f = f diff --git a/tests/.mypy.ini b/tests/.mypy.ini deleted file mode 100644 index f785436..0000000 --- a/tests/.mypy.ini +++ /dev/null @@ -1,3 +0,0 @@ -[mypy] -namespace_packages = True -explicit_package_bases = True diff --git a/tests/base.py b/tests/base.py index 1ec665c..d651783 100644 --- a/tests/base.py +++ b/tests/base.py @@ -79,22 +79,20 @@ def do_export(self): def do_compile(self): args = [ "gcc", - "--std", self.std.name, + "--std", self.std.value, os.path.join(self.output_dir, "out.h.test.c"), "-o", os.path.join(self.output_dir, "test.exe"), ] - ret = subprocess.run(args, capture_output=True) + ret = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) print(" ".join(args)) print(ret.stdout.decode('utf-8')) - print(ret.stderr.decode('utf-8')) self.assertEqual(ret.returncode, 0) def do_run(self): args = [os.path.join(self.output_dir, "test.exe")] - ret = subprocess.run(args, capture_output=True) + ret = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) print(" ".join(args)) print(ret.stdout.decode('utf-8')) - print(ret.stderr.decode('utf-8')) self.assertEqual(ret.returncode, 0) def do_test(self): diff --git a/tests/mypy.ini b/tests/mypy.ini new file mode 100644 index 0000000..f061b14 --- /dev/null +++ b/tests/mypy.ini @@ -0,0 +1,11 @@ +[mypy] +namespace_packages = True +explicit_package_bases = True + +[mypy-systemrdl.*] +# Ignore missing py.typed in release +ignore_missing_imports = True + +[mypy-peakrdl.*] +# Ignore missing py.typed in release +ignore_missing_imports = True diff --git a/tests/run.sh b/tests/run.sh index 326ca96..c4d6315 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -10,6 +10,7 @@ source .venv/bin/activate # Install test dependencies pip install -U pip setuptools wheel +pip install peakrdl pip install -r requirements.txt # Install dut @@ -28,4 +29,4 @@ coverage html -i -d htmlcov pylint --rcfile pylint.rc ../src/peakrdl_cheader # Run static type checking -#mypy ../src/peakrdl_cheader +mypy ../src/peakrdl_cheader