Skip to content
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

Fix get_python_install_dir issues #601

Merged
merged 5 commits into from
Jun 3, 2020
Merged

Fix get_python_install_dir issues #601

merged 5 commits into from
Jun 3, 2020

Conversation

timonegk
Copy link
Member

This pull request attempts to close #597 by shelling out to check cmake -P, as suggested in the issue. The executed script, however, does not depend on catkin and should therefore work fine for workspaces without catkin.
While it might have been possible to replicate the behavior of cmake manually, I decided against it because this solution is easier to maintain and less error-prone, especially since the find_program cmake builtin would have been rather annoying to reimplement.

I marked this pull request as a draft because

  • there is still a todo in the code that I do not really know how to implement. I think it would be right to abort the build process when conflicting cmake variables have been set (e.g. python version > version of python executable).
  • no caching of the result has been implemented yet (I am not even sure if it is needed because the result of get_python_install_dir is only used to write setup.sh once).

In the second commit I fixed the install path for python3 on debian systems to reflect catkin's behavior.

@mikepurvis
Copy link
Member

Hi @timonegk— sorry for the long delay, but thanks for taking a stab at this! I've been busy but would like to get back to trying to get this release out and am just taking a look at your work here.

Regarding the business of conflicting variables, I think if we were able to re-implement less logic here this wouldn't matter as much. That is, if we simply vendored-in (and clearly marked, in order to keep it in sync) a copy of python.cmake, and called it from a wrapper that printed out whatever PYTHON_INSTALL_DIR it lands on. Then it wouldn't be up to us to determine conflicts because even if they exist, we'd still be consistent with what was being done by catkin (it uses its version of that logic to determine where to install generated python message headers, for example).

Regarding caching, yeah it can be left off for now. It's not important in the base case of catkin/cmake packages. Internally at Clearpath, we call the function each time we build a plain Python package (see https://github.com/mikepurvis/catkin_tools_python/blob/master/catkin_tools_python/job.py#L215), but if that becomes a concern for us, we can handle adding the caching or changing that logic.

I think the litmus test for getting this in is probably to add a test that does the following:

  • Clone ros/catkin (which is a plain cmake package and therefore uses this logic)
  • Build the workspace
  • Source the workspace and check that PYTHONPATH is pointing to the correct Python.

This should be run 4x, once each for the workspace being Python 2 or Python 3 (catkin_tools itself is now always Python 3), and once each for the develspace and installspace, per this logic here:

# Check if the setup file needs to be generated
if context.install:
# Create the setup file in the install space
setup_file_needed = context.isolate_install or not os.path.exists(setup_file_path)
else:
# Do not replace existing setup.sh if devel space is merged
setup_file_needed = not context.link_devel and context.isolate_devel or not os.path.exists(setup_file_path)

@timonegk timonegk marked this pull request as ready for review May 22, 2020 20:29
@timonegk
Copy link
Member Author

Thank you for the feedback. I added the tests that you proposed. Regarding the PYTHON_INSTALL_DIR, you are probably right and it makes more sense not to mix cmake and python code as I did, I will update the pull request accordingly.

@timonegk
Copy link
Member Author

I do not really understand why the CI is failing. It seems to be related to ros/catkin#863 and therefore seems to be a problem of the CI itself. I also cannot reproduce the problem in a bionic container. If you don't know how to fix the issue, I would suggest to remove the install tests (since the same get_python_install_dir function is used for devel and install anyway).

Copy link
Member

@mikepurvis mikepurvis left a comment

Choose a reason for hiding this comment

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

So the issue with the install tests is that they're using the wrong Python— --install-layout=deb isn't recognized by the upstream Python that Travis uses for its virtualenvs; it's something that Debian patches into the version of Python that it ships in its python packages. This is why we specify using the Debian python in the test configurations:

- dist: xenial
language: python
python: "3.5"
os: linux
env: PYTHON=/usr/bin/python3.5 CATKIN_VERSION=indigo-devel
- dist: bionic
language: python
python: "3.6"
os: linux
env: PYTHON=/usr/bin/python3.6 CATKIN_VERSION=indigo-devel
- dist: bionic
language: python
python: "3.7"
os: linux
env: PYTHON=/usr/bin/python3.7 CATKIN_VERSION=indigo-devel
- dist: bionic
language: python
python: "3.8"
os: linux
env: PYTHON=/usr/bin/python3.8 CATKIN_VERSION=indigo-devel

Whereas your error is showing that it's using /home/travis/virtualenv/python3.5.6/bin/python3 instead.

Also, I'm noticing that there aren't actually any other tests that clone in external content— I thought there were, but they either never merged or have since been revised. I suggested this path though, so this approach is fine to merge for now, but eventually I may change this to just use a toy package contained within the repo, since the overall test harness already happens in a context which contains a build of catkin, per https://github.com/catkin/catkin_tools/blob/master/.travis.yml#L36.

.travis.yml Outdated
@@ -33,15 +33,18 @@ before_script:
# Install catkin_tools test harness dependencies
- ./.travis.before_script.bash
- pip install empy sphinx_rtd_theme nose coverage flake8 mock --upgrade
- python2 -m pip install --user catkin-pkg
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 necessary? Pretty sure we should always just call python and let the PATH set by travis steer that to the right place.

Copy link
Member Author

Choose a reason for hiding this comment

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

Building catkin with python 2 requires the catkin_pkg package for python 2. This is not related to the python version for catkin_tools which is managed by travis

@timonegk
Copy link
Member Author

Are you sure that setting the PYTHON environment variable actually changes the used python version? The travis log suggests otherwise, e.g. in the current build in line 597, the travis virtualenv is used.

@timonegk
Copy link
Member Author

timonegk commented Jun 1, 2020

Well, I just realized that the new get_python_install_dir function is never called in the tests. I adapted the tests to use a CMake package from the resources folder and made sure that the function is actually called this time. For that it was necessary to set the workspace layout to something other than "linked" to avoid using catkin_tools_prebuild which uses catkin's own logic to generate the setup files. (When building the catkin package as we did before, catkin generates the setup files too.)

@timonegk timonegk requested a review from mikepurvis June 1, 2020 15:30
@mikepurvis
Copy link
Member

This looks terrific. Really appreciate this contribution and your patience in iterating on it with me.

@mikepurvis mikepurvis merged commit 1cd92d4 into catkin:master Jun 3, 2020
@timonegk timonegk deleted the fix/get_python_install_dir branch June 3, 2020 18:36
@timonegk
Copy link
Member Author

timonegk commented Jun 3, 2020

Thank you, I'm happy to contribute!

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.

get_python_install_dir issues
2 participants