-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4820c6
commit f9dc77f
Showing
14 changed files
with
233 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright (c) 2024 Andi Hellmund. All rights reserved. | ||
|
||
# This work is licensed under the terms of the BSD-3-Clause license. | ||
# For a copy, see <https://opensource.org/license/bsd-3-clause>. | ||
|
||
import json | ||
from collections.abc import Mapping | ||
from pathlib import Path | ||
|
||
from pydantic import BaseModel, RootModel | ||
|
||
from cpp_dev.common.process import run_command | ||
|
||
from .types import ConanPackageReference | ||
|
||
############################################################################### | ||
# Public API ### | ||
############################################################################### | ||
|
||
|
||
def conan_config_install(conan_config_dir: Path) -> None: | ||
"""Run 'conan config install'.""" | ||
run_command("conan", "config", "install", str(conan_config_dir)) | ||
|
||
|
||
def conan_remote_login(remote: str, user: str, password: str) -> None: | ||
"""Run 'conan remote login'.""" | ||
run_command( | ||
"conan", | ||
"remote", | ||
"login", | ||
remote, | ||
user, | ||
"-p", | ||
password, | ||
) | ||
|
||
class ConanRemoteListResult(RootModel): | ||
root: Mapping[str, Mapping[str, dict]] | ||
|
||
def conan_list(remote: str, name: str) -> Mapping[ConanPackageReference, dict]: | ||
stdout, stderr = run_command( | ||
"conan", | ||
"list", | ||
"--json", | ||
f"--remote={remote}", | ||
f"{name}", | ||
) | ||
return json.loads(stdout)[remote] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright (c) 2024 Andi Hellmund. All rights reserved. | ||
|
||
# This work is licensed under the terms of the BSD-3-Clause license. | ||
# For a copy, see <https://opensource.org/license/bsd-3-clause>. | ||
|
||
from pathlib import Path | ||
|
||
from cpp_dev.common.types import SemanticVersion | ||
from cpp_dev.conan.command_wrapper import conan_list | ||
from cpp_dev.conan.setup import CONAN_REMOTE | ||
from cpp_dev.conan.types import ConanPackageReference | ||
from cpp_dev.conan.utils import conan_env | ||
|
||
############################################################################### | ||
# Public API ### | ||
############################################################################### | ||
|
||
def get_available_versions(conan_home: Path, repository: str, name: str) -> list[SemanticVersion]: | ||
"""Retrieve available versions for a package represented by repository (aka. Conan user) and name. | ||
Result: | ||
The versions get sorted in reverse order such that the latest version is first in the list. | ||
""" | ||
with conan_env(conan_home): | ||
package_references = _retrieve_conan_package_references(repository, name) | ||
available_versions = sorted([ref.version for ref in package_references], reverse=True) | ||
return available_versions | ||
|
||
|
||
|
||
############################################################################### | ||
# Implementation ### | ||
############################################################################### | ||
|
||
def _retrieve_conan_package_references(repository: str, name: str) -> list[ConanPackageReference]: | ||
package_data = conan_list(CONAN_REMOTE, name) | ||
package_references = [ | ||
ref | ||
for ref in package_data.keys() | ||
if ref.user == repository | ||
] | ||
return package_references |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2024 Andi Hellmund. All rights reserved. | ||
|
||
# This work is licensed under the terms of the BSD-3-Clause license. | ||
# For a copy, see <https://opensource.org/license/bsd-3-clause>. | ||
|
||
from collections.abc import Generator | ||
from contextlib import contextmanager | ||
from pathlib import Path | ||
|
||
from cpp_dev.common.utils import updated_env | ||
|
||
############################################################################### | ||
# Public API ### | ||
############################################################################### | ||
|
||
CONAN_HOME_ENV_VAR = "CONAN_HOME" | ||
|
||
|
||
@contextmanager | ||
def conan_env(conan_home: Path) -> Generator[None]: | ||
"""A context manager for setting the CONAN_HOME environment variable.""" | ||
with updated_env(**{CONAN_HOME_ENV_VAR: str(conan_home)}): | ||
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.