Skip to content

Fix CI for Windows #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 40 commits into from
Closed

Fix CI for Windows #242

wants to merge 40 commits into from

Conversation

Dr-Irv
Copy link
Collaborator

@Dr-Irv Dr-Irv commented Sep 1, 2022

Summary

  • Uses action to install poetry
  • For the test of the distribution, avoids poetry because Windows CI isn't installing it in the right place
  • Adds a couple of missing PYI files that pyright said were missing

One downside (at least for me). The setting

[tool.poe.executor]
type = "virtualenv"

makes a local test with poetry not work inside of a conda environment.

But at least the CI is working.

@Dr-Irv Dr-Irv requested a review from twoertwein September 1, 2022 04:04
@Dr-Irv Dr-Irv changed the title Poetrynopin Fix CI for Windows Sep 1, 2022
@bashtage
Copy link
Contributor

bashtage commented Sep 1, 2022

I was going to merge this since green. Fix looks fine, although the source'ing is annoying. but maybe necessary. Could you instead call poetry shell before the poe commands.

I didn't merge because looks like you accidentally got some pyi changes in that aren't needed.

uses: actions/cache@v2
with:
path: ~/.cache
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this key correct, the CI says it is venv-Linux--?

This caches the (large) venv but I think it does not cache poetry.lock.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I picked this up from https://github.com/snok/install-poetry#running-on-windows

There are comments there that say that caching doesn't work on Windows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the file poetry.lock exist on the CI? The previous caching used pyproject.toml as the key to cache poety.lock

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know. After spending hours on this last night, I was just happy to get it working.

@@ -1,6 +1,7 @@
[tool.poetry]
name = "pandas-stubs"
version = "1.4.3.220829"
# Use the big version number so in CI, it will use the built wheel
version = "1.4.3.999999"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that needed? To invalidate the cache?

This should already pick the newest wheel:

path = sorted(Path("dist/").glob("pandas_stubs-*.whl"))[-1]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that if I build and install the wheel from the run script, it gets installed into the wrong python environment. So now with test.yaml doing a direct build of the wheel and installation, I have to force it to install the newly built wheel, which requires a higher version number than what is available on pypi.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which requires a higher version number than what is available on pypi.

So pip is preferring the pypi.org wheel over the local wheel? There must be an option to ignore the remote wheel.

Could also simply bump the version number after each release so that the CI works but as soon as we forget it pip will install the wrong pandas-stubs - seems a bit fragile.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue here is that we need this to work for PR's, which means that contributors have to change the version number.

In the test.yaml, I am now doing this:

python -m pip install --find-links=./dist --force-reinstall pandas-stubs

The --find-links=./dist makes it so that pip will look in the dist directory. On Windows, you can't do pip install dist/*, so this is the workaround for that.


- if: matrix.python-version == '3.8' && matrix.os == 'ubuntu-latest'
uses: pre-commit/[email protected]

- name: Install pandas-stubs and run tests on the installed stubs
run: poetry run poe test_dist
run: |
source $VENV
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the above steps we can use poe ..., why can't we use it here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, if I use the run script, it installs the wheel into the "system" environment, not poetry's virtual environment.

@twoertwein
Copy link
Member

So the issue is that we have at least two python executables and for some reason, poetry/windows CI uses both of them in an inconsistent manner?

Is it possible to remove one of them from the PATH (or delete it) so that poetry/CI is not confused by it?

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Sep 1, 2022

I didn't merge because looks like you accidentally got some pyi changes in that aren't needed.

That was intentional, as pyright was reporting that some imports were missing.

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Sep 1, 2022

So the issue is that we have at least two python executables and for some reason, poetry/windows CI uses both of them in an inconsistent manner?

Is it possible to remove one of them from the PATH (or delete it) so that poetry/CI is not confused by it?

I don't know. Prior to a few days ago, we always had 2 environments on Windows and things worked. With the setup-python action, it creates a "system" python, and then poetry creates a virtual one. I created an issue in the poetry repo thinking that the upgrade from poetry 1.1.15 to 1.2 was the issue, but the poetry people found a failed CI run on Windows using 1.1.15.

I'm now thinking that it is the setup-python action that messed things up.

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Sep 1, 2022

I was going to merge this since green. Fix looks fine, although the source'ing is annoying. but maybe necessary. Could you instead call poetry shell before the poe commands.

See https://github.com/snok/install-poetry#running-on-windows as to why we have to do the sourcing.

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Sep 1, 2022

@bashtage @twoertwein I am unsure what to do about this whole issue. @bashtage pushed a commit last night and the current CI worked just fine. So the error we are getting is a bit random.

Ideally, we'd have a failed run and a successful CI run on Windows, where the only difference was small code changes. Then we could compare the logs and see what is happening.

If you look at the successful run at https://github.com/pandas-dev/pandas-stubs/runs/8132062193?check_suite_focus=true in the past few hours, you see this:

Creating virtualenv pandas-stubs-rIU6jvyd-py3.8 in C:\Users\runneradmin\AppData\Local\pypoetry\Cache\virtualenvs
Using virtualenv: C:\Users\runneradmin\AppData\Local\pypoetry\Cache\virtualenvs\pandas-stubs-rIU6jvyd-py3.8

This says poetry is installing everything into a virtual environment.

But then when mypy is run, you see this:

2022-09-01T09:37:34.6906054Z shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
2022-09-01T09:37:34.6906454Z env:
2022-09-01T09:37:34.6906856Z   pythonLocation: C:\hostedtoolcache\windows\Python\3.8.10\x64
2022-09-01T09:37:34.6907333Z   PKG_CONFIG_PATH: C:\hostedtoolcache\windows\Python\3.8.10\x64/lib/pkgconfig
2022-09-01T09:37:34.6907842Z   Python_ROOT_DIR: C:\hostedtoolcache\windows\Python\3.8.10\x64
2022-09-01T09:37:34.6908314Z   Python2_ROOT_DIR: C:\hostedtoolcache\windows\Python\3.8.10\x64
2022-09-01T09:37:34.6908791Z   Python3_ROOT_DIR: C:\hostedtoolcache\windows\Python\3.8.10\x64
2022-09-01T09:37:34.6909175Z ##[endgroup]
2022-09-01T09:37:36.2769734Z Poe => mypy
2022-09-01T09:37:57.9046815Z Success: no issues found in 217 source files

So it seems to say it will run from the python that is installed by the setup-python script.

But in a failure from here: https://github.com/pandas-dev/pandas-stubs/runs/8132162205?check_suite_focus=true, you get the same beginning, although poetry is using the cache in that case. Then when mypy fails, you get this:

2022-09-01T09:43:28.6803975Z �[36;1mpoetry run poe mypy�[0m
2022-09-01T09:43:28.6850454Z shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
2022-09-01T09:43:28.6850800Z env:
2022-09-01T09:43:28.6851127Z   pythonLocation: C:\hostedtoolcache\windows\Python\3.8.10\x64
2022-09-01T09:43:28.6851567Z   PKG_CONFIG_PATH: C:\hostedtoolcache\windows\Python\3.8.10\x64/lib/pkgconfig
2022-09-01T09:43:28.6852012Z   Python_ROOT_DIR: C:\hostedtoolcache\windows\Python\3.8.10\x64
2022-09-01T09:43:28.6852446Z   Python2_ROOT_DIR: C:\hostedtoolcache\windows\Python\3.8.10\x64
2022-09-01T09:43:28.6852858Z   Python3_ROOT_DIR: C:\hostedtoolcache\windows\Python\3.8.10\x64
2022-09-01T09:43:28.6853158Z ##[endgroup]
2022-09-01T09:43:30.1866948Z Poe => mypy
2022-09-01T09:43:31.3020569Z Traceback (most recent call last):
2022-09-01T09:43:31.3029206Z   File "<string>", line 1, in <module>
2022-09-01T09:43:31.3030149Z   File "c:\hostedtoolcache\windows\python\3.8.10\x64\lib\importlib\__init__.py", line 127, in import_module
2022-09-01T09:43:31.3030741Z     return _bootstrap._gcd_import(name[level:], package, level)

Note that it tried to use the system installed version.

Maybe there is a cache file sitting around that works, and another one that doesn't, and @bashtage was lucky in one run to pick up the cache, and unlucky in another run where it didn't pick up the cache.

I don't understand how this caching works. Maybe @twoertwein has an idea.

Given the randomness we are seeing, I don't know if we should merge this PR.

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Sep 1, 2022

closing in favor of #249

@Dr-Irv Dr-Irv closed this Sep 1, 2022
@Dr-Irv Dr-Irv deleted the poetrynopin branch December 28, 2022 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CI failing on Windows.
3 participants