Skip to content

Commit

Permalink
Move FFI build modules out of src
Browse files Browse the repository at this point in the history
  • Loading branch information
zacikpa committed Jul 1, 2024
1 parent cabb871 commit 9e14b7c
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ build:
- make
- make install
- pip install cffi
- python ./python/src/libcpuid/_ffi_build_manual.py ./libcpuid/libcpuid.h ./install
- python ./python/ffi_build_rtd.py ./libcpuid/libcpuid.h ./install

sphinx:
configuration: python/docs/conf.py
Expand Down
4 changes: 2 additions & 2 deletions python/src/libcpuid/_ffi_build.py → python/ffi_build.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""
Internal module for compiling the C FFI.
Module for compiling the C FFI.
"""

import subprocess
import os
from cffi import FFI


class FFIBuildException(Exception):
"""Generic exception for errors occuring during the CFFI build."""



def find_header():
"""
Obtains libcpuid header file location via pkg-config.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""
Internal library for compiling the C FFI.
Script for compiling the C FFI for the live documentation.
"""


import subprocess
import sys
import os
Expand All @@ -20,6 +19,6 @@
libraries=["cpuid"],
library_dirs=[library_dir],
include_dirs=[os.path.join(install_dir, "include", "libcpuid")],
extra_link_args=[f"-Wl,-rpath={library_dir}"]
extra_link_args=[f"-Wl,-rpath={library_dir}"],
)
ffibuilder.compile(verbose=True)
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from setuptools import setup

setup(
cffi_modules=["src/libcpuid/_ffi_build.py:ffibuilder"],
cffi_modules=["ffi_build.py:ffibuilder"],
)
5 changes: 4 additions & 1 deletion python/src/libcpuid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
libcpuid C library, which provides CPU identification.
"""

from libcpuid._libcpuid_cffi import ffi, lib # pylint: disable=no-name-in-module, import-error
from libcpuid._libcpuid_cffi import ( # pylint: disable=no-name-in-module, import-error
ffi,
lib,
)
from libcpuid import cpuid, enums
from libcpuid._utils import c_string_to_str

Expand Down
4 changes: 3 additions & 1 deletion python/src/libcpuid/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""

from typing import Optional
from libcpuid._libcpuid_cffi import ffi # pylint: disable=no-name-in-module, import-error
from libcpuid._libcpuid_cffi import ( # pylint: disable=no-name-in-module, import-error
ffi,
)


def c_string_to_str(c_string) -> str:
Expand Down
5 changes: 4 additions & 1 deletion python/src/libcpuid/cpuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
from typing import Optional
from libcpuid import enums, cpusgx
from libcpuid._utils import c_string_to_str, optional_int
from libcpuid._libcpuid_cffi import lib, ffi # pylint: disable=no-name-in-module, import-error
from libcpuid._libcpuid_cffi import ( # pylint: disable=no-name-in-module, import-error
lib,
ffi,
)


class CPUID: # pylint: disable=too-many-public-methods
Expand Down
4 changes: 3 additions & 1 deletion python/src/libcpuid/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"""

from enum import IntEnum
from libcpuid._libcpuid_cffi import lib # pylint: disable=no-name-in-module, import-error
from libcpuid._libcpuid_cffi import ( # pylint: disable=no-name-in-module, import-error
lib,
)


def _construct_enum(name, prefix):
Expand Down

0 comments on commit 9e14b7c

Please sign in to comment.