summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2016-04-11 21:38:30 +0200
committerDave Andreoli <dave@gurumeditation.it>2016-04-11 21:38:30 +0200
commit073eeedaeeaadbe7341cbc67f68c3922947697b8 (patch)
treee9e733f6eda5caea05f8577b7a4a790f267724e6
parent8f549cfaf5a5f77bf2cd2f15e8637fd84e0647f4 (diff)
Make setup.py generate/clean actually work
-rw-r--r--pyolian/generator.py6
-rwxr-xr-xsetup.py127
2 files changed, 97 insertions, 36 deletions
diff --git a/pyolian/generator.py b/pyolian/generator.py
index e7d062b..67018f6 100644
--- a/pyolian/generator.py
+++ b/pyolian/generator.py
@@ -24,7 +24,9 @@ def uncapitalize(s):
24 24
25### Templates ### 25### Templates ###
26 26
27COPYRIGHT = """{0} Copyright (C) 2007-%d various contributors (see AUTHORS) 27COPYRIGHT = """{0} PYOLIAN AUTOGENERATED FILE (never change this line)
28{0}
29{0} Copyright (C) 2007-%d various contributors (see AUTHORS)
28{0} 30{0}
29{0} This file is part of Python-EFL. 31{0} This file is part of Python-EFL.
30{0} 32{0}
@@ -352,6 +354,8 @@ class Generator(object):
352 354
353 func = ctor.function 355 func = ctor.function
354 ctors_py_code += ' lib.{}(...)\n'.format(func.full_c_name_get(eolian.EOLIAN_METHOD)) 356 ctors_py_code += ' lib.{}(...)\n'.format(func.full_c_name_get(eolian.EOLIAN_METHOD))
357 # header file
358 headerf.write('{};\n'.format(ctor.function.full_c_define_get(eolian.EOLIAN_METHOD)))
355 359
356 # print(klass.ctor_enable) 360 # print(klass.ctor_enable)
357 361
diff --git a/setup.py b/setup.py
index 8d6c9df..00ee20b 100755
--- a/setup.py
+++ b/setup.py
@@ -1,48 +1,109 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2 2
3#
4# Usage:
5# ======
6#
7# clean: remove ALL generated and compiled files
8#
9# generate: write the source files using eolian ('-v' for verbose)
10#
11# build: build the generated code
12#
13# install: install the bindings in the system
14#
15# Additionaly you can always use the '--skip-gen' option to disable
16# the pyolian generation
17#
18
3from __future__ import absolute_import, print_function, division 19from __future__ import absolute_import, print_function, division
4 20
5import os 21import os
6import sys 22import sys
23import shutil
7 24
8from setuptools import setup, find_packages, Command 25from setuptools import setup, find_packages, Command
9from setuptools.command.build_py import build_py 26from setuptools.command.test import test
10from efl2 import __version__, __version_info__
11
12
13PATH = os.path.dirname(os.path.realpath(__file__))
14
15 27
16class Generate(Command): 28script_path = os.path.dirname(os.path.abspath(__file__))
17 """ run the eolian generator """
18 description = "generate the source code from eo descriptions"
19 user_options = [('svg', 'v', 'Super Verbose Generation')]
20 29
21 def initialize_options(self):
22 self.svg = False
23
24 def finalize_options(self):
25 pass
26 30
31# === aggressive clean command ===
32class CleanALL(object):
33 MAGIC = 'PYOLIAN AUTOGENERATED FILE (never change this line)'
27 def run(self): 34 def run(self):
28 print('-'*60) 35 # clean efl2/ folder (compiled & generated)
29 print('generating bindings source code using pyolian') 36 p = os.path.join(script_path, 'efl2/')
30 from pyolian.generator import Generator 37 for root, dirs, files in os.walk(p, topdown=False):
38 for f in files:
39 full_path = os.path.join(root, f)
40 if f.endswith('.pyc') or self.is_generated(full_path):
41 self.remove_f(full_path)
42 for d in dirs:
43 full_path = os.path.join(root, d)
44 if not os.listdir(full_path): # empty dir ?
45 self.remove_d(full_path)
46
47 # clean compiled stuff in pyolian (pyc)
48 p = os.path.join(script_path, 'pyolian/')
49 for f in os.listdir(p):
50 if f.endswith('.pyc'):
51 self.remove_f(os.path.join(p, f))
31 52
32 if not Generator(main_py_path=os.path.join(PATH, 'efl2/'), 53 # clean root folder (build/, dist/, *.egg-info/)
33 headers_path=os.path.join(PATH, 'efl2/cffi/'), 54 self.remove_t(os.path.join(script_path, 'build'))
34 verbose=self.svg).generate_all(): 55 self.remove_t(os.path.join(script_path, 'dist'))
35 print('\nSomething goes wrong, generation aborted.\n') 56 for f in os.listdir(script_path):
36 exit(1) 57 if f.endswith('.egg-info'):
37 58 self.remove_t(os.path.join(script_path, f))
38 print('-'*60) 59
60 def is_generated(self, full_path):
61 if not full_path.endswith(('.py', '.h')):
62 return False
63 with open(full_path, 'r') as f:
64 first_line = f.readline()
65 if self.MAGIC in first_line:
66 return True
67 return False
68
69 def remove_f(self, full_path):
70 print('removing file: %s' % os.path.relpath(full_path))
71 os.remove(full_path)
72
73 def remove_d(self, full_path):
74 print("removing empty dir: %s/" % os.path.relpath(full_path))
75 os.rmdir(full_path)
76
77 def remove_t(self, full_path):
78 if os.path.isdir(full_path):
79 print("pruning dir: %s/" % os.path.relpath(full_path))
80 shutil.rmtree(full_path)
81
82if 'clean' in sys.argv:
83 CleanALL().run()
84 exit(0)
85
86
87# === pyolian generator ===
88if '--skip-gen' in sys.argv:
89 # consume the param and skip generation
90 sys.argv.remove('--skip-gen')
91elif set(('generate', 'build', 'install', 'doc', 'bdist', 'sdist')) & set(sys.argv):
92 # run the eolian generator
93 print('generating bindings source code using pyolian')
94 from pyolian.generator import Generator
95
96 if not Generator(main_py_path=os.path.join(script_path, 'efl2/'),
97 headers_path=os.path.join(script_path, 'efl2/cffi/'),
98 verbose=True if '-v' in sys.argv else False
99 ).generate_all():
100 raise RuntimeError('Something goes wrong, generation aborted.')
101
102 if 'generate' in sys.argv:
103 exit(0)
39 104
40 105
41class BuildPy(build_py): 106from efl2 import __version__, __version_info__
42 def run(self):
43 self.run_command("generate")
44 build_py.run(self)
45
46 107
47setup( 108setup(
48 name = 'python-efl2', 109 name = 'python-efl2',
@@ -77,11 +138,7 @@ setup(
77 setup_requires = ["cffi>=1.4.0"], 138 setup_requires = ["cffi>=1.4.0"],
78 139
79 packages = find_packages(exclude=['pyolian']), 140 packages = find_packages(exclude=['pyolian']),
80 zip_safe = False, # zipped the egg is slower to start? 141 zip_safe = False, # zipped the egg seems slower to start?
81 cmdclass = {
82 'generate': Generate,
83 'build_py': BuildPy,
84 },
85 cffi_modules = [ 142 cffi_modules = [
86 "./efl2/cffi/build_efl.py:ffi", 143 "./efl2/cffi/build_efl.py:ffi",
87 ], 144 ],