Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use setuptools for plugin mechanism. #33

Merged
merged 17 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 8 additions & 38 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/statick-tooling
permissions:
id-token: write

steps:
- uses: actions/checkout@v3
Expand All @@ -18,47 +23,12 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: '3.11'

- uses: actions/cache@v3
if: startsWith(runner.os, 'Linux')
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- uses: actions/cache@v3
if: startsWith(runner.os, 'macOS')
with:
path: ~/Library/Caches/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- uses: actions/cache@v3
if: startsWith(runner.os, 'Windows')
with:
path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- name: Install tools
run: |
python -m pip install --upgrade setuptools
python -m pip install --upgrade wheel
cache: 'pip'

- name: Build a binary wheel and a source tarball
run: |
python setup.py sdist bdist_wheel

- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TEST_TOKEN }}
repository_url: https://test.pypi.org/legacy/
pip install -q build
python -m build

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
64 changes: 15 additions & 49 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,77 +8,43 @@ on: # NOLINT
- cron: '0 10 * * MON'
workflow_dispatch:


jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-20.04, ubuntu-22.04, windows-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']
os: [macos-latest, ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, windows-latest]
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- uses: actions/setup-node@v3
with:
node-version: '16'

- uses: actions/cache@v3
if: startsWith(runner.os, 'Linux')
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- uses: actions/cache@v3
if: startsWith(runner.os, 'macOS')
with:
path: ~/Library/Caches/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

- uses: actions/cache@v3
if: startsWith(runner.os, 'Windows')
- uses: actions/setup-node@v4
with:
path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
node-version: '20'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install --upgrade wheel
python -m pip install --upgrade coverage
python -m pip install --upgrade mypy
python -m pip install --upgrade statick
python -m pip install --upgrade statick-md
python -m pip install --upgrade tox
python -m pip install --upgrade tox-gh-actions
python -m pip install --upgrade virtualenv
python -m pip install -r requirements.txt
pip install --upgrade pip
pip install .[docs,test]

# Have to install newer version from non-apt source due to SSL library compatibility issues.
- name: Install Node and node-based tools (Linux)
if: matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu-22.04'
- name: Install Node-based tools (Linux)
if: runner.os == 'Linux'
run: |
npm install -g markdownlint-cli
npm install -g dockerfilelint
npm install -g dockerfile_lint

# Do not install on macos until there is a hadolint release for macos (Darwin on arm64 architecture).
- name: Install Hadolint binary (github)
if: matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu-22.04' || matrix.os == 'windows-latest'
if: runner.os == 'Linux' || runner.os == 'Windows'
run: |
mkdir -p $HOME/.local/bin
echo "$HOME/.local/bin" >> $GITHUB_PATH
Expand All @@ -87,7 +53,7 @@ jobs:
mv hadolint $HOME/.local/bin/

- name: Install Hadolint docker image (Linux)
if: matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu-22.04'
if: runner.os == 'Linux'
run: |
docker pull hadolint/hadolint:latest

Expand All @@ -105,12 +71,12 @@ jobs:
fail_ci_if_error: false

- name: Statick Documentation
if: matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu-22.04'
if: runner.os == 'Linux'
run: |
statick . --check --user-paths . --profile documentation.yaml

- name: Self check
if: matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu-22.04'
if: runner.os == 'Linux'
run: |
mkdir statick-output
statick . --output-directory statick-output --check --profile self_check.yaml
47 changes: 35 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,55 @@ Custom exceptions can be applied the same way they are with [Statick exceptions]

## Table of Contents

* [Installation](#installation)
* [Usage](#usage)
* [Existing Plugins](#existing-plugins)
* [Discovery Plugins](#discovery-plugins)
* [Tool Plugins](#tool-plugins)
* [Contributing](#contributing)
* [Mypy](#mypy)
* [Formatting](#formatting)
- [Statick Tooling Plugins](#statick-tooling-plugins)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Usage](#usage)
- [Pip Install](#pip-install)
- [Pip Install and Custom Configuration](#pip-install-and-custom-configuration)
- [Source Install and Custom Configuration](#source-install-and-custom-configuration)
- [Existing Plugins](#existing-plugins)
- [Discovery Plugins](#discovery-plugins)
- [Tool Plugins](#tool-plugins)
- [Contributing](#contributing)
- [Mypy](#mypy)
- [Formatting](#formatting)

## Installation

The recommended method to install these Statick plugins is via pip:

```shell
python3 -m pip install statick-tooling
pip install statick-tooling
```

You can also clone the repository and use it locally.

## Usage

Make sure you install all the dependencies from apt/npm:
Make sure you install all the dependencies from apt/npm.
See <https://github.com/nodesource/distributions> for Node/npm installation instructions.

Configure npm to allow a non-root user to install packages.

```shell
npm config set prefix '~/.local/'
```

Make sure `~/.local/bin` exists.
Check your `PATH` with `echo $PATH`.
If `~/.local/bin` is not listed then add it to your `PATH`.

```shell
mkdir -p ~/.local/bin
echo 'export PATH="$HOME/.local/bin/:$PATH"' >> ~/.bashrc
```

Install npm packages.

```shell
cat install.txt | xargs sudo apt-get install -y
cat npm-deps.txt | xargs sudo npm install -g
npm install -g dockerfilelint
npm install -g dockerfile_lint
```

### Pip Install
Expand Down
1 change: 0 additions & 1 deletion install.txt

This file was deleted.

2 changes: 0 additions & 2 deletions npm-deps.txt

This file was deleted.

66 changes: 66 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "statick-tooling"
authors = [{name = "NIWC Pacific"}]
description="Statick analysis plugins for Tooling files."
version = "0.2.0"
readme = "README.md"
requires-python = ">=3.9"
license = {text = "CC0-1.0"}
classifiers = [
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Quality Assurance",
"Topic :: Software Development :: Testing",
"Typing :: Typed",
]

dependencies = [
"importlib_metadata",
"statick@git+https://github.com/tdenewiler/statick@stdlib-plugins",
denewiler marked this conversation as resolved.
Show resolved Hide resolved
"types-docutils",
]

[tool.setuptools.package-data]
statick_tool = [
"rsc/*",
"rsc/.*",
]

[project.entry-points."statick_tool.plugins.discovery"]
dockerfile = "statick_tool.plugins.discovery.dockerfile:DockerfileDiscoveryPlugin"

[project.entry-points."statick_tool.plugins.tool"]
dockerfile-lint = "statick_tool.plugins.tool.dockerfile_lint:DockerfileULintToolPlugin"
dockerfilelint = "statick_tool.plugins.tool.dockerfilelint:DockerfileLintToolPlugin"
hadolint = "statick_tool.plugins.tool.hadolint:HadolintToolPlugin"

[project.urls]
"Homepage" = "https://github.com/sscpac/statick-tooling"
"Bug Tracker" = "https://github.com/sscpac/statick-tooling/issues"

[project.optional-dependencies]
test = [
"coverage",
"mock",
"pytest",
"pytest-cov",
"statick-md@git+https://github.com/tdenewiler/statick-md@stdlib-plugins",
tdenewiler marked this conversation as resolved.
Show resolved Hide resolved
"tox",
"tox-gh-actions",
]
docs = [
"sphinx==1.7.9",
"yaml-1.3",
]

[tool.isort]
profile = "black"
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

51 changes: 0 additions & 51 deletions setup.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,22 @@ def add_filename(cls, output: str, src: str) -> str:
"""Add the filename to the json output.

This is because dockerfile-lint does not include the filename in the output.

Some warnings and errors are included in the tool output, but they are not in
json format. Those lines start with a "(". Any line that does not start with a
"(" is considered to be a line of output.
"""
updated_output = ""
for line in output.splitlines():
if not line.startswith("("):
updated_output = updated_output + line + "\n"
try:
json_dict = json.loads(output)
json_dict = json.loads(updated_output)
json_dict["filename"] = src
return json.dumps(json_dict)
except ValueError as ex:
logging.warning("ValueError: %s", ex)
return output
return updated_output

def parse_output(
self, total_output: List[str], package: Optional[Package] = None
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion src/statick_tooling/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion src/statick_tooling/plugins/__init__.py

This file was deleted.

Loading