Skip to content

Commit

Permalink
Make package runnable
Browse files Browse the repository at this point in the history
  • Loading branch information
Croydon committed May 10, 2024
1 parent 89b2e1f commit 07ad0fe
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 30 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,25 @@ jobs:
name: "Tests"
runs-on: ubuntu-22.04
env:
CONAN_LOGGING_LEVEL: 10
CONAN_LOGGING_LEVEL: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: |
cd bincrafters_conan_remote/
pip install -r requirements.txt
pip install -r requirements_dev.txt
- name: Install package
run: |
pip install .
- name: Start Local Server
run: |
fastapi dev remote.py & disown
bincrafters-remote-conan run & disown
- name: Configure Conan
run: |
conan --version
conan user
conan config set general.revisions_enabled=1
conan remote remove conancenter
conan remote add inexorgame http://127.0.0.1:8000/r/github+bincrafters_remote+testing_v-998+inexorgame/
conan remote add inexorgame "http://127.0.0.1:8000/r/github+bincrafters_remote+testing_v-998+inexorgame/""
conan remote list
- name: Tests
run: |
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: |
cd bincrafters_conan_remote/
pip install -r requirements.txt
pip install -r requirements_dev.txt
- name: Install package
run: |
pip install .
- name: Configure Conan
run: |
conan --version
Expand All @@ -46,7 +45,7 @@ jobs:
conan remote remove conancenter
- name: Generate
run: |
python generate.py --remote-url https://bincrafters.jfrog.io/artifactory/api/conan/conan-legacy-inexorgame/ --remote-name ${{ env.REMOTE_NAME }}
bincrafters-conan-remote generate --remote-url https://bincrafters.jfrog.io/artifactory/api/conan/conan-legacy-inexorgame/ --remote-name ${{ env.REMOTE_NAME }}
- name: List Generate Files
run: |
du -sh cache/
Expand Down
19 changes: 10 additions & 9 deletions bincrafters_conan_remote/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import atexit
import time
import argparse
import threading

from fastapi import FastAPI, Request
from fastapi.responses import Response
Expand Down Expand Up @@ -139,22 +140,22 @@ def _shell_background(command: str) -> None:
atexit.register(process.kill)
return None

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generate a static Conan remote from an existing Conan remote.")
parser.add_argument("--port", type=int, default=8043, help="Port to run the FastAPI server.")
parser.add_argument("--remote-url", type=str, default="https://bincrafters.jfrog.io/artifactory/api/conan/conan-legacy-inexorgame/", help="Remote URL to generate the static remote from. It can not contain spaces or plus signs (+) and has to end on a slash.")
parser.add_argument("--remote-name", type=str, default="inexorgame", help="Remote URL to generate the static remote from.")
args = parser.parse_args()
def _run_uvicorn(port: int) -> None:
uvicorn.run(app, host="0.0.0.0", port=port, log_level="info")

def run_generate(args):
_PORT = args.port
remote_url_quoted = "{" + args.remote_url + "}"

server_thread = threading.Thread(target=_run_uvicorn, args=(_PORT,))
server_thread.start()

# uvicorn.run(app, host="0.0.0.0", port=_PORT, log_level="info")
_shell_background(f"fastapi dev generate.py --port {_PORT} --no-reload")
#_shell_background(f"fastapi dev generate.py --port {_PORT} --no-reload")
time.sleep(3)

_shell("conan remote remove bincrafters-remote-tmp || true", check=False)
_shell(f"conan remote add bincrafters-remote-tmp http://127.0.0.1:{_PORT}/r/conan+{remote_url_quoted}+{args.remote_name}/")
_shell("conan remote remove bincrafters-remote-tmp", check=False)
_shell(f'conan remote add bincrafters-remote-tmp "http://127.0.0.1:{_PORT}/r/conan+{remote_url_quoted}+{args.remote_name}/"')
_shell("conan remote list")

# Get all recipes and recipes revisions
Expand Down
22 changes: 22 additions & 0 deletions bincrafters_conan_remote/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import argparse
from bincrafters_conan_remote.generate import run_generate
from bincrafters_conan_remote.remote import run_remote


def run():
parser = argparse.ArgumentParser(description="Experimental. Don't use.")
subparsers = parser.add_subparsers(dest="command")
generate_parser = subparsers.add_parser("run", help="Run a local Conan remote that fetches external files.")


generate_parser = subparsers.add_parser("generate", help="Generate a static Conan remote from an existing Conan remote.")
generate_parser.add_argument("--port", type=int, default=8043, help="Port to run the FastAPI server.")
generate_parser.add_argument("--remote-url", type=str, default="https://bincrafters.jfrog.io/artifactory/api/conan/conan-legacy-inexorgame/", help="Remote URL to generate the static remote from. It can not contain spaces or plus signs (+) and has to end on a slash.")
generate_parser.add_argument("--remote-name", type=str, default="inexorgame", help="Remote URL to generate the static remote from.")

args = parser.parse_args()

if args.command == "run":
run_remote(args)
elif args.command == "generate":
run_generate(args)
5 changes: 3 additions & 2 deletions bincrafters_conan_remote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io
import os
import json
import uvicorn

from fastapi import FastAPI, Request
from fastapi.responses import Response
Expand Down Expand Up @@ -130,7 +131,7 @@ async def get_external_site(request: Request, url_path: str):
logger.info(f"Getting URL: {getting_url}")
r = await client.get(getting_url, headers={'User-Agent': user_agent})

logger.info(f"Headers: {r.headers}")
# logger.info(f"Headers: {r.headers}")
content_type = r.headers.get('Content-Type', 'application/json')
if remote_http_suffix == ".json":
content_type = "application/json"
Expand All @@ -149,5 +150,5 @@ async def get_external_site(request: Request, url_path: str):



if __name__ == "__main__":
def run_remote(args):
uvicorn.run(app, host="0.0.0.0", port=8000)
1 change: 1 addition & 0 deletions bincrafters_conan_remote/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
fastapi>=0.111.0,<1
conan==1.*
12 changes: 5 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ def get_requires(filename):
# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# pip to create the appropriate form of executable for the target platform.
#entry_points={
# 'console_scripts': [
# 'conan=conans.conan:run',
# 'conan_server=conans.conan_server:run',
# 'conan_build_info=conans.build_info.command:run'
# ],
#},
entry_points={
"console_scripts": [
"bincrafters-conan-remote=bincrafters_conan_remote.main:run"
],
},
)

0 comments on commit 07ad0fe

Please sign in to comment.