Skip to content

Commit e458431

Browse files
authored
Fix Python 2.7 related CI issues (#4232)
* CI: Remove some Py2.7 specifics * Add pip to PyPI skeleton's run_setuppy env * Add limited support for platform_system/sys_platform env markers in PyPI skeleton * lint * CI: Travis: install pip
1 parent 7cbef5d commit e458431

5 files changed

+81
-42
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ install:
3131
- conda info
3232
# avoids a python 3.7 problem
3333
- conda install -q cytoolz
34-
- conda install -q anaconda-client requests filelock contextlib2 jinja2 patchelf ripgrep pyflakes beautifulsoup4 chardet pycrypto glob2 psutil pytz tqdm conda-package-handling py-lief python-libarchive-c
34+
- conda install -q anaconda-client requests filelock contextlib2 jinja2 patchelf ripgrep pyflakes beautifulsoup4 chardet pycrypto glob2 psutil pytz tqdm conda-package-handling py-lief python-libarchive-c pip
3535
- pip install pkginfo
3636
- if [[ "$FLAKE8" == "true" ]]; then
3737
conda install -q flake8;

azure-pipelines.yml

+16-24
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ jobs:
3838
ps -ef | grep $$
3939
conda list
4040
grep '^#' "${CONDA_PREFIX}/conda-meta/history"
41-
if [ "$PYTHON_VERSION" = "2.7" ]; then
42-
# No Python 2.7 builds after conda=4.8.4 available.
43-
conda install python=$PYTHON_VERSION conda\<=4.8.4 -y
44-
else
45-
conda install python=$PYTHON_VERSION -y
46-
fi
41+
conda install python=$PYTHON_VERSION -y
4742
mkdir -p /usr/share/miniconda/locks
4843
mkdir -p /usr/share/miniconda/bin
4944
chmod a-w /usr/share/miniconda/locks
@@ -89,7 +84,7 @@ jobs:
8984
9085
- publish: $(Build.ArtifactStagingDirectory)/pytest-replay
9186
artifact: 'Linux-$(CONDA_VERSION)-Py$(PYTHON_VERSION)'
92-
condition: and(always(), ne(variables['PYTHON_VERSION'], '2.7'))
87+
condition: always()
9388

9489

9590
- job: 'macOS'
@@ -153,12 +148,7 @@ jobs:
153148
conda info
154149
conda list
155150
grep '^#' "${CONDA_PREFIX}/conda-meta/history"
156-
if [ "$PYTHON_VERSION" = "2.7" ]; then
157-
# No Python 2.7 builds after conda=4.8.4 available.
158-
conda install python=$PYTHON_VERSION conda\<=4.8.4 -y
159-
else
160-
conda install python=$PYTHON_VERSION -y
161-
fi
151+
conda install python=$PYTHON_VERSION -y
162152
mkdir -p $(Build.StagingDirectory)/miniconda/locks
163153
mkdir -p $(Build.StagingDirectory)/miniconda/bin
164154
chmod -w $(Build.StagingDirectory)/miniconda/locks
@@ -205,7 +195,7 @@ jobs:
205195
206196
- publish: $(Build.ArtifactStagingDirectory)/pytest-replay
207197
artifact: 'macOS-$(CONDA_VERSION)-Py$(PYTHON_VERSION)'
208-
condition: and(always(), ne(variables['PYTHON_VERSION'], '2.7'))
198+
condition: always()
209199

210200

211201
- job: 'Windows'
@@ -237,8 +227,14 @@ jobs:
237227
inputs:
238228
versionSpec: '$(PYTHON_VERSION)'
239229

240-
- script: |
241-
choco install vcpython27 -fdv -y --debug
230+
# SHA256 checksum (070474db76a2e625513a5835df4595df9324d820f9cc97eab2a596dcbc2f5cbf) is identical for
231+
# https://web.archive.org/web/20210106040224/https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi
232+
# and
233+
# https://github.com/GeoNode/geonode-win-installer/raw/ffb76c7cbf1d6b4970c6c25f79c3c7682a3aa035/VCForPython27.msi
234+
- powershell: |
235+
$wc = New-Object net.webclient
236+
$wc.Downloadfile("https://github.com/GeoNode/geonode-win-installer/raw/ffb76c7cbf1d6b4970c6c25f79c3c7682a3aa035/VCForPython27.msi", "VCForPython27.msi")
237+
Start-Process "VCForPython27.msi" /qn -Wait
242238
displayName: Install vcpython27.msi
243239
244240
- script: |
@@ -281,8 +277,7 @@ jobs:
281277
set PATH
282278
call %UserProfile%\Miniconda3\condabin\activate.bat base||exit 1
283279
set PATH
284-
:: No Python 2.7 builds after conda=4.8.4 available.
285-
if "%PYTHON_VERSION%" == "2.7" (call conda install python="%PYTHON_VERSION%" "conda<=4.8.4" -y||exit 1) else (call conda install python="%PYTHON_VERSION%" -y||exit 1)
280+
call conda install python="%PYTHON_VERSION%" -y||exit 1
286281
if "%CONDA_VERSION%" == "canary" (call conda update -c conda-canary conda||exit 1) else (call conda update -q conda||exit 1)
287282
call conda config --set always_yes yes
288283
call conda config --set auto_update_conda no
@@ -292,12 +287,10 @@ jobs:
292287
python -c "import sys; print(sys.prefix)"
293288
call conda update -q --all||exit 1
294289
call conda install -q pip python-libarchive-c pytest git pytest-cov jinja2 m2-patch flake8 mock requests contextlib2 chardet glob2 perl pyflakes pycrypto posix m2-git anaconda-client numpy beautifulsoup4 pytest-xdist pytest-mock filelock pkginfo psutil pytz tqdm conda-package-handling pytest-azurepipelines||exit 1
295-
if "%PYTHON_VERSION%" == "2.7" call conda install -c defaults -c conda-forge pytest-replay pytest-rerunfailures "coverage<5.0|>5.0" -y||exit 1
296-
if "%PYTHON_VERSION%" NEQ "2.7" call conda install pytest-replay pytest-rerunfailures -y||exit 1
290+
call conda install pytest-replay pytest-rerunfailures -y||exit 1
297291
echo safety_checks: disabled >> %UserProfile%\.condarc
298292
echo local_repodata_ttl: 1800 >> %UserProfile%\.condarc
299-
if "%PYTHON_VERSION%" == "2.7" call conda install -q scandir pathlib2||exit 1
300-
if "%PYTHON_VERSION%" NEQ "2.7" call conda install -q py-lief||exit 1
293+
call conda install -q py-lief||exit 1
301294
python --version
302295
python -c "import struct; print(struct.calcsize('P') * 8)"
303296
pip install --no-deps .
@@ -311,8 +304,7 @@ jobs:
311304
call conda create -n blarg -yq --download-only python=3.8||exit 1
312305
call conda create -n blarg -yq --download-only python cmake||exit 1
313306
mkdir $(Build.ArtifactStagingDirectory)\\pytest-replay
314-
set "PYTEST_REPLAY_OPTIONS=--replay-record-dir=$(Build.ArtifactStagingDirectory)\\pytest-replay"
315-
if "%PYTHON_VERSION%" NEQ "2.7" set "PYTEST_REPLAY_OPTIONS=--replay-record-dir=$(Build.ArtifactStagingDirectory)\\pytest-replay --replay-base-name=Win-%CONDA_VERSION%-Py%PYTHON_VERSION%"
307+
set "PYTEST_REPLAY_OPTIONS=--replay-record-dir=$(Build.ArtifactStagingDirectory)\\pytest-replay --replay-base-name=Win-%CONDA_VERSION%-Py%PYTHON_VERSION%"
316308
echo "##vso[task.setvariable variable=PYTEST_REPLAY_OPTIONS]%PYTEST_REPLAY_OPTIONS%"
317309
displayName: 'Configuration'
318310

conda_build/skeletons/pypi.py

+36-13
Original file line numberDiff line numberDiff line change
@@ -667,35 +667,58 @@ def convert_version(version):
667667
return pin_compatible
668668

669669

670-
MARKER_RE = re.compile(r"(?P<name>^[^=<>!~\s]+)"
670+
MARKER_RE = re.compile(r"(?P<name>^[^=<>!~\s;]+)"
671671
r"\s*"
672672
r"(?P<constraint>[=!><~]=?\s*[^\s;]+)?"
673-
r"(?:\s+;\s+)?(?P<env_mark_name>[^=<>!~\s;]+)?"
673+
r"(?:\s*;\s+)?(?P<env_mark_name>[^=<>!~\s;]+)?"
674674
r"\s*"
675675
r"(?P<env_mark_constraint>[=<>!\s]+[^=<>!~\s]+)?"
676676
)
677677

678678

679+
def _get_env_marker_operator_and_value(constraint):
680+
operator, value = constraint.split()
681+
value = value.strip("'").strip('"').strip()
682+
return operator, value
683+
684+
679685
def _translate_python_constraint(constraint):
680-
parts = constraint.split()
681686
translation = constraint
682-
if len(parts) == 2:
683-
operator, value = parts
684-
value = "".join(value.strip("'").strip('"').split(".")[:2])
687+
if len(constraint.split()) == 2:
688+
operator, value = _get_env_marker_operator_and_value(constraint)
689+
value = "".join(value.split(".")[:2])
685690
translation = " ".join((operator, value))
686-
return translation
691+
return "py {}".format(translation)
692+
693+
694+
def _translate_platform_system_constraint(constraint):
695+
operator, value = _get_env_marker_operator_and_value(constraint)
696+
system = {
697+
"Linux": "linux",
698+
"Darwin": "osx",
699+
"Windows": "win",
700+
}.get(value, value.lower())
701+
return "{}{}".format("not " if operator == "!=" else "", system)
702+
703+
704+
def _translate_sys_platform_constraint(constraint):
705+
operator, value = _get_env_marker_operator_and_value(constraint)
706+
# Only take the "letter" part to translate, e.g., "linux2"->"linux", "win32"->"win".
707+
system = re.match('^[a-z]*', value, re.I)[0]
708+
return "{}{}".format("not " if operator == "!=" else "", system)
687709

688710

689711
def env_mark_lookup(env_mark_name, env_mark_constraint):
690712
"""returns translated variable name and corresponding function to run to normalize the
691713
version constraint to conda style"""
692714
# TODO: implement more of these from PEP 508 as necessary:
693715
# https://www.python.org/dev/peps/pep-0508/
694-
env_mark_table = {'python_version': {"repl": "py",
695-
"constraint_trans_fn": _translate_python_constraint},
696-
}
697-
marker = " ".join((env_mark_table[env_mark_name]["repl"],
698-
env_mark_table[env_mark_name]['constraint_trans_fn'](env_mark_constraint)))
716+
env_mark_table = {
717+
"python_version": _translate_python_constraint,
718+
"platform_system": _translate_platform_system_constraint,
719+
"sys_platform": _translate_sys_platform_constraint,
720+
}
721+
marker = env_mark_table[env_mark_name](env_mark_constraint)
699722
return ' # [ ' + marker + ' ]'
700723

701724

@@ -1201,7 +1224,7 @@ def run_setuppy(src_dir, temp_dir, python_version, extra_specs, config, setup_op
12011224
# specs = ['python %s*' % python_version, 'pyyaml', 'setuptools', 'six', 'packaging', 'appdirs']
12021225
subdir = config.host_subdir
12031226
specs = ['python {}*'.format(python_version),
1204-
'pyyaml', 'setuptools'] + (['m2-patch', 'm2-gcc-libs'] if config.host_subdir.startswith('win')
1227+
'pip', 'pyyaml', 'setuptools'] + (['m2-patch', 'm2-gcc-libs'] if config.host_subdir.startswith('win')
12051228
else ['patch'])
12061229
with open(os.path.join(src_dir, "setup.py")) as setup:
12071230
text = setup.read()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Enhancements:
2+
-------------
3+
4+
* Add limited support for platform_system/sys_platform env markers in PyPI skeleton
5+
6+
Bug fixes:
7+
----------
8+
9+
* <news item>
10+
11+
Deprecations:
12+
-------------
13+
14+
* <news item>
15+
16+
Docs:
17+
-----
18+
19+
* <news item>
20+
21+
Other:
22+
------
23+
24+
* <news item>
25+

tests/test_published_examples.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313

1414
@pytest.mark.sanity
1515
def test_skeleton_pypi(testing_workdir):
16-
"""published in docs at http://conda.pydata.org/docs/build_tutorials/pkgs.html"""
16+
"""published in docs at https://docs.conda.io/projects/conda-build/en/latest/user-guide/tutorials/build-pkgs-skeleton.html"""
1717
conda_path = os.path.join(sys.prefix, 'Scripts' if sys.platform == 'win32' else 'bin', 'conda')
18-
# Note, if you use Click here instead it will fail.
19-
cmd = conda_path + ' skeleton pypi Flask'
18+
cmd = conda_path + ' skeleton pypi click'
2019
check_call_env(cmd.split())
21-
cmd = conda_path + ' build flask'
20+
cmd = conda_path + ' build click'
2221
check_call_env(cmd.split())
2322

2423

0 commit comments

Comments
 (0)