Skip to content

Commit

Permalink
typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
henryborchers committed Oct 11, 2023
1 parent f17cd1a commit 5d90437
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion uiucprescon/build/conan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
if _version('conan')[0] == "2":
from . import v2 as conan_api
else:
from . import v1 as conan_api
from . import v1 as conan_api # type: ignore[no-redef]

__all__ = ['conan_api']
4 changes: 3 additions & 1 deletion uiucprescon/build/conan/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def build_deps_with_conan(
announce=None
):

conan = conan_api.Conan(cache_folder=os.path.abspath(conan_cache))
conan = conan_api.Conan(
cache_folder=os.path.abspath(conan_cache) if conan_cache else None
)
settings = []
logger = logging.Logger(__name__)
conan_profile_cache = os.path.join(build_dir, "profiles")
Expand Down
16 changes: 13 additions & 3 deletions uiucprescon/build/conan_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import shutil
import abc
from typing import Dict, List, Optional
from typing import Dict, List, Optional, cast, Set
import setuptools
from distutils import ccompiler
from pathlib import Path
Expand All @@ -14,6 +14,7 @@
)
import json
from setuptools.dist import Distribution
from setuptools.command.build_ext import build_ext as BuildExt
import toml
from uiucprescon.build.conan import conan_api
from uiucprescon.build.conan.files import ConanBuildInfo, ConanBuildInfoParser
Expand Down Expand Up @@ -45,11 +46,15 @@ def test_binary_dependents(self, file_path: Path):
class MacResultTester(AbsResultTester):
def test_binary_dependents(self, file_path: Path):
otool = shutil.which("otool")
if otool is None:
raise FileNotFoundError('otool')
self.compiler.spawn([otool, '-L', str(file_path.resolve())])


class WindowsResultTester(AbsResultTester):
def test_binary_dependents(self, file_path: Path):
if self.compiler is None:
raise ValueError('compiler is None')
self.compiler.initialize()

deps = get_win_deps(
Expand All @@ -59,6 +64,8 @@ def test_binary_dependents(self, file_path: Path):
)

system_path = os.getenv('PATH')
if system_path is None:
raise ValueError('PATH variable not set')
for dep in deps:
print(f"{file_path} requires {dep}")
locations = list(filter(os.path.exists, system_path.split(";")))
Expand All @@ -75,6 +82,8 @@ def test_binary_dependents(self, file_path: Path):
class LinuxResultTester(AbsResultTester):
def test_binary_dependents(self, file_path: Path):
ldd = shutil.which("ldd")
if ldd is None:
raise FileNotFoundError("ldd not found")
self.compiler.spawn([ldd, str(file_path.resolve())])


Expand All @@ -89,10 +98,11 @@ def __init__(self, build_ext_cmd) -> None:
self._place_to_add = build_ext_cmd.compiler

def add_libs(self, libs: List[str]):
extension_deps = set()
extension_deps: Set[str] = set()
for lib in reversed(libs):
if lib not in self._place_to_add.libraries and \
lib not in extension_deps:
extension_deps.add(lib)
self._place_to_add.libraries.insert(0, lib)

def add_lib_dirs(self, lib_dirs: List[str]):
Expand Down Expand Up @@ -211,7 +221,7 @@ def getConanBuildInfo(self, root_dir):
return None

def add_deps_to_compiler(self, metadata) -> None:
build_ext_cmd = self.get_finalized_command("build_ext")
build_ext_cmd = cast(BuildExt, self.get_finalized_command("build_ext"))
compiler_adder = CompilerInfoAdder(build_ext_cmd)

include_dirs = metadata['include_paths']
Expand Down
10 changes: 7 additions & 3 deletions uiucprescon/build/pybind11_builder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import abc
import sys
from typing import Optional
from typing import Optional, cast
import pybind11
from pybind11.setup_helpers import Pybind11Extension, build_ext
from . import conan_libs
from setuptools.command.build_py import build_py as Build_Py
from distutils.ccompiler import CCompiler
import os

Expand Down Expand Up @@ -87,7 +88,10 @@ def get_pybind11_include_path(self) -> str:

def _add_conan_libs_to_ext(self, ext: Pybind11Extension):
conan_build_info = os.path.join(
self.get_finalized_command("build_clib").build_temp,
cast(
Build_Py,
self.get_finalized_command("build_clib"),
).build_temp,
"conanbuildinfo.txt"
)
if not os.path.exists(conan_build_info):
Expand All @@ -99,7 +103,7 @@ def _add_conan_libs_to_ext(self, ext: Pybind11Extension):

lib_output = os.path.abspath(os.path.join(self.build_temp, "lib"))

build_py = self.get_finalized_command("build_py")
build_py = cast(Build_Py, self.get_finalized_command("build_py"))
package_path = build_py.get_package_dir(build_py.packages[0])
if os.path.exists(lib_output) and not self._inplace:
dest = os.path.join(self.build_lib, package_path)
Expand Down

0 comments on commit 5d90437

Please sign in to comment.