Skip to content

Commit 686f7e9

Browse files
author
Release Manager
committed
gh-37352: `sage --package create`: When re-creating with a different source type, clean up <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> For example, when switching from a `pip` package to `wheel` package, remove the `requirements.txt` file. When switching from `normal` to `wheel`, remove the `spkg-install.in` file. One of these cases was handled by a commit on #36641, cherry-picked from there. Generalizing here to avoid mistakes such as #37129 (comment) in the future. Example: ``` $ ./sage -package create imagesize --pypi Downloading tarball from https://pypi.io/packages/py2.py3/i/imagesize/im agesize-1.4.1-py2.py3-none-any.whl to /Users/mkoeppe/s/sage/sage- rebasing/worktree-pristine/upstream/imagesize-1.4.1-py2.py3-none-any.whl [......................................................................] $ git status On branch sage_package_create_remove_files Your branch is ahead of 'upstream/develop' by 3 commits. (use "git push" to publish your local commits) Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: build/pkgs/imagesize/SPKG.rst modified: build/pkgs/imagesize/checksums.ini modified: build/pkgs/imagesize/install-requires.txt deleted: build/pkgs/imagesize/spkg-install.in modified: build/pkgs/imagesize/type ``` <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #37352 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee, Matthias Köppe
2 parents 0df697a + 7f1d531 commit 686f7e9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

build/sage_bootstrap/creator.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ 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+
os.remove(os.path.join(self.path, file))
90+
except OSError:
91+
pass
92+
8393
def set_python_data_and_scripts(self, pypi_package_name=None, source='normal'):
8494
"""
8595
Write the file ``dependencies`` and other files for Python packages.
@@ -90,6 +100,8 @@ def set_python_data_and_scripts(self, pypi_package_name=None, source='normal'):
90100
If ``source`` is ``"wheel"``, write the file ``install-requires.txt``.
91101
92102
If ``source`` is ``"pip"``, write the file ``requirements.txt``.
103+
104+
Remove existing files that belong to other source types.
93105
"""
94106
if pypi_package_name is None:
95107
pypi_package_name = self.package_name
@@ -101,13 +113,23 @@ def set_python_data_and_scripts(self, pypi_package_name=None, source='normal'):
101113
f.write('cd src\nsdh_pip_install .\n')
102114
with open(os.path.join(self.path, 'install-requires.txt'), 'w+') as f:
103115
f.write('{0}\n'.format(pypi_package_name))
116+
# Remove this file, which would mark the package as a pip package.
117+
self._remove_files(['requirements.txt'])
104118
elif source == 'wheel':
105119
with open(os.path.join(self.path, 'install-requires.txt'), 'w+') as f:
106120
f.write('{0}\n'.format(pypi_package_name))
121+
# Remove this file, which would mark the package as a pip package.
122+
self._remove_files(['requirements.txt'])
123+
if pypi_package_name != 'pip':
124+
# 'pip' should be the only wheel package that has a custom spkg-install.in script.
125+
# Remove the script for all other wheel packages, to avoid errors when
126+
# switching from normal to wheel packages.
127+
self._remove_files(['spkg-build.in', 'spkg-install.in', 'spkg-install'])
107128
elif source == 'pip':
108129
with open(os.path.join(self.path, 'requirements.txt'), 'w+') as f:
109130
f.write('{0}\n'.format(pypi_package_name))
131+
self._remove_files(['checksums.ini', 'spkg-build.in', 'spkg-install.in', 'spkg-install', 'install-requires.txt'])
110132
elif source == 'script':
111-
pass
133+
self._remove_files(['checksums.ini', 'requirements.txt'])
112134
else:
113135
raise ValueError('package source must be one of normal, script, pip, or wheel')

src/doc/en/developer/packaging.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ the following source types:
9292

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

95+
- no build and install scripts are needed
96+
(with one exception: the package :ref:`spkg_pip` installs itself from
97+
its wheel using a custom install script);
98+
9599
- Sage records the version number of the package installed using a file in
96100
``$SAGE_LOCAL/var/lib/sage/installed/`` and will rerun the installation
97101
if ``package-version.txt`` changes.

0 commit comments

Comments
 (0)