From e1c8b84339f38255d232096ba036f09c7854c04c Mon Sep 17 00:00:00 2001 From: Justin Simon Date: Sun, 17 Nov 2024 18:19:53 -0600 Subject: [PATCH] initial commit of package framework Added a basic "hatch" project to build, format, and publish a Python package. --- .editorconfig | 11 ++++ .github/workflows/build.yml | 85 +++++++++++++++++++++++++++ .gitignore | 111 ++++++++++++++++++++++++++++++++++++ .vscode/settings.json | 21 +++++++ LICENSE | 22 +++++++ README.md | 28 +++++++++ pyproject.toml | 94 ++++++++++++++++++++++++++++++ src/pymctp/__about__.py | 4 ++ src/pymctp/__init__.py | 3 + tests/__init__.py | 3 + 10 files changed, 382 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/build.yml create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 LICENSE create mode 100644 README.md create mode 100644 pyproject.toml create mode 100644 src/pymctp/__about__.py create mode 100644 src/pymctp/__init__.py create mode 100644 tests/__init__.py diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..634594e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +# http://editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true +insert_final_newline = true +charset = utf-8 +end_of_line = lf diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..a4d74ab --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,85 @@ +name: Build + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python_version: ['3.10'] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python_version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install hatch + hatch env create + - name: Lint and typecheck + run: | + hatch fmt --check + # - name: Test + # run: | + # hatch run test-cov-xml + # - uses: codecov/codecov-action@v4 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # fail_ci_if_error: true + # verbose: true + + release: + runs-on: ubuntu-latest + environment: release + needs: test + if: startsWith(github.ref, 'refs/tags/') + permissions: + contents: write + id-token: write + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.9' + - name: Install dependencies + shell: bash + run: | + python -m pip install --upgrade pip + pip install hatch + - name: mint API token + id: mint-token + run: | + # retrieve the ambient OIDC token + resp=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ + "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi") + oidc_token=$(jq -r '.value' <<< "${resp}") + + # exchange the OIDC token for an API token + resp=$(curl -X POST https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}") + api_token=$(jq -r '.token' <<< "${resp}") + + # mask the newly minted API token, so that we don't accidentally leak it + echo "::add-mask::${api_token}" + + # see the next step in the workflow for an example of using this step output + echo "api-token=${api_token}" >> "${GITHUB_OUTPUT}" + - name: Build and publish on PyPI + env: + HATCH_INDEX_USER: __token__ + HATCH_INDEX_AUTH: ${{ steps.mint-token.outputs.api-token }} + run: | + hatch build + hatch publish + - name: Create release + uses: ncipollo/release-action@v1 + with: + draft: true + body: ${{ github.event.head_commit.message }} + artifacts: dist/*.whl,dist/*.tar.gz + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f772e1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,111 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ +junit/ +junit.xml +test.db + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# OS files +.DS_Store + +# ignore VSCode settings +.history/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..aad8a3c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,21 @@ +{ + "python.analysis.typeCheckingMode": "basic", + "python.analysis.autoImportCompletions": true, + "python.terminal.activateEnvironment": true, + "python.terminal.activateEnvInCurrentTerminal": true, + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true, + "editor.rulers": [120], + "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python", + "python.testing.pytestPath": "${workspaceFolder}/.venv/bin/pytest", + "python.testing.cwd": "${workspaceFolder}", + "python.testing.pytestArgs": ["--no-cov"], + "[python]": { + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll": "explicit", + "source.organizeImports": "explicit" + }, + "editor.defaultFormatter": "charliermarsh.ruff" + } + } diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..89d633a --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2024, Justin Simon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..8e5bf5f --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# PyMCTP + +

+ PyMCTP is a tool to forge/decode DMTF MCTP communication packets +

+ +[![build](https://github.com/jls5177/mctp-emu/workflows/Build/badge.svg)](https://github.com/jls5177/mctp-emu/actions) +[![codecov](https://codecov.io/gh/jls5177/mctp-emu/branch/master/graph/badge.svg)](https://codecov.io/gh/jls5177/mctp-emu) +[![PyPI version](https://badge.fury.io/py/pymctp.svg)](https://badge.fury.io/py/pymctp) + +[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pymctp.svg)](https://pypi.org/project/pymctp) + +----- + +## Table of Contents + +- [Installation](#installation) +- [License](#license) + +## Installation + +```console +pip install pymctp +``` + +## License + +`pymctp` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..de7423b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,94 @@ +[build-system] +requires = ["hatchling", "hatch-regex-commit"] +build-backend = "hatchling.build" + +[project] +name = "pymctp" +dynamic = ["version"] +description = "PyMCTP is a tool to forge/decode DMTF MCTP communication packets" +readme = "README.md" +requires-python = ">=3.8" +license = { file = "LICENSE" } +keywords = [] +authors = [ + { name = "Justin Simon", email = "justin@simonctl.com" } +] +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Programming Language :: Python", + "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 :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Topic :: Software Development :: Libraries", + "Topic :: Utilities", +] +dependencies = [ + "scapy>=2.5.0", + "crc8>=0.1.0", + "pyaardvark>=0.7.1", + "mashumaro>=3.5" +] + +[project.urls] +Documentation = "https://github.com/jls5177/mctp-emu#readme" +Issues = "https://github.com/jls5177/mctp-emu/issues" +Source = "https://github.com/jls5177/mctp-emu" + +[tool.hatch.metadata] +allow-direct-references = true + +[tool.hatch.version] +source = "regex_commit" +path = "src/pymctp/__about__.py" +#commit_extra_args = ["-e"] + +[tool.hatch.build.targets.sdist] +exclude = [ + ".history", + ".ruff_cache", + ".venv", + ".vscode", + "dist", +] + +[tool.hatch.envs.types] +extra-dependencies = [ + "mypy>=1.0.0", +] +[tool.hatch.envs.types.scripts] +check = "mypy --install-types --non-interactive {args:src/pymctp tests}" + +[tool.hatch.envs.default] +type = "virtual" +path = ".venv" + +# Ruff +[tool.ruff] +target-version = "py310" +line-length = 120 +exclude = ["./.history", "./.venv"] + +# Coverage +[tool.coverage.run] +source_pkgs = ["pymctp", "tests"] +branch = true +parallel = true +omit = [ + "src/pymctp/__about__.py", +] + +[tool.coverage.paths] +pymctp = ["src/pymctp", "*/pymctp/src/pymctp"] +tests = ["tests", "*/pymctp/tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] diff --git a/src/pymctp/__about__.py b/src/pymctp/__about__.py new file mode 100644 index 0000000..c9fe23d --- /dev/null +++ b/src/pymctp/__about__.py @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2024-present Justin Simon +# +# SPDX-License-Identifier: MIT +__version__ = "0.0.1" diff --git a/src/pymctp/__init__.py b/src/pymctp/__init__.py new file mode 100644 index 0000000..f459b26 --- /dev/null +++ b/src/pymctp/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2024-present Justin Simon +# +# SPDX-License-Identifier: MIT diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..f459b26 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2024-present Justin Simon +# +# SPDX-License-Identifier: MIT