by Bernat Gabor /
@gjbernat /
Bloomberg
https://gaborbernat.github.io/pep-660-662-2022
Copyright 2022 Bernat Gabor All rights reserved
Copyright 2022 Bernat Gabor All rights reserved
.
├── pyproject.toml
└── src
└── demo
└── __init__.py
[build-system]
build-backend = "hatchling.build"
requires = ["hatchling>=0.14"]
[project]
name = "demo"
version = "1.0"
def say_hi(name: str) -> None:
print(f"Hello {name}")
$ python -c 'from demo import say_hi; say_hi("PyCon")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'demo'
$ virtualenv venv --clear --no-wheel --no-setuptools --activators ""
created virtual environment CPython3.10.4.final.0-64 in 88ms
creator CPython3Posix(dest=/tmp/prj/venv, clear=True, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, via=copy, app_data_dir=/tmp/virtualenv)
added seed packages: pip==22.0.4
$ venv/bin/pip install .
Processing /tmp/prj
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: demo
Building wheel for demo (pyproject.toml) ... done
Created wheel for demo: filename=demo-1.0-py2.py3-none-any.whl size=1089 sha256=4af9f4008bef1f029
Stored in directory: /tmp/pip-ephem-wheel-cache-1t02m0nm/wheels/41/8a/ba/ffb94b3ccf1b5c11339
Successfully built demo
Installing collected packages: demo
Successfully installed demo-1.0
$ venv/bin/python -c 'from demo import say_hi; say_hi("PyCon")'
Hello PyCon
def say_hi(name: str) -> None:
print(f"Hello {name}!")
$ venv/bin/python -c 'from demo import say_hi; say_hi("PyCon")'
Hello PyCon
$ venv/bin/pip install .
Processing /tmp/prj
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: demo
Building wheel for demo (pyproject.toml) ... done
Created wheel for demo: filename=demo-1.0-py2.py3-none-any.whl size=1089 sha256=4af9f4008bef1f029
Stored in directory: /tmp/pip-ephem-wheel-cache-1t02m0nm/wheels/41/8a/ba/ffb94b3ccf1b5c11339
Successfully built demo
Installing collected packages: demo
Successfully installed demo-1.0
$ venv/bin/python -c 'from demo import say_hi; say_hi("PyCon")'
Hello PyCon!
Copyright of the above image owned by StreamClips
$ venv/bin/pip install -e .
Processing /tmp/prj
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: demo
Building wheel for demo (pyproject.toml) ... done
Created wheel for demo: filename=demo-1.0-py2.py3-none-any.whl size=1089 sha256=4af9f4008bef1f029f9ae06fdd752a1e36c
Stored in directory: /tmp/pip-ephem-wheel-cache-1t02m0nm/wheels/41/8a/ba/ffb94b3ccf1b5c11339bf57ad6563
Successfully built demo
Installing collected packages: demo
Successfully installed demo-1.0
$ venv/bin/python -c 'from demo import say_hi; say_hi("PyCon")'
Hello PyCon
def say_hi(name: str) -> None:
print(f"Hello {name}!")
$ venv/bin/python -c 'from demo import say_hi; say_hi("PyCon")'
Hello PyCon!
Copyright 2022 Bernat Gabor All rights reserved
$ python setup.py develop
$ python -m pip install -e /path/to/project
# under the hood calls - python setup.py develop with current working directory of /path/to/project
.
├── pyproject.toml
└── src
└── demo
└── __init__.py
$ venv/bin/pip install .
Processing /tmp/prj
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: demo
Building wheel for demo (pyproject.toml) ... done
Created wheel for demo: filename=demo-1.0-py2.py3-none-any.whl size=1089 sha256=4af9f4008bef1f029f9ae06fdd752a1e36c
Stored in directory: /tmp/pip-ephem-wheel-cache-1t02m0nm/wheels/41/8a/ba/ffb94b3ccf1b5c11339bf57ad6563
Successfully built demo
Installing collected packages: demo
Successfully installed demo-1.0
$ zipinfo -1 demo-1.0-py2.py3-none-any.whl
demo/__init__.py
demo-1.0.dist-info/METADATA
demo-1.0.dist-info/WHEEL
demo-1.0.dist-info/entry_points.txt
demo-1.0.dist-info/RECORD
.
├── pyproject.toml
└── src
└── demo
└── __init__.py
$ venv/bin/pip install .
Processing /tmp/prj
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: demo
Building wheel for demo (pyproject.toml) ... done
Created wheel for demo: filename=demo-1.0-py2.py3-none-any.whl size=1089 sha256=4af9f4008bef1f029f9ae06fdd752a1e36c
Stored in directory: /tmp/pip-ephem-wheel-cache-1t02m0nm/wheels/41/8a/ba/ffb94b3ccf1b5c11339bf57ad6563
Successfully built demo
Installing collected packages: demo
Successfully installed demo-1.0
$ zipinfo -1 demo-1.0-py2.py3-none-any.whl
demo/__init__.py
demo-1.0.dist-info/METADATA
demo-1.0.dist-info/WHEEL
demo-1.0.dist-info/entry_points.txt
demo-1.0.dist-info/RECORD
$ zipinfo -1 demo-1.0-py2.py3-none-any.whl
demo/__init__.py
demo-1.0.dist-info/METADATA
demo-1.0.dist-info/WHEEL
demo-1.0.dist-info/entry_points.txt
demo-1.0.dist-info/RECORD
$ lsd --tree venv/lib/python3.10/site-packages/demo*
venv/lib/python3.10/site-packages/demo
├── __init__.py
└── __pycache__
└── __init__.cpython-310.pyc
venv/lib/python3.10/site-packages/demo-1.0.dist-info
├── direct_url.json
├── entry_points.txt
├── INSTALLER
├── METADATA
├── RECORD
├── REQUESTED
└── WHEEL
$ zipinfo -1 demo-1.0-py2.py3-none-any.whl
demo/__init__.py
demo-1.0.dist-info/METADATA
demo-1.0.dist-info/WHEEL
demo-1.0.dist-info/entry_points.txt
demo-1.0.dist-info/RECORD
$ lsd --tree venv/lib/python3.10/site-packages/demo*
venv/lib/python3.10/site-packages/demo
├── __init__.py
└── __pycache__
└── __init__.cpython-310.pyc
venv/lib/python3.10/site-packages/demo-1.0.dist-info
├── direct_url.json
├── entry_points.txt
├── INSTALLER
├── METADATA
├── RECORD
├── REQUESTED
└── WHEEL
$ zipinfo -1 demo-1.0-py2.py3-none-any.whl
demo/__init__.py
demo-1.0.dist-info/METADATA
demo-1.0.dist-info/WHEEL
demo-1.0.dist-info/entry_points.txt
demo-1.0.dist-info/RECORD
$ lsd --tree venv/lib/python3.10/site-packages/demo*
venv/lib/python3.10/site-packages/demo
├── __init__.py
└── __pycache__
└── __init__.cpython-310.pyc
venv/lib/python3.10/site-packages/demo-1.0.dist-info
├── direct_url.json
├── entry_points.txt
├── INSTALLER
├── METADATA
├── RECORD
├── REQUESTED
└── WHEEL
.
├── setup.py
└── src
└── demo
└── __init__.py
from setuptools import setup
setup(
name="demo",
version="1.0",
package_dir={"": "src"},
packages=["demo"])
$ virtualenv venv --clear --no-wheel --pip 21.2 --activators ""
created virtual environment CPython3.10.4.final.0-64 in 101ms
added seed packages: pip==21.2, setuptools==62.1.0
$ venv/bin/pip install -e .
Obtaining file:///home/bernat/git/pep-660-662-2022/prj
Installing collected packages: demo
Running setup.py develop for demo
Successfully installed demo-1.0
.
├── setup.py
└── src
├── demo
│ └── __init__.py
└── demo.egg-info
├── dependency_links.txt
├── PKG-INFO
├── SOURCES.txt
└── top_level.txt
$ cat venv/lib/python3.10/site-packages/easy-install.pth
/tmp/prj/src
$ venv/bin/python -m site
sys.path = [
'/tmp/prj',
'/usr/lib/python310.zip',
'/usr/lib/python3.10',
'/usr/lib/python3.10/lib-dynload',
'/tmp/prj/venv/lib/python3.10/site-packages',
'/tmp/prj/src',
]
USER_BASE: '/home/bernat/.local' (exists)
USER_SITE: '/home/bernat/.local/lib/python3.10/site-packages' (exists)
ENABLE_USER_SITE: False
.
├── setup.py
└── src
├── demo
│ └── __init__.py
└── demo.egg-info
├── dependency_links.txt
├── PKG-INFO
├── SOURCES.txt
└── top_level.txt
$ cat venv/lib/python3.10/site-packages/easy-install.pth
/tmp/prj/src
$ venv/bin/python -m site
sys.path = [
'/tmp/prj',
'/usr/lib/python310.zip',
'/usr/lib/python3.10',
'/usr/lib/python3.10/lib-dynload',
'/tmp/prj/venv/lib/python3.10/site-packages',
'/tmp/prj/src',
]
USER_BASE: '/home/bernat/.local' (exists)
USER_SITE: '/home/bernat/.local/lib/python3.10/site-packages' (exists)
ENABLE_USER_SITE: False
Copyright 2022 Bernat Gabor All rights reserved
from setuptools import setup
setup(
name="demo",
version="1.0",
package_dir={"": "src"},
packages=["demo"],
)
.
├── setup.py
└── src
├── demo
│ └── __init__.py
├── magic
│ └── __init__.py
└── demo.egg-info
├── dependency_links.txt
├── PKG-INFO
├── SOURCES.txt
└── top_level.txt
from setuptools import setup
setup(
name="demo",
version="1.0",
package_dir={"": "src"},
packages=["demo"],
exclude=["demo.tests"],
)
.
├── setup.py
└── src
├── demo
│ ├── __init__.py
│ └── tests
│ └── __init__.py
└── demo.egg-info
├── dependency_links.txt
├── PKG-INFO
├── SOURCES.txt
└── top_level.txt
{
"type": "object",
"properties": {
"firstName": {
"type": "string",
"description": "The person's first name."
}
}
}
$ datamodel-codegen --input schema.json
# generated by datamodel-codegen:
# filename: schema.json
# timestamp: 2022-04-17T15:16:32+00:00
from __future__ import annotations
from typing import Optional
from pydantic import BaseModel, Field
class Model(BaseModel):
firstName: Optional[str] = Field(None, description="The person's first name.")
.
├── setup.py
└── src
└── demo
├── __init__.py
└── _demo.pyx
.
├── setup.py
└── src
├── demo
│ ├── __init__.py
│ ├── _demo.pyx
│ └── _demo.cpython-310-x86_64-linux-gnu.so*
└── demo.egg-info
├── dependency_links.txt
├── PKG-INFO
├── SOURCES.txt
└── top_level.txt
Copyright 2022 Bernat Gabor All rights reserved
$ lsd -tree /tmp/prj
.
├── pyproject.toml
└── src
└── demo
└── __init__.py
$ lsd -alth venv/lib/python3.10/site-packages/demo
drwxr-xr-x bernat bernat 131 B Sun Apr 17 17:30:12 2022 .
lrwxrwxrwx bernat bernat 46 B Sun Apr 17 17:30:12 2022 demo ⇒ /tmp/prj/src/demo
$ lsd -tree /tmp/prj
.
├── pyproject.toml
└── src
│── demo
│ └── __init__.py
└── test_demo.py
$ lsd -alth venv/lib/python3.10/site-packages/demo
drwxr-xr-x bernat bernat 25 B Sun Apr 17 17:36:40 2022 .
lrwxrwxrwx bernat bernat 58 B Sun Apr 17 17:36:14 2022 __init__.py ⇒ /tmp/prj/src/demo/__init__.py
.rw-r--r-- venv/lib/python3.10/site-packages/demo.pth
.rw-r--r-- venv/lib/python3.10/site-packages/_editable_impl_demo.py
import _editable_impl_pyproject_fmt
from editables.redirector import RedirectingFinder as F
F.install() # install import editables import hook to sys.meta_path
F.map_module('demo', '/tmp/prj/src/demo/__init__.py') # register module name to source file
Copyright 2022 Bernat Gabor All rights reserved
pip wheel -w --no-deps /tmp/prj
pyproject-build -w .
In order to build a wheel, two distinct components work together:
[build-system]
build-backend = "hatchling.build"
requires = ["hatchling>=0.14"]
def get_requires_for_build_wheel(config_settings=None):
return ["wheel"]
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
... # e.g., for setuptools call python setup.py bdist_wheel
$ pyproject-build -w /tmp/virtualenv
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 62.1.0, setuptools-scm >= 6.4)
* Getting dependencies for wheel...
* Installing packages in isolated environment... (wheel >= 0.37.1)
* Building wheel...
running bdist_wheel
running build
running build_py
...
Successfully built virtualenv-20.14.1-py2.py3-none-any.whl
$ pyproject-build -w /tmp/virtualenv
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 62.1.0, setuptools-scm >= 6.4)
* Getting dependencies for wheel...
* Installing packages in isolated environment... (wheel >= 0.37.1)
* Building wheel...
running bdist_wheel
running build
running build_py
...
Successfully built virtualenv-20.14.1-py2.py3-none-any.whl
$ pyproject-build -w /tmp/virtualenv
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 62.1.0, setuptools-scm >= 6.4)
* Getting dependencies for wheel...
* Installing packages in isolated environment... (wheel >= 0.37.1)
* Building wheel...
running bdist_wheel
running build
running build_py
...
Successfully built virtualenv-20.14.1-py2.py3-none-any.whl
$ pyproject-build -w /tmp/virtualenv
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 62.1.0, setuptools-scm >= 6.4)
* Getting dependencies for wheel...
* Installing packages in isolated environment... (wheel >= 0.37.1)
* Building wheel...
running bdist_wheel
running build
running build_py
...
Successfully built virtualenv-20.14.1-py2.py3-none-any.whl
$ pyproject-build -w /tmp/virtualenv
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 62.1.0, setuptools-scm >= 6.4)
* Getting dependencies for wheel...
* Installing packages in isolated environment... (wheel >= 0.37.1)
* Building wheel...
running bdist_wheel
running build
running build_py
...
Successfully built virtualenv-20.14.1-py2.py3-none-any.whl
$ pyproject-build -w /tmp/virtualenv
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools >= 62.1.0, setuptools-scm >= 6.4)
* Getting dependencies for wheel...
* Installing packages in isolated environment... (wheel >= 0.37.1)
* Building wheel...
running bdist_wheel
running build
running build_py
...
Successfully built virtualenv-20.14.1-py2.py3-none-any.whl
Copyright 2022 Bernat Gabor All rights reserved
def get_requires_for_build_editable(config_settings=None):
...
def build_editable(wheel_directory, config_settings=None, metadata_directory=None):
...
def get_requires_for_build_editable(config_settings=None):
...
def build_editable(wheel_directory, config_settings=None, metadata_directory=None):
...
{
"version": 1,
"scheme": {
"purelib": {"/src/tree/a.py": "tree/a.py"},
"platlib": {},
"data": {"/src/tree/py.typed": "tree/py.typed"},
"headers": {},
"scripts": {}
}
}
pip install -e /prj --mode=symlink|pth|hook
Creative Commons Attribution-Share Alike 4.0 International
Copyright 2022 Bernat Gabor All rights reserved
Bloomberg
© 2022 Bloomberg Finance L.P.
All rights reserved.