From 134c129edc1f56e7163106a1723f34c276c2ba10 Mon Sep 17 00:00:00 2001 From: Azat Ibrakov Date: Sun, 12 May 2019 16:20:17 +0300 Subject: [PATCH] Fix installing in 'venv' and datetime tests on Windows (#472) * Add failing test * Complete formatting * Fix commands execution * Fix commands execution for Linux * Extract virtual environment creation/removing into separate functions * Complete error messages * Complete examples building * Use 'venv' independent path * Call script by dotted path instead of 'source' call * Add Travis CI script * Rename variable: 'exec_prefix' -> 'base_prefix' * Add AppVeyor script * Remove Rust test * Complete shell script mode * Complete path to powershell script * Use 'pushd'/'popd' instead of 'cd' * Complete powershell script * Complete shell script * Fix setup * Use 'tox-venv' plugin for 'venv' stdlib module support * Remove additional 'venv' testing * Use global environment instead of calling 'set' * Use 'tox' for AppVeyor, extract commands into 'setup' & 'test' scripts * Add updating of 'pip' & 'setuptools' * Add moving in/back from examples directories * Complete 'pip'/'setuptools' updating * Complete requirements * Complete 'word-count' example configuration * Simplify 'setup' script * Complete 'rustapi_module' example tests * Revert formatting * Complete examples configuration * Remove redundant annotations * Add entry in changelog --- .travis.yml | 2 +- CHANGELOG.md | 1 + appveyor.yml | 17 +++++++------- build.rs | 12 +++++----- ci/appveyor/setup.ps1 | 8 +++++++ ci/appveyor/test.ps1 | 22 +++++++++++++++++++ ci/travis/test.sh | 6 +++-- examples/rustapi_module/pyproject.toml | 2 +- examples/rustapi_module/requirements-dev.txt | 1 + .../rustapi_module/tests/test_datetime.py | 22 +++++++++++++++++-- examples/word-count/pyproject.toml | 2 +- examples/word-count/requirements-dev.txt | 1 + 12 files changed, 74 insertions(+), 22 deletions(-) create mode 100644 ci/appveyor/setup.ps1 create mode 100644 ci/appveyor/test.ps1 diff --git a/.travis.yml b/.travis.yml index b040dee4..81e85209 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,7 @@ before_install: - source ./ci/travis/setup.sh install: - - pip install setuptools-rust pytest pytest-benchmark tox + - pip install setuptools-rust pytest pytest-benchmark tox tox-venv script: - ./ci/travis/test.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 39b52aef..879b83f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * Fixed issues with `pymethods` crashing on doc comments containing double quotes. * `PySet::new` and `PyFrozenSet::new` now return `PyResult<&Py[Frozen]Set>`; exceptions are raised if the items are not hashable. + * Fixed building using `venv` on Windows. ## [0.6.0] - 2018-03-28 diff --git a/appveyor.yml b/appveyor.yml index d92083fa..2a75343a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,25 +1,24 @@ version: 0.2.{build} environment: TARGET: x86_64-pc-windows-msvc + RUST_BACKTRACE: 1 matrix: - PYTHON: "C:/Python35-x64" - PYTHON: "C:/Python36-x64" install: - - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" - - "python --version" - - ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-nightly-${env:TARGET}.msi" - - start /wait msiexec /i rust-nightly-%TARGET%.msi INSTALLDIR="%CD%\rust-nightly-%TARGET%" /quiet /qn /norestart + - python -V + - ps: .\ci\appveyor\setup.ps1 - call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64 - - set PATH=%PATH%;%CD%/rust-nightly-%TARGET%/bin - rustc -V - cargo -V - - set RUST_BACKTRACE=1 build_script: - cargo build --verbose +before_test: + - python -m pip install -U pip setuptools + - pip install setuptools-rust pytest pytest-benchmark tox tox-venv + test_script: - - cargo test --verbose - - pip install setuptools-rust pytest pytest-benchmark - - cd examples/word-count && python setup.py install && pytest -v tests + - ps: .\ci\appveyor\test.ps1 diff --git a/build.rs b/build.rs index 9d1a58d0..8efff375 100644 --- a/build.rs +++ b/build.rs @@ -503,7 +503,7 @@ if PYPY: else: print(sysconfig.get_config_var('Py_ENABLE_SHARED')) print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short')) -print(sys.exec_prefix) +print(sys.base_prefix) print(platform.python_implementation()) "#; let out = run_python_script(interpreter, script)?; @@ -531,10 +531,10 @@ fn configure(interpreter_version: &PythonVersion, lines: Vec) -> Result< interpreter_version )); - let libpath: &str = &lines[1]; - let enable_shared: &str = &lines[2]; - let ld_version: &str = &lines[3]; - let exec_prefix: &str = &lines[4]; + let libpath = &lines[1]; + let enable_shared = &lines[2]; + let ld_version = &lines[3]; + let base_prefix = &lines[4]; let is_extension_module = env::var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some(); if !is_extension_module || cfg!(target_os = "windows") { @@ -545,7 +545,7 @@ fn configure(interpreter_version: &PythonVersion, lines: Vec) -> Result< if libpath != "None" { println!("cargo:rustc-link-search=native={}", libpath); } else if cfg!(target_os = "windows") { - println!("cargo:rustc-link-search=native={}\\libs", exec_prefix); + println!("cargo:rustc-link-search=native={}\\libs", base_prefix); } } diff --git a/ci/appveyor/setup.ps1 b/ci/appveyor/setup.ps1 new file mode 100644 index 00000000..414faa34 --- /dev/null +++ b/ci/appveyor/setup.ps1 @@ -0,0 +1,8 @@ +$env:PATH="$env:PYTHON;$env:PYTHON\\Scripts;$env:PATH" + +Start-FileDownload "https://static.rust-lang.org/dist/rust-nightly-${env:TARGET}.msi" +Start-Process -FilePath "msiexec.exe" -ArgumentList "/i rust-nightly-$env:TARGET.msi INSTALLDIR=`"$((Get-Location).Path)\rust-nightly-$env:TARGET`" /quiet /qn /norestart" -Wait +$env:PATH="$env:PATH;$((Get-Location).Path)/rust-nightly-$env:TARGET/bin" + +$pythonLocation = Invoke-Expression "python -c `"import sys; print(sys.base_prefix)`"" +$env:LIBPATH = "$env:LIBPATH; $( Join-Path $pythonLocation "libs" )" diff --git a/ci/appveyor/test.ps1 b/ci/appveyor/test.ps1 new file mode 100644 index 00000000..ba5f1832 --- /dev/null +++ b/ci/appveyor/test.ps1 @@ -0,0 +1,22 @@ +Set-PSDebug -trace 2 + +function Invoke-Call +{ + param ([scriptblock]$ScriptBlock) + & @ScriptBlock + if ($LastExitCode -ne 0) + { + exit $LastExitCode + } +} + +Invoke-Call { cargo test --verbose } + +$examplesDirectory = "examples" + +foreach ($example in Get-ChildItem $examplesDirectory) +{ + Push-Location $( Join-Path $examplesDirectory $example ) + Invoke-Call { tox -c "tox.ini" -e py } + Pop-Location +} diff --git a/ci/travis/test.sh b/ci/travis/test.sh index 6c4c719a..f7c4f9fb 100755 --- a/ci/travis/test.sh +++ b/ci/travis/test.sh @@ -16,9 +16,11 @@ if [ "$TRAVIS_JOB_NAME" = "Minimum nightly" ]; then fi for example_dir in examples/*; do + cd $example_dir if [[ $FEATURES == *"pypy"* ]]; then - tox -c "$example_dir/tox.ini" -e pypy3 + tox -c "tox.ini" -e pypy3 else - tox -c "$example_dir/tox.ini" -e py + tox -c "tox.ini" -e py fi + cd - done diff --git a/examples/rustapi_module/pyproject.toml b/examples/rustapi_module/pyproject.toml index c27f9845..b3f9d1e7 100644 --- a/examples/rustapi_module/pyproject.toml +++ b/examples/rustapi_module/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools", "wheel", "setuptools_rust>=0.10.2", "toml"] +requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=0.10.2", "toml"] build-backend = "setuptools.build_meta" diff --git a/examples/rustapi_module/requirements-dev.txt b/examples/rustapi_module/requirements-dev.txt index b1000dbb..1aad0c65 100644 --- a/examples/rustapi_module/requirements-dev.txt +++ b/examples/rustapi_module/requirements-dev.txt @@ -1,3 +1,4 @@ +pip>=19.1 hypothesis>=3.55 pytest>=3.5.0 setuptools-rust>=0.10.2 diff --git a/examples/rustapi_module/tests/test_datetime.py b/examples/rustapi_module/tests/test_datetime.py index 9fc5b230..4437c60d 100644 --- a/examples/rustapi_module/tests/test_datetime.py +++ b/examples/rustapi_module/tests/test_datetime.py @@ -45,6 +45,22 @@ except Exception: MAX_MICROSECONDS = int(pdt.timedelta.max.total_seconds() * 1e6) MIN_MICROSECONDS = int(pdt.timedelta.min.total_seconds() * 1e6) +IS_X86 = platform.architecture()[0] == '32bit' +IS_WINDOWS = sys.platform == 'win32' +if IS_WINDOWS: + if IS_X86: + MIN_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(86400) + MAX_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(32536789199) + else: + MIN_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(0) + MAX_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(32536799999) +else: + if IS_X86: + MIN_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(-2147483648) + MAX_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(2147483647) + else: + MIN_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(-62135510400) + MAX_DATETIME_FROM_TIMESTAMP = pdt.datetime.fromtimestamp(253402300799) PYPY = platform.python_implementation() == "PyPy" HAS_FOLD = getattr(pdt.datetime, "fold", False) @@ -83,7 +99,8 @@ def test_invalid_date_fails(): rdt.make_date(2017, 2, 30) -@given(d=st.dates()) +@given(d=st.dates(MIN_DATETIME_FROM_TIMESTAMP.date(), + MAX_DATETIME_FROM_TIMESTAMP.date())) def test_date_from_timestamp(d): if PYPY and d < pdt.date(1900, 1, 1): pytest.xfail("get_timestamp will raise on PyPy with dates before 1900") @@ -222,7 +239,8 @@ def test_datetime_typeerror(): rdt.make_datetime("2011", 1, 1, 0, 0, 0, 0) -@given(dt=st.datetimes()) +@given(dt=st.datetimes(MIN_DATETIME_FROM_TIMESTAMP, + MAX_DATETIME_FROM_TIMESTAMP)) def test_datetime_from_timestamp(dt): if PYPY and dt < pdt.datetime(1900, 1, 1): pytest.xfail("get_timestamp will raise on PyPy with dates before 1900") diff --git a/examples/word-count/pyproject.toml b/examples/word-count/pyproject.toml index 0b05068f..b3f9d1e7 100644 --- a/examples/word-count/pyproject.toml +++ b/examples/word-count/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools", "wheel", "setuptools-rust", "toml"] +requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=0.10.2", "toml"] build-backend = "setuptools.build_meta" diff --git a/examples/word-count/requirements-dev.txt b/examples/word-count/requirements-dev.txt index f55c7ca8..deeb5e80 100644 --- a/examples/word-count/requirements-dev.txt +++ b/examples/word-count/requirements-dev.txt @@ -1,3 +1,4 @@ +pip>=19.1 pytest>=3.5.0 setuptools-rust>=0.10.2 pytest-benchmark>=3.1.1