Skip to content

Commit 4e9d108

Browse files
authored
BLD Create an installable pyodide-build package (pyodide#1566)
1 parent 9dc5a76 commit 4e9d108

36 files changed

+78
-30
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ jobs:
189189
- run:
190190
name: test
191191
command: |
192-
pytest src pyodide_build packages/micropip/ -v -k 'not (chrome or firefox)' --cov=pyodide_build --cov=pyodide
192+
pytest src pyodide-build packages/micropip/ -v -k 'not (chrome or firefox)' --cov=pyodide_build --cov=pyodide
193193
194194
benchmark:
195195
<<: *defaults

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ geckodriver.log
2424
node_modules/
2525
packages/.artifacts
2626
packages/*/build.log
27+
dist/

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ update_base_url: \
117117
build/webworker.js
118118

119119
test: all
120-
pytest src emsdk/tests packages/*/test* pyodide_build -v
120+
pytest src emsdk/tests packages/*/test* pyodide-build -v
121121

122122
lint:
123123
# check for unused imports, the rest is done by black
124-
flake8 --select=F401 src tools pyodide_build benchmark conftest.py docs
124+
flake8 --select=F401 src tools pyodide-build benchmark conftest.py docs
125125
clang-format-6.0 -output-replacements-xml `find src -type f -regex ".*\.\(c\|h\\)"` | (! grep '<replacement ')
126126
$(PRETTIER) --check `find src -type f -name '*.js'`
127127
black --check .
128-
mypy --ignore-missing-imports pyodide_build/ src/ packages/micropip/micropip/ packages/*/test* conftest.py docs
128+
mypy --ignore-missing-imports pyodide-build/pyodide_build/ src/ packages/micropip/micropip/ packages/*/test* conftest.py docs
129129

130130
apply-lint:
131131
./tools/apply-lint.sh
@@ -163,7 +163,7 @@ build/test.data: $(CPYTHONLIB)
163163
python $(FILEPACKAGER) test.data --lz4 --preload ../$(CPYTHONLIB)/test@/lib/python$(PYMINOR)/test --js-output=test.js --export-name=globalThis.pyodide._module --exclude __pycache__ \
164164
)
165165
$(UGLIFYJS) build/test.js -o build/test.js
166-
166+
167167

168168
build/distutils.data: $(CPYTHONLIB)
169169
( \

bin/pyodide

-9
This file was deleted.

conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
TEST_PATH = ROOT_PATH / "src" / "tests"
2020
BUILD_PATH = ROOT_PATH / "build"
2121

22-
sys.path.append(str(ROOT_PATH))
22+
sys.path.append(str(ROOT_PATH / "pyodide-build"))
2323

2424
from pyodide_build.testing import set_webdriver_script_timeout, parse_driver_timeout
2525

docs/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
base_dir = pathlib.Path(__file__).resolve().parent.parent
1313
path_dirs = [
1414
str(base_dir),
15+
str(base_dir / "pyodide-build"),
1516
str(base_dir / "docs/sphinx_pyodide"),
1617
str(base_dir / "src/pyodide-py"),
1718
str(base_dir / "packages/micropip/micropip"),

docs/development/new-packages.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ load a package's dependencies automatically.
3030
If you wish to create a new package for Pyodide, the easiest place to start is
3131
with the {ref}`mkpkg tool <pyodide-mkpkg>`. If your package is on PyPI, just run:
3232

33-
`bin/pyodide mkpkg $PACKAGE_NAME`
33+
`pyodide-build mkpkg $PACKAGE_NAME`
3434

3535
This will generate a `meta.yaml` (see below) that should work out of the box
3636
for many pure Python packages. This tool will populate the latest version, download

docs/development/testing.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ and check that they are in your `PATH`.
2020
To run the pytest suite of tests, type on the command line:
2121

2222
```bash
23-
pytest src/ pyodide_build/ packages/*/test_*
23+
pytest src/ pyodide-build/ packages/*/test_*
2424
```
2525

2626
There are 3 test locations,
2727
- `src/tests/`: general Pyodide tests and tests running the CPython test suite
28-
- `pyodide_build/tests/`: tests related to Pyodide build system (do not require selenium to run)
28+
- `pyodide-build/pyodide_build/tests/`: tests related to Pyodide build system
29+
(do not require selenium to run)
2930
- `packages/*/test_*`: package specific tests.
3031

3132
### Manual interactive testing
@@ -38,7 +39,7 @@ environment and the host system, run: `./run_docker`
3839

3940
2. Now, this can be used to test the Pyodide builds running within the
4041
docker environment using external browser programs on the host system. To do
41-
this, run: `./bin/pyodide serve`
42+
this, run: `pyodide-build serve`
4243

4344
3. This serves the ``build`` directory of the Pyodide project on port 8000.
4445
* To serve a different directory, use the ``--build_dir`` argument followed
@@ -77,7 +78,7 @@ make lint
7778
### run_in_pyodide
7879
Many tests simply involve running a chunk of code in Pyodide and ensuring it
7980
doesn't error. In this case, one can use the `run_in_pyodide` decorate from
80-
`pyodide_build/testing.py`, e.g.
81+
`pyodide_build.testing`, e.g.
8182

8283
```python
8384
from pyodide_build.testing import run_in_pyodide

docs/project/changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ substitutions:
3232
- {{ Enhancement }} Added the {any}`PyProxy.clone` method.
3333
{pr}`1549`
3434

35+
### pyodide-build
36+
37+
- {{ Enhancement }} pyodide-build is now an installable Python package, with an identically named
38+
CLI entrypoint that replaces `bin/pyodide` which is removed {pr}`1566`
39+
40+
3541
## Version 0.17.0
3642
*April 21, 2020*
3743

docs/usage/api/pyodide-build-cli.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(pyodide-build-cli)=
2-
# pyodide_build CLI
2+
# pyodide-build CLI
33

44
```{eval-rst}
55
.. sphinx_argparse_cli::
66
:module: pyodide_build.__main__
77
:func: make_parser
8-
:prog: bin/pyodide
8+
:prog: pyodide-build
99
:title:
1010
```

packages/Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ endif
99

1010
all:
1111
mkdir -p $(PYODIDE_LIBRARIES)
12-
PYTHONPATH=$(PYODIDE_LIBRARIES)/lib/python ../bin/pyodide buildall . ../build \
12+
python3 -m pip install -e ../pyodide-build --no-deps --prefix $(PYODIDE_LIBRARIES)
13+
PYTHONPATH="$(PYODIDE_LIBRARIES)/lib/python:$(PYODIDE_ROOT)/pyodide-build/" pyodide-build buildall . ../build \
1314
--target=$(TARGETPYTHONROOT) $(ONLY_PACKAGES) --install-dir $(PYODIDE_LIBRARIES) --n-jobs $${PYODIDE_JOBS:-4}
1415

1516

1617
update-all:
1718
for pkg in $$(find . -maxdepth 1 -type d -exec basename {} \; | tail -n +2); do \
18-
../bin/pyodide mkpkg "$${pkg}" --update; \
19+
pyodide-build mkpkg "$${pkg}" --update; \
1920
done
2021

2122
clean:

pyodide-build/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# pyodide-build
2+
3+
Tools for building Pyodide.
4+
5+
See [https://github.com/pyodide/pyodide](https://github.com/pyodide/pyodide) for more information.
6+
7+
## License
8+
9+
Pyodide uses the [Mozilla Public License Version
10+
2.0](https://choosealicense.com/licenses/mpl-2.0/).

pyodide-build/pyodide_build/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

pyodide_build/common.py pyodide-build/pyodide_build/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def get_make_environment_vars():
5555
"""Load environment variables from Makefile.envs
5656
5757
This allows us to set all build vars in one place"""
58-
__ROOTDIR = Path(__file__).parents[1].resolve()
58+
# TODO: make this not rely on paths outside of pyodide-build
59+
__ROOTDIR = Path(__file__).parents[2].resolve()
5960
environment = {}
6061
result = subprocess.run(
6162
["make", "-f", str(__ROOTDIR / "Makefile.envs"), ".output_vars"],
File renamed without changes.
File renamed without changes.

pyodide_build/pywasmcross.py pyodide-build/pyodide_build/pywasmcross.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
from pyodide_build._f2c_fixes import fix_f2c_clapack_calls
4141

4242

43-
TOOLSDIR = Path(common.get_make_flag("TOOLSDIR"))
4443
symlinks = set(["cc", "c++", "ld", "ar", "gcc", "gfortran"])
4544

4645

@@ -59,6 +58,7 @@ def collect_args(basename):
5958
It writes the arguments to the build.log, and then delegates to the real
6059
native compiler or linker.
6160
"""
61+
TOOLSDIR = Path(common.get_make_flag("TOOLSDIR"))
6262
# Remove the symlink compiler from the PATH, so we can delegate to the
6363
# native compiler
6464
env = dict(os.environ)
@@ -112,6 +112,7 @@ def make_symlinks(env):
112112
Makes sure all of the symlinks that make this script look like a compiler
113113
exist.
114114
"""
115+
TOOLSDIR = Path(common.get_make_flag("TOOLSDIR"))
115116
exec_path = Path(__file__).resolve()
116117
for symlink in symlinks:
117118
symlink_path = TOOLSDIR / symlink
@@ -130,6 +131,7 @@ def make_symlinks(env):
130131

131132

132133
def capture_compile(args):
134+
TOOLSDIR = Path(common.get_make_flag("TOOLSDIR"))
133135
env = dict(os.environ)
134136
make_symlinks(env)
135137
env["PATH"] = str(TOOLSDIR) + ":" + os.environ["PATH"]
File renamed without changes.
File renamed without changes.

pyodide_build/tests/test_buildall.py pyodide-build/pyodide_build/tests/test_buildall.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pyodide_build import buildall
77
import pytest
88

9-
PACKAGES_DIR = (Path(__file__) / ".." / ".." / ".." / "packages").resolve()
9+
PACKAGES_DIR = (Path(__file__).parents[3] / "packages").resolve()
1010

1111

1212
def test_generate_dependency_graph():

pyodide_build/tests/test_run_docker.py pyodide-build/pyodide_build/tests/test_run_docker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pathlib import Path
22
import subprocess
33

4-
BASE_DIR = Path(__file__).parents[2]
4+
BASE_DIR = Path(__file__).parents[3]
55

66

77
def test_run_docker_script():

pyodide-build/pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel"]

pyodide-build/setup.cfg

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[metadata]
2+
name = pyodide-build
3+
version = 0.18.0dev0
4+
author = Pyodide developers
5+
description = "Tools for building Pyodide"
6+
long_description = file: README.md
7+
long_description_content_type = text/markdown
8+
url = https://github.com/pyodide/pyodide
9+
project_urls =
10+
Bug Tracker = https://github.com/pyodide/pyodide/issues
11+
Documentation = https://pyodide.org/en/stable/
12+
classifiers =
13+
Programming Language :: Python :: 3
14+
License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
15+
Operating System :: OS Independent
16+
17+
[options]
18+
package_dir =
19+
= .
20+
packages = find:
21+
python_requires = >=3.8
22+
install_requires =
23+
pyyaml
24+
cython<3.0
25+
[options.entry_points]
26+
console_scripts =
27+
pyodide-build = pyodide_build.__main__:main
28+
29+
[options.packages.find]
30+
where = .

pyodide-build/setup.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import setuptools
2+
3+
setuptools.setup()

pyodide_build/__init__.py

-1
This file was deleted.

pyodide_env.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ ROOT=`dirname ${BASH_SOURCE[0]}`
55
# emsdk_env.sh is fairly noisy, and suppress error message if the file doesn't
66
# exist yet (i.e. before building emsdk)
77
source "$ROOT/emsdk/emsdk/emsdk_env.sh" 2> /dev/null || true
8-
export PATH=$ROOT/node_modules/.bin/:$PATH
8+
export PATH="$ROOT/node_modules/.bin/:$PATH:$ROOT/packages/.artifacts/bin/"
99
export EM_DIR=$(dirname $(which emcc.py || echo "."))

0 commit comments

Comments
 (0)