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

chore(python): clean up python deps to add anyio #8228

Merged
merged 10 commits into from
Aug 26, 2021
Merged

Conversation

mcous
Copy link
Contributor

@mcous mcous commented Aug 10, 2021

Overview

The CPX team has run into too many walls with asyncio, so we're bringing in anyio so we can have:

  • Better mangement of background tasks with task cleanup
  • Async file reading/writing
  • Generally nicer async APIs

It's been a while since we've added a fresh Python dep to the robot, and our dependencies are fairly messy at this point. I took the opportunity to try to clean things up and make sure each of these was aligned for all of our Python projects:

  • Pipfile
  • Pipfile.lock
  • setup.py
  • Config.in
  • buildroot/package/python-***

Changes require accompanying buildroot PR: Opentrons/buildroot#131

Changelog

  • Upgrade pipenv so I can stop wiping out the lockfile everytime I need to change something
  • Add anyio to api and robot-server
  • Remove unused dependencies and dev dependencies from api/Pipfile
    • clint (dev)
    • dill (dev)
    • jsonrpcserver (prod)
  • Upgrade typing-extensions to 3.10.0.0
  • Upgrade uvicorn to 0.14.0
  • Upgrade wsproto to 1.0.0
  • Lock a bunch of * depedencies in the Pipfiles
  • Add / correct a bunch of cross-monorepo file dependencies
  • Correct misalignment between Pipfile and setup.py
  • Correct misalignment between setup.py and Config.in
  • Update Dockerfile to ensure everything still works after missing deps were added to api/setup.py

Review requests

Please check a box and sign off if you complete one of these tests)

  • Smoke tests against Docker emulator (@mcous, resulting in 7b0fd6f)
  • Dockerfile changes are sensible (@amitlissack 👍'd this PR after I asked him to look at the Dockerfile)
  • Smoke test against hardware
    • Regular robot-server smoke testing via protocols, etc (@SyntaxColoring)
    • Update server smoke testing via downgrading back to production (@mcous)
  • Make sure development environment is good (lint + test) and the dev server runs with editable installs of local projects

This PR (or rather, the companion PR over at Opentrons/buildroot#131) adds a new dependency that can be really helpful for some quick smoke testing of Python dependencies: importlib_metadata. With the OS build of this branch loaded on your robot: SSH in and load a python REPL:

from importlib_metadata import version

# check opentrons package
version('opentrons')
# > 4.5.0

# check uvicorn, upgraded by this PR
version('uvicorn')
# > 0.14.0

# check newly added anyio package
version('anyio')
# > 3.3.0

You can also try out anyio specifically in the REPL using anyio's hello world example

from anyio import run

async def main():
    print('Hello, world!')

run(main)

Risk assessment

High, changes to production dependencies (when combined with BR PR)

@mcous mcous added chore robot-svcs Falls under the purview of the Robot Services squad (formerly CPX, Core Platform Experience). python General Python tickets and PRs; e.g. tech debt or Python guild activities labels Aug 10, 2021
@codecov
Copy link

codecov bot commented Aug 10, 2021

Codecov Report

Merging #8228 (30fae68) into edge (a2cd0ff) will increase coverage by 0.13%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             edge    #8228      +/-   ##
==========================================
+ Coverage   74.78%   74.91%   +0.13%     
==========================================
  Files        1661     1695      +34     
  Lines       44316    44918     +602     
  Branches     4433     4513      +80     
==========================================
+ Hits        33140    33652     +512     
- Misses      10423    10501      +78     
- Partials      753      765      +12     
Flag Coverage Δ
api 85.86% <ø> (+0.08%) ⬆️
app 70.89% <ø> (+0.25%) ⬆️
components 48.69% <ø> (ø)
notify-server 89.49% <ø> (?)
protocol-designer 44.15% <ø> (ø)
robot-server 93.48% <ø> (ø)
shared-data 83.53% <ø> (ø)
step-generation 90.33% <ø> (ø)
update-server 74.12% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
api/src/opentrons/api/__init__.py 53.76% <0.00%> (-46.24%) ⬇️
api/src/opentrons/__init__.py
notify-server/notify_server/models/event.py 100.00% <0.00%> (ø)
...p/utils/getModuleTypesThatRequireExtraAttention.ts 100.00% <0.00%> (ø)
notify-server/notify_server/logging.py 85.71% <0.00%> (ø)
notify-server/notify_server/main.py 92.30% <0.00%> (ø)
...er/notify_server/models/hardware_event/__init__.py 100.00% <0.00%> (ø)
notify-server/notify_server/server/__init__.py 100.00% <0.00%> (ø)
...erver/notify_server/models/hardware_event/names.py 100.00% <0.00%> (ø)
.../RunSetupCard/ModuleSetup/MultipleModulesModal.tsx 50.00% <0.00%> (ø)
... and 35 more

Copy link
Member

@sfoster1 sfoster1 left a comment

Choose a reason for hiding this comment

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

Nice cleanup!

@mcous mcous marked this pull request as ready for review August 11, 2021 18:30
@mcous mcous requested review from a team as code owners August 11, 2021 18:30
@mcous mcous requested review from sanni-t and removed request for a team August 11, 2021 18:30
robot-server/Pipfile Outdated Show resolved Hide resolved
update-server/Pipfile Outdated Show resolved Hide resolved
@@ -9,11 +9,13 @@ runs:
steps:
- shell: bash
run: |
[[ "${OSTYPE}" =~ "linux" ]] && sudo sed -i 's/azure\.//' /etc/apt/sources.list && sudo apt-get update && sudo apt-get install -y --no-install-recommends libsystemd-dev || echo "do nothing and avoid pipefail"
if [[ "${OSTYPE}" =~ "linux" ]]; then
Copy link
Contributor Author

@mcous mcous Aug 12, 2021

Choose a reason for hiding this comment

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

This change made because the install of libsystemd-dev was failing in our Linux CI builds, which causes the later pipenv sync to fail somewhat obscurely when trying to install systemd-python.

The failure (GH Actions logs are gone, don't know why) looked a lot like the justification for adding this sed in the first place: some Microsoft owned entry in the list was causing apt to error out. So, I made two changes:

  1. Removed the sed ... /etc/apt/sources.list since it didn't appear to be doing anything
  2. Moved from an ... && ... || ... chain to an explicit if block so:
    • This step continues to be skipped without prejudice on macOS and Windows
    • This step fails loudly (rather than silently) on Linux builds if something goes wrong with apt-get install

I'm pretty sure this was flakiness on the server end (there were 500s and 409s in the logs), so I don't think these changes fixed anything. However, I still thing they're sensible changes

Copy link
Contributor

@amitlissack amitlissack left a comment

Choose a reason for hiding this comment

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

Looks good!

Comment on lines +2 to +4
ENV TZ=Etc/UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && apt-get install --yes python3 pip pkg-config libsystemd-dev
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other than adding apt-get install ... libsystemd-dev, I'm not sure why I needed to make any of these changes to get the Docker build working. Someone please check my work! With the changes, I can successfully build and run the server + emulator images

Copy link
Member

Choose a reason for hiding this comment

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

it looks good to me; would bet that pkg-config is a runtime configuration dep for libsystemd-dev, and the timezone stuff is Eternal Docker Containers Aren't Good At Being General Purpose Computing Environments worries

@@ -30,7 +30,7 @@ def get_version():

VERSION = get_version()

DISTNAME = "robotserver"
DISTNAME = "robot_server"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing to match actual name used in import statement in the source

@@ -19,10 +21,6 @@ pytest-cov = "<2.11.0"
pytest-aiohttp = "*"
twine = ">=1.12.0"
wheel = "==0.30.0"
coverage = "==4.4.2"
colorama = "*"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did not add the atomicwrites and colorama deps to update server because this particular project is not able to run cross-platform

@mattwelch mattwelch added this to the CPX Sprint 39 milestone Aug 24, 2021
Copy link
Contributor

@SyntaxColoring SyntaxColoring left a comment

Choose a reason for hiding this comment

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

Smoke-tested by running a protocol on a robot, toggling random switches, etc. Seems to work!

Copy link
Member

@sanni-t sanni-t left a comment

Choose a reason for hiding this comment

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

🍾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore python General Python tickets and PRs; e.g. tech debt or Python guild activities robot-svcs Falls under the purview of the Robot Services squad (formerly CPX, Core Platform Experience).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants