diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..95d4fc1 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,76 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + pull_request: + # The branches below must be a subset of the branches above + branches: [ "master" ] + schedule: + - cron: '24 3 * * 6' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'python' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..81f2759 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,46 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + pull_request: + branches: [ "master" ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + if: '! github.event.pull_request.draft' + runs-on: ${{ matrix.os }} + + strategy: + matrix: + python-version: [ 3.8, 3.9, "3.10", "3.11", "3.12" ] + os: [ ubuntu-latest, macos-latest ] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Lint with flake8 + run: | + python -m pip install flake8 + flake8 . --max-line-length=127 + - name: Verify sorted imports + run: | + python -m pip install isort + isort . -m HANGING_INDENT -l 120 --check-only + - name: Test install + run: | + python -m pip install --upgrade pip + python -m pip install -U . + - name: Test + run: | + c-struct "struct dirent" + c-struct "struct dirent" d_ino + c-const EAGAIN diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..fdda02e --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,29 @@ +# This workflows will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +name: Upload Python Package + +on: + release: + types: [ created ] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -U build setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python -m build + twine upload dist/* diff --git a/.gitignore b/.gitignore index 875ed12..95fcc14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -._DS_Store +.DS_Store .idea dist *.egg_info diff --git a/c_helpers/__main__.py b/c_helpers/__main__.py index cbfe09d..20ff00c 100644 --- a/c_helpers/__main__.py +++ b/c_helpers/__main__.py @@ -1,28 +1,23 @@ import os +from pathlib import Path from tempfile import NamedTemporaryFile from typing import Optional import click -from pathlib import Path - from plumbum import local clang = local['clang'] SUFFIX = '.mm' if os.uname().sysname == 'Darwin' else '.cpp' -HEADERS = ['stdio.h', - 'unistd.h', - 'errno.h', - 'sys/socket.h', - 'sys/stat.h', - 'sys/types.h', - 'sys/dir.h', - 'sys/dirent.h', - 'dlfcn.h', - 'sys/utsname.h', - 'resolv.h', - 'AppleArchive/AADefs.h'] +HEADERS = ['stdio.h', 'unistd.h', 'errno.h', 'sys/socket.h', 'sys/stat.h', 'sys/types.h', 'sys/dir.h', + 'dlfcn.h', 'sys/utsname.h', 'resolv.h', ] + +if os.uname().sysname == 'Darwin': + HEADERS += ['sys/dirent.h', 'AppleArchive/AADefs.h', ] +else: + HEADERS += ['dirent.h', ] + FRAMEWORKS = ['Foundation', 'CoreFoundation', 'SystemConfiguration', 'CoreGraphics', 'CoreImage'] C_STRUCT_MEMBER_FORMAT = r''' @@ -32,8 +27,9 @@ printf("{highlight}sizeof({name}): {default}%lu (0x%.2x)\n\ {highlight}offsetof({name}, {member}): {default}%lu (0x%.2x)\n\ {highlight}sizeof({name}::{member}): {default}%lu (0x%.2x)", \ -sizeof(var), sizeof(var), __builtin_offsetof({name}, {member}), __builtin_offsetof({name}, {member}), sizeof(var.{member}), sizeof(var.{member})); - +sizeof(var), sizeof(var), __builtin_offsetof({name}, {member}), __builtin_offsetof({name}, {member}), \ +sizeof(var.{member}), sizeof(var.{member})); + return 0; }} ''' diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7dda5ae --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +click +plumbum \ No newline at end of file