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
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 23 additions & 1 deletion build/sage_bootstrap/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ 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:
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 +100,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,13 +113,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))
# 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))
# 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', 'spkg-install'])
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')
4 changes: 4 additions & 0 deletions src/doc/en/developer/packaging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ the following source types:

- its version number is defined by the required file ``package-version.txt``;

- no build and install scripts are needed
(with one exception: the package :ref:`spkg_pip` installs itself from
its wheel using a custom install script);

- Sage records the version number of the package installed using a file in
``$SAGE_LOCAL/var/lib/sage/installed/`` and will rerun the installation
if ``package-version.txt`` changes.
Expand Down
Loading