@@ -80,6 +80,17 @@ def heading(title, char='-'):
80
80
if upstream_contact :
81
81
f .write ('{0}\n \n ' .format (upstream_contact ))
82
82
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
+
83
94
def set_python_data_and_scripts (self , pypi_package_name = None , source = 'normal' ):
84
95
"""
85
96
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'):
90
101
If ``source`` is ``"wheel"``, write the file ``install-requires.txt``.
91
102
92
103
If ``source`` is ``"pip"``, write the file ``requirements.txt``.
104
+
105
+ Remove existing files that belong to other source types.
93
106
"""
94
107
if pypi_package_name is None :
95
108
pypi_package_name = self .package_name
@@ -101,23 +114,23 @@ def set_python_data_and_scripts(self, pypi_package_name=None, source='normal'):
101
114
f .write ('cd src\n sdh_pip_install .\n ' )
102
115
with open (os .path .join (self .path , 'install-requires.txt' ), 'w+' ) as f :
103
116
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' ])
109
119
elif source == 'wheel' :
110
120
with open (os .path .join (self .path , 'install-requires.txt' ), 'w+' ) as f :
111
121
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' ])
117
129
elif source == 'pip' :
118
130
with open (os .path .join (self .path , 'requirements.txt' ), 'w+' ) as f :
119
131
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' ])
120
133
elif source == 'script' :
121
- pass
134
+ self . _remove_files ([ 'checksums.ini' , 'requirements.txt' ])
122
135
else :
123
136
raise ValueError ('package source must be one of normal, script, pip, or wheel' )
0 commit comments