Skip to content

Commit 9e3f975

Browse files
committed
[examples] Split Makefile to be standalone and improve readme.
Fixes facebookresearch#536.
1 parent 22ac844 commit 9e3f975

File tree

4 files changed

+63
-24
lines changed

4 files changed

+63
-24
lines changed

Makefile

+3-18
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ Post-installation Tests
5151
the fuzz tests for a minimum of one minute. This requires that the
5252
CompilerGym package has been installed (`make install`).
5353

54-
make examples-test
55-
Run pytest in the examples directory. This requires that the CompilerGym
56-
package has been installed (`make install`).
57-
5854

5955
Documentation
6056
-------------
@@ -169,9 +165,6 @@ DISTTOOLS_OUTS := \
169165
build \
170166
compiler_gym.egg-info \
171167
dist \
172-
examples/build \
173-
examples/compiler_gym_examples.egg-info \
174-
examples/dist \
175168
$(NULL)
176169

177170
BUILD_TARGET ?= //:package
@@ -333,12 +326,6 @@ endef
333326
install-test: | install-test-setup
334327
$(call pytest,--no-success-flaky-report --benchmark-disable -n auto -k "not fuzz" --durations=5)
335328

336-
examples-pip-install:
337-
cd examples && python setup.py install
338-
339-
examples-test: examples-pip-install
340-
cd examples && pytest --no-success-flaky-report --benchmark-disable -n auto --durations=5 . --cov=compiler_gym --cov-report=xml:$(COV_REPORT) $(PYTEST_ARGS)
341-
342329
# Note we export $CI=1 so that the tests always run as if within the CI
343330
# environement. This is to ensure that the reported coverage matches that of
344331
# the value on: https://codecov.io/gh/facebookresearch/CompilerGym
@@ -352,11 +339,7 @@ FUZZ_SECONDS ?= 300
352339
install-fuzz: install-test-setup
353340
$(call pytest,--no-success-flaky-report -p no:sugar -x -vv -k fuzz --seconds=$(FUZZ_SECONDS))
354341

355-
post-install-test:
356-
$(MAKE) -C examples/makefile_integration clean
357-
SEARCH_TIME=3 $(MAKE) -C examples/makefile_integration test
358-
359-
.PHONY: test post-install-test examples-pip-install examples-test
342+
.PHONY: test post-install-test
360343

361344

362345
################
@@ -370,6 +353,7 @@ pip-install: uninstall
370353
$(PYTHON) setup.py install
371354

372355
install: | init-runtime-requirements bazel-build pip-install
356+
$(MAKE) -C examples install
373357

374358
.PHONY: pip-install install
375359

@@ -402,6 +386,7 @@ distclean: clean
402386

403387
uninstall:
404388
$(PYTHON) -m pip uninstall -y compiler_gym
389+
$(MAKE) -C examples uninstall
405390

406391
purge: distclean uninstall
407392
rm -rf $(COMPILER_GYM_DATA_FILE_LOCATIONS)

examples/Makefile

+43-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,55 @@ CompilerGym usage examples. See README.md for details. Available targets:
99
Install the example python packages.
1010

1111
make test
12-
Run the example unit tests.
12+
Run pytest in this directory.
13+
14+
make clean
15+
Remove build artifacts.
16+
17+
make uninstall
18+
Uninstall the example python packages.
1319
endef
1420
export HELP
1521

22+
# The path of the repository reoot.
23+
ROOT := $(realpath $(dir $(realpath $(firstword $(MAKEFILE_LIST))))/..)
24+
1625
PYTHON ?= python3
1726

27+
# Extra command line arguments for pytest.
28+
PYTEST_ARGS ?=
29+
30+
# The path of the XML pytest coverage report to generate when running the
31+
# install-test-cov target.
32+
COV_REPORT ?= $(ROOT)/coverage.xml
33+
34+
DISTTOOLS_OUTS := \
35+
build \
36+
compiler_gym_examples.egg-info \
37+
dist \
38+
$(NULL)
39+
40+
.DEFAULT_GOAL := help
41+
42+
help:
43+
@echo "$$HELP"
44+
1845
install:
1946
$(PYTHON) setup.py install
2047

48+
uninstall:
49+
$(PYTHON) -m pip uninstall -y compiler_gym_examples
50+
2151
test:
22-
$(PYTHON) -m pytest .
52+
pytest --no-success-flaky-report --benchmark-disable -n auto --durations=5 . --cov=compiler_gym --cov-report=xml:$(COV_REPORT) $(PYTEST_ARGS)
53+
$(MAKE) -C makefile_integration clean
54+
SEARCH_TIME=3 $(MAKE) -C makefile_integration test
55+
56+
clean:
57+
rm -rf $(DISTTOOLS_OUTS)
58+
59+
disclean: clean
60+
61+
purge: distclean uninstall
62+
63+
.PHONY: help install uninstall test clean distclean purge

examples/README.md

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
# CompilerGym Examples <!-- omit in toc -->
22

3-
This directory contains code samples for everything from implementing simple
4-
RL agents to adding support for entirely new compilers. Is there an example that
5-
you think is missing? If so, please [contribute](/CONTRIBUTING.md)!
3+
This directory contains standalone code samples for everything from implementing
4+
simple RL agents to adding support for entirely new compilers. You can run these
5+
examples using a `pip` installed CompilerGym, though there are some additional
6+
dependencies that can be installed using:
67

8+
make install
79

8-
**Table of contents:**
10+
Then run the python scripts from this directory. E.g.:
11+
12+
python actor_critic.py
13+
14+
Is there an example that you think is missing? If so, please file a [feature
15+
request](https://github.com/facebookresearch/CompilerGym/issues/new/choose) or
16+
[contribute](/CONTRIBUTING.md)!
17+
18+
19+
## Table of contents <!-- omit in toc -->
920

1021
- [Autotuning](#autotuning)
1122
- [Performing a random walk of an environment](#performing-a-random-walk-of-an-environment)

examples/setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
version = f.read().strip()
1414
with open("requirements.txt") as f:
1515
requirements = [ln.split("#")[0].rstrip() for ln in f.readlines()]
16+
with open("../tests/requirements.txt") as f:
17+
requirements += [ln.split("#")[0].rstrip() for ln in f.readlines()]
1618

1719
setuptools.setup(
1820
name="compiler_gym_examples",

0 commit comments

Comments
 (0)