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(api): Make the Makefile have more real prerequisites/targets #2510

Merged
merged 5 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 40 additions & 19 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
SHELL := /bin/bash

# add yarn CLI dev deps to PATH (for cross platform POSIX commands via shx)
# and also make an explicit version for shx for use in the shell function,
# where PATH won’t be propagated
PATH := $(shell cd .. && yarn bin):$(PATH)
SHX := npx shx

# make push wheel file (= rather than := to expand at every use)
wheel = $(wildcard dist/*.whl)
firmware = $(wildcard smoothie/*.hex)

# python and pipenv config
Expand All @@ -16,9 +18,32 @@ pytest := pipenv run py.test
pipenv_opts := --dev
pipenv_opts += $(and $(CI),--keep-outdated)

# Find the version of the wheel from package.json using a helper script. We
# use python here so we can use the same version normalization that will be
# used to create the wheel.
wheel_file = dist/opentrons-$(shell $(python) normalized_version.py)-py2.py3-none-any.whl
wheel_pattern := dist/opentrons-%-py2.py3-none-any.whl

# These variables can be overriden when make is invoked to customize the
# behavior of pytest. For instance,
# make test tests=tests/opentrons/tools/test_qc_scripts.py would run only the
# specified test
tests ?= tests
test_opts ?=

# Source discovery
# For the python sources
ot_py_sources := $(filter %.py,$(shell $(SHX) find src/opentrons/))
# And the out of tree shared data
ot_shared_data_sources := $(filter %.json,$(shell $(SHX) find ../shared-data/))
# And the arbitrary stuff in resources
ot_resources := $(filter %,$(shell $(SHX) find src/opentrons/resources))
ot_sources := $(ot_py_sources) $(ot_shared_data_sources) $(ot_resources)

# Defined separately than the clean target so the wheel file doesn’t have to
# depend on a PHONY target
clean_cmd = shx rm -rf build dist .coverage coverage.xml '*.egg-info' '**/__pycache__' '**/*.pyc'

.PHONY: install
install:
pipenv sync $(pipenv_opts)
Expand All @@ -28,21 +53,23 @@ all: lint test

.PHONY: clean
clean:
shx rm -rf \
build \
dist \
.coverage \
coverage.xml \
'*.egg-info' \
'**/__pycache__' \
'**/*.pyc'
$(clean_cmd)

$(wheel_pattern): setup.py $(ot_sources)
$(clean_cmd)
$(python) setup.py bdist_wheel
shx rm -rf build
shx ls dist

.PHONY: wheel
wheel: $(wheel_file)

.PHONY: test
test: local-install
${pytest} ${tests} ${test_opts}
$(pytest) $(tests) $(test_opts)

.PHONY: lint
lint:
lint: $(ot_py_sources)
$(python) -m mypy src/opentrons
$(python) -m pylama src/opentrons tests

Expand All @@ -62,15 +89,9 @@ dev: export ENABLE_VIRTUAL_SMOOTHIE := true
dev: local-install
$(python) -m opentrons.main -P 31950

.PHONY: wheel
wheel: clean
$(python) setup.py bdist_wheel
shx rm -rf build
shx ls dist

.PHONY: local-install
local-install: wheel
$(pip) install --ignore-installed --no-deps dist/opentrons-*.whl
$(pip) install --ignore-installed --no-deps $(wildcard dist/opentrons-*.whl)

.PHONY: local-shell
local-shell: local-install
Expand All @@ -80,7 +101,7 @@ local-shell: local-install
push: wheel
curl -X POST \
-H "Content-Type: multipart/form-data" \
-F "whl=@$(wheel)" \
-F "whl=@$(wildcard dist/opentrons-*.whl)" \
http://$(host):31950/server/update

.PHONY: flash
Expand Down
18 changes: 18 additions & 0 deletions api/normalized_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import json
import os
# Pipenv requires setuptools >= 36.2.1. Since 36.2.1, setuptools changed
# the way they vendor dependencies, like the packaging module that
# provides the way to normalize version numbers for wheel file names. So
# we try all the possible ways to find it.
try:
# new way
from setuptools.extern import packaging
except ImportError:
# old way
from pkg_resources.extern import packaging

pkg_json_path = os.path.join('src', 'opentrons', 'package.json')
old_ver = json.load(open(pkg_json_path))['version']
vers_obj = packaging.version.Version(old_ver)

print(str(vers_obj))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this print statement supposed to be here?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, the $(shell) function has its "return value" whatever the thing it invokes prints out. that's how we pass the information up to make.