Skip to content

Commit b021ad8

Browse files
author
Matthias Koeppe
committed
sage --package create: When re-creating as a different source type, remove files that belong to other source types
1 parent 6682438 commit b021ad8

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

build/sage_bootstrap/creator.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ def heading(title, char='-'):
8080
if upstream_contact:
8181
f.write('{0}\n\n'.format(upstream_contact))
8282

83+
def _remove_files(self, files):
84+
"""
85+
Remove ``files`` from the package directory if they exist
86+
"""
87+
for file in files:
88+
try:
89+
# Remove this file, which would mark the package as a pip package.
90+
os.remove(os.path.join(self.path, file))
91+
except OSError:
92+
pass
93+
8394
def set_python_data_and_scripts(self, pypi_package_name=None, source='normal'):
8495
"""
8596
Write the file ``dependencies`` and other files for Python packages.
@@ -90,6 +101,8 @@ def set_python_data_and_scripts(self, pypi_package_name=None, source='normal'):
90101
If ``source`` is ``"wheel"``, write the file ``install-requires.txt``.
91102
92103
If ``source`` is ``"pip"``, write the file ``requirements.txt``.
104+
105+
Remove existing files that belong to other source types.
93106
"""
94107
if pypi_package_name is None:
95108
pypi_package_name = self.package_name
@@ -101,23 +114,23 @@ def set_python_data_and_scripts(self, pypi_package_name=None, source='normal'):
101114
f.write('cd src\nsdh_pip_install .\n')
102115
with open(os.path.join(self.path, 'install-requires.txt'), 'w+') as f:
103116
f.write('{0}\n'.format(pypi_package_name))
104-
try:
105-
# Remove this file, which would mark the package as a pip package.
106-
os.remove(os.path.join(self.path, 'requirements.txt'))
107-
except OSError:
108-
pass
117+
# Remove this file, which would mark the package as a pip package.
118+
self._remove_files(['requirements.txt'])
109119
elif source == 'wheel':
110120
with open(os.path.join(self.path, 'install-requires.txt'), 'w+') as f:
111121
f.write('{0}\n'.format(pypi_package_name))
112-
try:
113-
# Remove this file, which would mark the package as a pip package.
114-
os.remove(os.path.join(self.path, 'requirements.txt'))
115-
except OSError:
116-
pass
122+
# Remove this file, which would mark the package as a pip package.
123+
self._remove_files(['requirements.txt'])
124+
if pypi_package_name != 'pip':
125+
# 'pip' should be the only wheel package that has a custom spkg-install.in script.
126+
# Remove the script for all other wheel packages, to avoid errors when
127+
# switching from normal to wheel packages.
128+
self._remove_files(['spkg-build.in', 'spkg-install.in'])
117129
elif source == 'pip':
118130
with open(os.path.join(self.path, 'requirements.txt'), 'w+') as f:
119131
f.write('{0}\n'.format(pypi_package_name))
132+
self._remove_files(['checksums.ini', 'spkg-build.in', 'spkg-install.in', 'spkg-install', 'install-requires.txt'])
120133
elif source == 'script':
121-
pass
134+
self._remove_files(['checksums.ini', 'requirements.txt'])
122135
else:
123136
raise ValueError('package source must be one of normal, script, pip, or wheel')

0 commit comments

Comments
 (0)