Corrected gitignore mistake

This commit is contained in:
Cian Hughes
2024-01-10 17:13:07 +00:00
parent 465eb89ab8
commit 0c73e89df9
3 changed files with 77 additions and 2 deletions

4
.gitignore vendored
View File

@@ -200,5 +200,5 @@ cython_debug/
.swagger-codegen*
src/portainer_api/*
# These files do need to be included though:
!src/portainer/pyproject.toml
!src/portainer/build.py
!src/portainer_api/pyproject.toml
!src/portainer_api/build.py

View File

@@ -0,0 +1,50 @@
from pathlib import Path
import requests # type: ignore
import docker # type: ignore
def fetch_portainer_api_spec(version: str):
"""Gets and caches the portainer api spec for a given version"""
if not Path(f".cache/portainer_api/{version}/swagger.json").exists():
Path(f".cache/portainer_api/{version}").mkdir(parents=True, exist_ok=True)
json_request = requests.get(f"https://api.swaggerhub.com/apis/portainer/portainer-ce/{version}/swagger.json")
json_request.raise_for_status()
with open(f".cache/portainer_api/{version}/swagger.json", "w") as f:
f.write(json_request.text)
def build_portainer_api(version: str):
"""Builds the portainer api"""
# Path("src/portainer_api").mkdir(parents=True, exist_ok=True)
docker_client = docker.from_env()
docker_client.containers.run(
"swaggerapi/swagger-codegen-cli",
"generate -i /schemas/swagger.json -l python -o /local -D packageName=portainer",
mounts = [
docker.types.Mount(
target="/local",
source=str(Path().resolve()),
type="bind"
),
docker.types.Mount(
target="/schemas",
source=str(Path(f".cache/portainer_api/{version}").resolve()),
type="bind"
),
],
auto_remove=True,
)
def init_portainer_api():
c = docker.from_env().containers.run("portainer/portainer-ce:latest", detach=True, tty=True, remove=True)
portainer_version = c.exec_run("/portainer --version").output.decode().strip()
c.stop()
fetch_portainer_api_spec(portainer_version)
build_portainer_api(portainer_version)
def build():
init_portainer_api()
if __name__ == "__main__":
build()

View File

@@ -0,0 +1,25 @@
[tool.poetry]
name = "portainer"
version = "0.1.0"
description = ""
authors = ["Cian Hughes <cian.hughes@dcu.ie>"]
packages = [{ include = "portainer", from = "." }]
[tool.poetry.dependencies]
python = "^3.11"
requests = "^2.31.0"
docker = "^7.0.0"
[tool.poetry.build]
script = "build.py"
generate-setup-file = false
[build-system]
requires = ["poetry-core", "setuptools", "requests", "docker"]
build-backend = "poetry.core.masonry.api"
[project]
dynamic = ["dependencies"]
[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }