Skip to content

Commit

Permalink
Fixes for pathlib and ConfigParser.read
Browse files Browse the repository at this point in the history
  • Loading branch information
robertodr committed Sep 2, 2018
1 parent baaf3c0 commit 728db60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
17 changes: 9 additions & 8 deletions chapter-11/recipe-03/cxx-example/account/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from subprocess import check_output
from cffi import FFI
import os
import sys
from configparser import ConfigParser
from pathlib import Path
from subprocess import check_output

from cffi import FFI


def get_lib_handle(definitions, header_file, library_file):
Expand All @@ -28,9 +29,9 @@ def get_lib_handle(definitions, header_file, library_file):
_cfg_file = _this_path / 'interface_file_names.cfg'
if _cfg_file.exists():
config = ConfigParser()
config.read(_cfg_file)
config.read(str(_cfg_file))
header_file_name = config.get('configuration', 'header_file_name')
_header_file = _this_path / 'include' / header_file_name
_header_file = _this_path / 'include' / header_file_name
_header_file = str(_header_file)
library_file_name = config.get('configuration', 'library_file_name')
_library_file = _this_path / 'lib' / library_file_name
Expand All @@ -41,10 +42,10 @@ def get_lib_handle(definitions, header_file, library_file):
_library_file = os.getenv('ACCOUNT_LIBRARY_FILE')
assert _library_file is not None

_lib = get_lib_handle(definitions=['-DACCOUNT_API=', '-DACCOUNT_NOINCLUDE'],
header_file=_header_file,
library_file=_library_file)

_lib = get_lib_handle(
definitions=['-DACCOUNT_API=', '-DACCOUNT_NOINCLUDE'],
header_file=_header_file,
library_file=_library_file)

# we change names to obtain a more pythonic API
new = _lib.account_new
Expand Down
17 changes: 9 additions & 8 deletions chapter-11/recipe-03/fortran-example/account/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from subprocess import check_output
from cffi import FFI
import os
import sys
from configparser import ConfigParser
from pathlib import Path
from subprocess import check_output

from cffi import FFI


def get_lib_handle(definitions, header_file, library_file):
Expand All @@ -28,9 +29,9 @@ def get_lib_handle(definitions, header_file, library_file):
_cfg_file = _this_path / 'interface_file_names.cfg'
if _cfg_file.exists():
config = ConfigParser()
config.read(_cfg_file)
config.read(str(_cfg_file))
header_file_name = config.get('configuration', 'header_file_name')
_header_file = _this_path / 'include' / header_file_name
_header_file = _this_path / 'include' / header_file_name
_header_file = str(_header_file)
library_file_name = config.get('configuration', 'library_file_name')
_library_file = _this_path / 'lib' / library_file_name
Expand All @@ -41,10 +42,10 @@ def get_lib_handle(definitions, header_file, library_file):
_library_file = os.getenv('ACCOUNT_LIBRARY_FILE')
assert _library_file is not None

_lib = get_lib_handle(definitions=['-DACCOUNT_API=', '-DACCOUNT_NOINCLUDE'],
header_file=_header_file,
library_file=_library_file)

_lib = get_lib_handle(
definitions=['-DACCOUNT_API=', '-DACCOUNT_NOINCLUDE'],
header_file=_header_file,
library_file=_library_file)

# we change names to obtain a more pythonic API
new = _lib.account_new
Expand Down

0 comments on commit 728db60

Please sign in to comment.