Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sage --package create: When re-creating with a different source type, clean up #37352

Merged
merged 4 commits into from
Feb 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sage --package create: When re-creating as a different source type, r…
…emove files that belong to other source types
  • Loading branch information
Matthias Koeppe committed Feb 15, 2024
commit b021ad885daf2834d9b8081d527b6daaa78ff534
35 changes: 24 additions & 11 deletions build/sage_bootstrap/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ def heading(title, char='-'):
if upstream_contact:
f.write('{0}\n\n'.format(upstream_contact))

def _remove_files(self, files):
"""
Remove ``files`` from the package directory if they exist
"""
for file in files:
try:
# Remove this file, which would mark the package as a pip package.
os.remove(os.path.join(self.path, file))
except OSError:
pass

def set_python_data_and_scripts(self, pypi_package_name=None, source='normal'):
"""
Write the file ``dependencies`` and other files for Python packages.
Expand All @@ -90,6 +101,8 @@ def set_python_data_and_scripts(self, pypi_package_name=None, source='normal'):
If ``source`` is ``"wheel"``, write the file ``install-requires.txt``.

If ``source`` is ``"pip"``, write the file ``requirements.txt``.

Remove existing files that belong to other source types.
"""
if pypi_package_name is None:
pypi_package_name = self.package_name
Expand All @@ -101,23 +114,23 @@ def set_python_data_and_scripts(self, pypi_package_name=None, source='normal'):
f.write('cd src\nsdh_pip_install .\n')
with open(os.path.join(self.path, 'install-requires.txt'), 'w+') as f:
f.write('{0}\n'.format(pypi_package_name))
try:
# Remove this file, which would mark the package as a pip package.
os.remove(os.path.join(self.path, 'requirements.txt'))
except OSError:
pass
# Remove this file, which would mark the package as a pip package.
self._remove_files(['requirements.txt'])
elif source == 'wheel':
with open(os.path.join(self.path, 'install-requires.txt'), 'w+') as f:
f.write('{0}\n'.format(pypi_package_name))
try:
# Remove this file, which would mark the package as a pip package.
os.remove(os.path.join(self.path, 'requirements.txt'))
except OSError:
pass
# Remove this file, which would mark the package as a pip package.
self._remove_files(['requirements.txt'])
if pypi_package_name != 'pip':
# 'pip' should be the only wheel package that has a custom spkg-install.in script.
# Remove the script for all other wheel packages, to avoid errors when
# switching from normal to wheel packages.
self._remove_files(['spkg-build.in', 'spkg-install.in'])
elif source == 'pip':
with open(os.path.join(self.path, 'requirements.txt'), 'w+') as f:
f.write('{0}\n'.format(pypi_package_name))
self._remove_files(['checksums.ini', 'spkg-build.in', 'spkg-install.in', 'spkg-install', 'install-requires.txt'])
elif source == 'script':
pass
self._remove_files(['checksums.ini', 'requirements.txt'])
else:
raise ValueError('package source must be one of normal, script, pip, or wheel')