Skip to content

Commit

Permalink
Various fixes and tweaks to make the library usable
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMcGrath committed Dec 5, 2024
1 parent 05893bb commit ba352b7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
dynamic = ["version"]
name = "tenint"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
Expand Down Expand Up @@ -34,8 +34,15 @@ testing = [
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.version]
path = "tenint/__init__.py"

[tool.hatch.build.targets.sdist]
include = ["tenint/*py", "tenint/templates"]
include = [
"tenint/*py",
"tenint/models/*py",
"tenint/templates"
]

[tool.uv]
dev-dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion tenint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .models.configuration import Configuration, Settings # noqa F401
from .connector import Connector # noqa F401

__version__ = '1.0.0'
__version__ = '0.1.3'
8 changes: 6 additions & 2 deletions tenint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from rich.panel import Panel
from typer import Option, Typer

from tenint.models.marketplace import MarketplaceConnector
from tenint.models.pyproject import PyProject

console = Console()
Expand Down Expand Up @@ -111,8 +112,11 @@ def build_connector(
dockerfile.unlink()


@app.command()
@app.command('marketplace')
def gen_marketplace(
path: Annotated[Path, Option(help='connector code path')] = Path('.'),
):
pass
mpfile = path.joinpath('marketplace.json')
with mpfile.open('w', encoding='utf-8') as fobj:
mp = MarketplaceConnector.load_from_pyproject('pyproject.toml')
fobj.write(mp.model_dump_json())
6 changes: 3 additions & 3 deletions tenint/models/marketplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ def load_from_pyproject(
else:
if isinstance(filename, str):
filename = Path(filename)
with filename.open('rb') as fobj:
obj = PyProject(**tomllib.load(pf))
with filename.open("rb") as fobj:
obj = PyProject(**tomllib.load(fobj))
return cls(
name=obj.tool.tenint.connector.title,
slug=obj.project.name,
description=obj.project.description,
icon_url=obj.project.urls.logo,
image_url=obj.project.connector.images.amd64,
image_url=obj.tool.tenint.connector.images.amd64,
marketplace_tag=obj.project.version,
connector_owner=obj.project.authors[0].name,
support_contact=obj.project.authors[0].email,
Expand Down
7 changes: 3 additions & 4 deletions tenint/models/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ class TenintConnectorUrls(BaseModel):

class Project(BaseModel):
name: str
description: str
version: str
authors: list[ProjectAuthor]
urls: TenintConnectorUrls
dependencies: list[str]
optional_dependencies: Annotated[
TestingDependencies, Field(alias='optional-dependencies')
TestingDependencies, Field(alias="optional-dependencies")
]


Expand All @@ -37,10 +38,8 @@ class TenintImages(BaseModel):

class TenintConnector(BaseModel):
title: str
products: list[str]
tags: list[str]
timeout: int = 3600
contact: EmailStr

images: TenintImages


Expand Down
9 changes: 8 additions & 1 deletion tenint/templates/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
FROM python:3.12-alpine AS build
RUN pip install uv && uv install tenint
RUN pip install uv && uv pip install --system tenint
RUN addgroup -S connector && adduser connector -S -G connector -h /connector

ADD --chown=connector:connector ./ /connector/

RUN uv pip install --system -r /connector/pyproject.toml


FROM build AS test
WORKDIR /connector/
RUN uv pip install --system "tenint[testing]" \
&& uv pip install --system --extra testing -r /connector/pyproject.toml
RUN ruff check
RUN python -m pytest
RUN uv export --format requirements-txt | uv tool run pip-audit
RUN uv tool run \
--with "bandit[toml,baseline,sarif]" \
bandit -c pyproject.toml -r . -ll
RUN tenint marketplace

FROM build AS release
WORKDIR /connector/
COPY --from=test --chown=connector:connector /connector/marketplace.json marketplace.json
ENTRYPOINT ["python", "connector.py"]
2 changes: 1 addition & 1 deletion tenint/templates/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ support = "https://example.com/support"
name = "Company, Inc."

# Support contact email for any issues with the connector.
email = "suppoert@example.com"
email = "support@example.com"

[project.optional-dependencies]
# Any testing libraries that need to be installed to support
Expand Down

0 comments on commit ba352b7

Please sign in to comment.