From 34936d5f253d513f482fc153ca30f9b938e5e9a5 Mon Sep 17 00:00:00 2001 From: Mukundan314 Date: Tue, 30 Nov 2021 18:08:36 +0530 Subject: [PATCH] fix pip installation for cffi --- .gitignore | 1 + cffi/MANIFEST.in | 1 + cffi/setup.py | 46 ++++++++++++++++++++------- cffi/src/notcurses/build_notcurses.py | 6 ++-- 4 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 cffi/MANIFEST.in diff --git a/.gitignore b/.gitignore index 918a841e1..92f19c5df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /build/ doc/examples/book obj-x86_64-linux-gnu +cffi/include python/.eggs/ python/build/ python/dist/ diff --git a/cffi/MANIFEST.in b/cffi/MANIFEST.in new file mode 100644 index 000000000..18e7a8b29 --- /dev/null +++ b/cffi/MANIFEST.in @@ -0,0 +1 @@ +recursive-include include *.h diff --git a/cffi/setup.py b/cffi/setup.py index a483d5c14..1852a4d08 100644 --- a/cffi/setup.py +++ b/cffi/setup.py @@ -1,11 +1,28 @@ from setuptools import setup from setuptools.command.install import install +from setuptools.command.sdist import sdist +from distutils.command.build import build import os -import sys +import shutil + +here = os.path.dirname(__file__) or '.' + + +def read(fname): + return open(os.path.join(os.path.dirname(__file__), fname)).read() + + +def copy_include_dir(): + src = os.path.join(here, "../include") + dst = os.path.join(here, "include") + if os.path.exists(src): + if os.path.exists(dst): + shutil.rmtree(dst) + shutil.copytree(src, dst) + class ManPageGenerator(install): def run(self): - here = os.path.dirname(__file__) or '.' files = [] outfile = 'notcurses-pydemo.1' pypandoc.convert_file(os.path.join(here, 'notcurses-pydemo.1.md'), 'man', outputfile=outfile, extra_args=['-s']) @@ -19,18 +36,25 @@ class ManPageGenerator(install): print("data_files: ", self.distribution.data_files) super().run() + +class SdistCommand(sdist): + def run(self): + copy_include_dir() + super().run() + + +class BuildCommand(build): + def run(self): + copy_include_dir() + super().run() + + +cmdclass = {"sdist": SdistCommand, "build": BuildCommand} try: import pypandoc + cmdclass["install"] = ManPageGenerator except ImportError: print("warning: pypandoc module not found, won't generate man pages") - manpageinstaller=dict() -else: - manpageinstaller=dict( - install=ManPageGenerator, - ) - -def read(fname): - return open(os.path.join(os.path.dirname(__file__), fname)).read() setup( name="notcurses", @@ -61,5 +85,5 @@ setup( 'Programming Language :: Python', ], include_package_data=True, - cmdclass=manpageinstaller + cmdclass=cmdclass, ) diff --git a/cffi/src/notcurses/build_notcurses.py b/cffi/src/notcurses/build_notcurses.py index f1e0f448a..a690fa31e 100644 --- a/cffi/src/notcurses/build_notcurses.py +++ b/cffi/src/notcurses/build_notcurses.py @@ -11,7 +11,7 @@ ffibuild.set_source( libraries=["notcurses"], ) -with open('../include/notcurses/notcurses.h') as fp: +with open('include/notcurses/notcurses.h') as fp: lines = fp.read().splitlines() # remove initial #includes and #ifdefs first = next(i for i, line in enumerate(lines) if 'notcurses_version' in line) @@ -21,7 +21,7 @@ with open('../include/notcurses/notcurses.h') as fp: del lines[last:] # same with direct.h -with open('../include/notcurses/direct.h') as fp: +with open('include/notcurses/direct.h') as fp: direct_lines = fp.read().splitlines() first = next(i for i, line in enumerate(direct_lines) if '#define ALLOC' in line) del direct_lines[:first+1] @@ -29,7 +29,7 @@ with open('../include/notcurses/direct.h') as fp: del direct_lines[last:] # and also nckeys.key -with open('../include/notcurses/nckeys.h') as fp: +with open('include/notcurses/nckeys.h') as fp: nckeys_lines = fp.read().splitlines() first = next(i for i, line in enumerate(nckeys_lines) if '#define NCKEY_' in line) del nckeys_lines[:first]