From 6682438b9b27db988582db338d27aaa108682997 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 13 Nov 2023 09:04:15 -0800 Subject: [PATCH 1/4] sage --package create: When re-creating as a normal or wheel package, remove requirements.txt --- build/sage_bootstrap/creator.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build/sage_bootstrap/creator.py b/build/sage_bootstrap/creator.py index c52090e5fa3..4f9a902b370 100644 --- a/build/sage_bootstrap/creator.py +++ b/build/sage_bootstrap/creator.py @@ -101,9 +101,19 @@ 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 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 elif source == 'pip': with open(os.path.join(self.path, 'requirements.txt'), 'w+') as f: f.write('{0}\n'.format(pypi_package_name)) From b021ad885daf2834d9b8081d527b6daaa78ff534 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 14 Feb 2024 22:30:56 -0800 Subject: [PATCH 2/4] sage --package create: When re-creating as a different source type, remove files that belong to other source types --- build/sage_bootstrap/creator.py | 35 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/build/sage_bootstrap/creator.py b/build/sage_bootstrap/creator.py index 4f9a902b370..9d3854f50ae 100644 --- a/build/sage_bootstrap/creator.py +++ b/build/sage_bootstrap/creator.py @@ -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. @@ -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 @@ -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') From 40bde9d895dbd72cc374006345f07f0fa3f20171 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 14 Feb 2024 22:37:50 -0800 Subject: [PATCH 3/4] src/doc/en/developer/packaging.rst: (Almost all) wheel packages do not need scripts --- src/doc/en/developer/packaging.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/doc/en/developer/packaging.rst b/src/doc/en/developer/packaging.rst index 777d9203b46..c95cc27a9bc 100644 --- a/src/doc/en/developer/packaging.rst +++ b/src/doc/en/developer/packaging.rst @@ -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. From 7f1d53135d1d95765b36b117d47465292a621546 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 15 Feb 2024 21:58:23 -0800 Subject: [PATCH 4/4] Suggested edits --- build/sage_bootstrap/creator.py | 5 ++--- src/doc/en/developer/packaging.rst | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/build/sage_bootstrap/creator.py b/build/sage_bootstrap/creator.py index 9d3854f50ae..a9a0384e129 100644 --- a/build/sage_bootstrap/creator.py +++ b/build/sage_bootstrap/creator.py @@ -82,11 +82,10 @@ def heading(title, char='-'): def _remove_files(self, files): """ - Remove ``files`` from the package directory if they exist + 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 @@ -125,7 +124,7 @@ def set_python_data_and_scripts(self, pypi_package_name=None, source='normal'): # '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']) + 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)) diff --git a/src/doc/en/developer/packaging.rst b/src/doc/en/developer/packaging.rst index c95cc27a9bc..ea391941c9c 100644 --- a/src/doc/en/developer/packaging.rst +++ b/src/doc/en/developer/packaging.rst @@ -92,7 +92,7 @@ the following source types: - its version number is defined by the required file ``package-version.txt``; - - No build and install scripts are needed + - 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);