Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Copy extra files to build directory instead of using data_files
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed Oct 4, 2016
1 parent 35ecf4b commit 2b5fa98
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
5 changes: 1 addition & 4 deletions src/sage_setup/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _find_stale_files(site_packages, python_packages, python_modules, ext_module
sage: python_packages, python_modules = find_python_sources(
....: SAGE_SRC, ['sage', 'sage_setup'])
sage: extra_files = find_extra_files(python_packages, SAGE_SRC,
....: SAGE_CYTHONIZED, SAGE_LIB, ["ntlwrap.cpp"])
....: SAGE_CYTHONIZED, ["ntlwrap.cpp"])
sage: from sage_setup.clean import _find_stale_files
TODO: move ``module_list.py`` into ``sage_setup`` and also check
Expand Down Expand Up @@ -119,9 +119,6 @@ def _find_stale_files(site_packages, python_packages, python_modules, ext_module
# Convert data_files to a set
installed_files = set()
for dir, files in data_files:
dir = os.path.relpath(dir, site_packages)
if dir.startswith("."): # dir is not inside site_packages
continue
for f in files:
installed_files.add(os.path.join(dir, os.path.basename(f)))

Expand Down
11 changes: 4 additions & 7 deletions src/sage_setup/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def find_python_sources(src_dir, modules=('sage',)):
return python_packages, python_modules


def find_extra_files(packages, src_dir, cythonized_dir, site_packages, special_filenames=[]):
def find_extra_files(packages, src_dir, cythonized_dir, special_filenames=[]):
"""
Find all extra files which should be installed.
Expand All @@ -94,18 +94,15 @@ def find_extra_files(packages, src_dir, cythonized_dir, site_packages, special_f
- ``cythonized_dir`` -- the directory where the Cython-generated
files are
- ``site_packages`` -- the directory where the files should be
installed
- ``special_filenames`` -- a list of filenames to be installed from
``src_dir``
EXAMPLES::
sage: from sage_setup.find import find_extra_files
sage: from sage.env import SAGE_SRC, SAGE_CYTHONIZED
sage: find_extra_files(["sage.modular.arithgroup"], SAGE_SRC, SAGE_CYTHONIZED, ".")
[('./sage/modular/arithgroup',
sage: find_extra_files(["sage.modular.arithgroup"], SAGE_SRC, SAGE_CYTHONIZED)
[('sage/modular/arithgroup',
['.../src/sage/modular/arithgroup/farey.pxd', ...farey_symbol.h...])]
"""
data_files = []
Expand All @@ -122,7 +119,7 @@ def find_extra_files(packages, src_dir, cythonized_dir, site_packages, special_f
if f.endswith(".h")]

if files:
data_files.append((os.path.join(site_packages, dir), files))
data_files.append((dir, files))

return data_files

Expand Down
26 changes: 18 additions & 8 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ def finalize_options(self):
t = time.time()
self.run_cython()
log.warn("Finished Cythonizing, time: %.2f seconds." % (time.time() - t))
self.copy_extra_files()

def run_cython(self):
"""
Expand Down Expand Up @@ -634,22 +635,33 @@ def build_extension(self, p):
build_temp=self.build_temp,
target_lang=language)

def copy_extra_files(self):
"""
Copy extra Cython files to the build directory. These will then
be installed in site-packages/sage.
"""
dist = self.distribution
from sage_setup.find import find_extra_files
dist.extra_files = find_extra_files(dist.packages,
".", SAGE_CYTHONIZED, ["ntlwrap.cpp"])

for (dst_dir, src_files) in dist.extra_files:
dst = os.path.join(self.build_lib, dst_dir)
for src in src_files:
self.copy_file(src, dst, preserve_mode=False)


#########################################################
### Discovering Sources
#########################################################

print("Discovering Python/Cython source code....")
t = time.time()
from sage_setup.find import find_python_sources, find_extra_files
from sage_setup.find import find_python_sources
python_packages, python_modules = find_python_sources(
SAGE_SRC, ['sage', 'sage_setup'])
python_data_files = find_extra_files(python_packages,
".", SAGE_CYTHONIZED, SAGE_LIB, ["ntlwrap.cpp"])

log.info('python_packages = {0}'.format(python_packages))
log.info('python_modules = {0}'.format(python_modules))
log.info('python_data_files = {0}'.format(python_data_files))

print("Discovered Python/Cython sources, time: %.2f seconds." % (time.time() - t))

Expand Down Expand Up @@ -710,7 +722,7 @@ def clean_stale_files(self):
dist.packages,
py_modules,
dist.ext_modules,
dist.data_files)
dist.extra_files)


#########################################################
Expand All @@ -725,7 +737,5 @@ def clean_stale_files(self):
author_email= 'http://groups.google.com/group/sage-support',
url = 'http://www.sagemath.org',
packages = python_packages,
data_files = python_data_files,
scripts = [],
cmdclass = dict(build_ext=sage_build_ext, install=sage_install),
ext_modules = ext_modules)

0 comments on commit 2b5fa98

Please sign in to comment.