Skip to content

Commit

Permalink
refactor config file
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedrichFroebel authored Jul 27, 2023
1 parent 01b1067 commit 2b1bc3b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ def get_djvulibre_version():
return Version(version)


CONFIG_TEMPLATE = """
cdef extern from *:
\"\"\"
#define PYTHON_DJVULIBRE_VERSION "{py_version}"
#define HAVE_MINIEXP_IO_T {have_miniexp_io_t}
\"\"\"
extern const char* PYTHON_DJVULIBRE_VERSION
extern const bint HAVE_MINIEXP_IO_T
"""


class BuildExtension(_build_ext):
name = 'build_ext'

Expand All @@ -134,10 +146,10 @@ def run(self):
for attr, flags in compiler_flags.items():
getattr(extension, attr)
setattr(extension, attr, flags)
new_config = [
f'DEF PYTHON_DJVULIBRE_VERSION = b"{py_version}"',
f'DEF HAVE_MINIEXP_IO_T = {djvulibre_version >= Version("3.5.26")}',
]
new_config = CONFIG_TEMPLATE.format(
py_version=py_version,
have_miniexp_io_t=djvulibre_version >= Version("3.5.26")
)
self.src_dir = src_dir = os.path.join(self.build_temp, 'src')
os.makedirs(src_dir, exist_ok=True)
self.config_path = os.path.join(src_dir, 'config.pxi')
Expand All @@ -146,7 +158,6 @@ def run(self):
old_config = fp.read()
except IOError:
old_config = ''
new_config = '\n'.join(new_config)
if new_config.strip() != old_config.strip():
logger.info(f'creating {self.config_path!r}')
with open(self.config_path, mode='w') as fd:
Expand Down

0 comments on commit 2b1bc3b

Please # to comment.