Skip to content

Commit 9aa5339

Browse files
committed
Re-organize the setup.py so that Astropy is not required for egg_info
1 parent 68eedf1 commit 9aa5339

1 file changed

Lines changed: 80 additions & 78 deletions

File tree

‎setup.py‎

Lines changed: 80 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
import __builtin__ as builtins
1616
builtins._ASTROPY_SETUP_ = True
1717

18-
import astropy
19-
from astropy.setup_helpers import (register_commands, adjust_compiler,
20-
get_debug_option)
21-
from astropy.version_helpers import get_git_devstr, generate_version_py
22-
2318
# Set affiliated package-specific settings
2419
PACKAGENAME = 'packagename'
2520
DESCRIPTION = 'Astropy affiliated package'
@@ -35,80 +30,87 @@
3530
# Indicates if this version is a release version
3631
RELEASE = 'dev' not in VERSION
3732

38-
if not RELEASE:
39-
VERSION += get_git_devstr(False)
33+
metadata = dict(
34+
name=PACKAGENAME,
35+
package_data={},
36+
version=VERSION,
37+
description=DESCRIPTION,
38+
requires=['astropy'],
39+
install_requires=['astropy'],
40+
provides=[PACKAGENAME],
41+
author=AUTHOR,
42+
author_email=AUTHOR_EMAIL,
43+
license=LICENSE,
44+
url=URL,
45+
long_description=LONG_DESCRIPTION,
46+
zip_safe=False,
47+
use_2to3=True
48+
)
49+
50+
# Treat everything in scripts except README.rst as a script to be installed
51+
metadata['scripts'] = [fname for fname in glob.glob(os.path.join('scripts', '*'))
52+
if os.path.basename(fname) != 'README.rst']
4053

41-
# Populate the dict of setup command overrides; this should be done before
42-
# invoking any other functionality from distutils since it can potentially
43-
# modify distutils' behavior.
44-
cmdclassd = register_commands(PACKAGENAME, VERSION, RELEASE)
54+
# Add the project-global data
55+
metadata['package_data'][PACKAGENAME] = ['data/*']
4556

46-
# Adjust the compiler in case the default on this platform is to use a
47-
# broken one.
48-
adjust_compiler(PACKAGENAME)
57+
if len(sys.argv) >= 2 and sys.argv[1] == 'egg_info':
4958

50-
# Freeze build information in version.py
51-
generate_version_py(PACKAGENAME, VERSION, RELEASE, get_debug_option())
59+
# TODO: if we have a copy of get_git_devstr in the package template we can
60+
# set the proper version here.
5261

53-
# Treat everything in scripts except README.rst as a script to be installed
54-
scripts = [fname for fname in glob.glob(os.path.join('scripts', '*'))
55-
if os.path.basename(fname) != 'README.rst']
56-
57-
58-
try:
59-
60-
from astropy.setup_helpers import get_package_info
61-
62-
# Get configuration information from all of the various subpackages.
63-
# See the docstring for setup_helpers.update_package_files for more
64-
# details.
65-
package_info = get_package_info(PACKAGENAME)
66-
67-
# Add the project-global data
68-
package_info['package_data'][PACKAGENAME] = ['data/*']
69-
70-
except ImportError: # compatibility with Astropy 0.2 - can be removed in cases
71-
# where Astropy 0.2 is no longer supported
72-
73-
from setuptools import find_packages
74-
from astropy.setup_helpers import filter_packages, update_package_files
75-
76-
package_info = {}
77-
78-
# Use the find_packages tool to locate all packages and modules
79-
package_info['packages'] = filter_packages(find_packages())
80-
81-
# Additional C extensions that are not Cython-based should be added here.
82-
package_info['ext_modules'] = []
83-
84-
# A dictionary to keep track of all package data to install
85-
package_info['package_data'] = {PACKAGENAME: ['data/*']}
86-
87-
# A dictionary to keep track of extra packagedir mappings
88-
package_info['package_dir'] = {}
89-
90-
# Update extensions, package_data, packagenames and package_dirs from
91-
# any sub-packages that define their own extension modules and package
92-
# data. See the docstring for setup_helpers.update_package_files for
93-
# more details.
94-
update_package_files(PACKAGENAME, package_info['ext_modules'],
95-
package_info['package_data'], package_info['packages'],
96-
package_info['package_dir'])
97-
98-
setup(name=PACKAGENAME,
99-
version=VERSION,
100-
description=DESCRIPTION,
101-
scripts=scripts,
102-
requires=['astropy'],
103-
install_requires=['astropy'],
104-
provides=[PACKAGENAME],
105-
author=AUTHOR,
106-
author_email=AUTHOR_EMAIL,
107-
license=LICENSE,
108-
url=URL,
109-
long_description=LONG_DESCRIPTION,
110-
cmdclass=cmdclassd,
111-
zip_safe=False,
112-
use_2to3=True,
113-
**package_info
114-
)
62+
pass
63+
64+
else:
65+
66+
from astropy.setup_helpers import register_commands, adjust_compiler, get_debug_option
67+
from astropy.version_helpers import get_git_devstr, generate_version_py
68+
69+
if not RELEASE:
70+
VERSION += get_git_devstr(False)
71+
72+
# Populate the dict of setup command overrides; this should be done before
73+
# invoking any other functionality from distutils since it can potentially
74+
# modify distutils' behavior.
75+
metadata['cmdclass'] = register_commands(PACKAGENAME, VERSION, RELEASE)
76+
77+
# Adjust the compiler in case the default on this platform is to use a
78+
# broken one.
79+
adjust_compiler(PACKAGENAME)
80+
81+
# Freeze build information in version.py
82+
generate_version_py(PACKAGENAME, VERSION, RELEASE, get_debug_option())
83+
84+
try:
85+
86+
from astropy.setup_helpers import get_package_info
87+
88+
# Get configuration information from all of the various subpackages.
89+
# See the docstring for setup_helpers.update_package_files for more
90+
# details.
91+
metadata.update(get_package_info(PACKAGENAME))
92+
93+
except ImportError: # compatibility with Astropy 0.2 - can be removed in cases
94+
# where Astropy 0.2 is no longer supported
95+
96+
from setuptools import find_packages
97+
from astropy.setup_helpers import filter_packages, update_package_files
98+
99+
# Use the find_packages tool to locate all packages and modules
100+
metadata['packages'] = filter_packages(find_packages())
101+
102+
# Additional C extensions that are not Cython-based should be added here.
103+
metadata['ext_modules'] = []
104+
105+
# A dictionary to keep track of extra packagedir mappings
106+
metadata['package_dir'] = {}
107+
108+
# Update extensions, package_data, packagenames and package_dirs from
109+
# any sub-packages that define their own extension modules and package
110+
# data. See the docstring for setup_helpers.update_package_files for
111+
# more details.
112+
update_package_files(PACKAGENAME, metadata['ext_modules'],
113+
metadata['package_data'], metadata['packages'],
114+
metadata['package_dir'])
115+
116+
setup(**metadata)

0 commit comments

Comments
 (0)