Skip to content

Commit 7567295

Browse files
authored
Add: examples for various build systems
Pdm meson
2 parents c2d67d7 + ef5962f commit 7567295

14 files changed

+185
-1433
lines changed

.gitignore

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
**/.pdm.toml
12
# Byte-compiled / optimized / DLL files
23
__pycache__/
3-
.DS_Store
4+
**/.DS_Store
45

56

67
# Distribution / packaging
@@ -11,8 +12,6 @@ dist/
1112
downloads/
1213
eggs/
1314
.eggs/
14-
lib/
15-
lib64/
1615
parts/
1716
sdist/
1817
var/
@@ -39,10 +38,8 @@ coverage.xml
3938
.hypothesis/
4039
.pytest_cache/
4140

42-
4341
# Sphinx documentation
4442
docs/_build/
4543
docs/built_examples/
4644

47-
# Jupyter Notebook
48-
.ipynb_checkpoints
45+

example2_flit/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ The install for flit is light weight and fast.
4242
```bash
4343
Collecting flit
4444
Using cached flit-3.8.0-py3-none-any.whl (49 kB)
45-
Requirement already satisfied: requests in /Users/leahawasser/opt/miniconda3/lib/python3.9/site-packages (from flit) (2.27.1)
45+
Requirement already satisfied: requests in ../miniconda3/lib/python3.9/site-packages (from flit) (2.27.1)
4646
Collecting tomli-w
4747
Using cached tomli_w-1.0.0-py3-none-any.whl (6.0 kB)
4848
Collecting flit_core>=3.8.0
4949
Using cached flit_core-3.8.0-py3-none-any.whl (62 kB)
50-
Requirement already satisfied: docutils in /Users/leahawasser/opt/miniconda3/lib/python3.9/site-packages (from flit) (0.17.1)
51-
Requirement already satisfied: idna<4,>=2.5 in /Users/leahawasser/opt/miniconda3/lib/python3.9/site-packages (from requests->flit) (3.3)
52-
Requirement already satisfied: charset-normalizer~=2.0.0 in /Users/leahawasser/opt/miniconda3/lib/python3.9/site-packages (from requests->flit) (2.0.4)
53-
Requirement already satisfied: certifi>=2017.4.17 in /Users/leahawasser/opt/miniconda3/lib/python3.9/site-packages (from requests->flit) (2022.12.7)
54-
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/leahawasser/opt/miniconda3/lib/python3.9/site-packages (from requests->flit) (1.26.9)
50+
Requirement already satisfied: docutils in ../miniconda3/lib/python3.9/site-packages (from flit) (0.17.1)
51+
Requirement already satisfied: idna<4,>=2.5 in ../miniconda3/lib/python3.9/site-packages (from requests->flit) (3.3)
52+
Requirement already satisfied: charset-normalizer~=2.0.0 in ../miniconda3/lib/python3.9/site-packages (from requests->flit) (2.0.4)
53+
Requirement already satisfied: certifi>=2017.4.17 in ../miniconda3/lib/python3.9/site-packages (from requests->flit) (2022.12.7)
54+
Requirement already satisfied: urllib3<1.27,>=1.21.1 in ../miniconda3/lib/python3.9/site-packages (from requests->flit) (1.26.9)
5555
Installing collected packages: tomli-w, flit-core, flit
5656
Successfully installed flit-3.8.0 flit-core-3.8.0 tomli-w-1.0.0
5757
```

example4_pdm/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Collecting pdm
7777
Using cached pdm-2.4.0-py3-none-any.whl (205 kB)
7878
Collecting unearth>=0.7
7979
Using cached unearth-0.7.2-py3-none-any.whl (39 kB)
80-
Requirement already satisfied: certifi in /Users/leahawasser/opt/miniconda3/envs/pdm/lib/python3.9/site-packages (from pdm) (2022.12.7)
80+
Requirement already satisfied: certifi in ../miniconda3/envs/pdm/lib/python3.9/site-packages (from pdm) (2022.12.7)
8181
Collecting pyproject-hooks
8282
Using cached pyproject_hooks-1.0.0-py3-none-any.whl (9.3 kB)
8383
Collecting shellingham>=1.3.2
@@ -153,13 +153,13 @@ PDM did ask me what envt I wanted to use which was nice! it found my pdm conda e
153153
> pdm init
154154
Creating a pyproject.toml for PDM...
155155
Please enter the Python interpreter to use
156-
0. /Users/leahawasser/opt/miniconda3/envs/pdm/bin/python (3.9)
156+
0. ../miniconda3/envs/pdm/bin/python (3.9)
157157
1. /opt/homebrew/bin/python3.11 (3.11)
158158
2. /opt/homebrew/bin/python3.10 (3.10)
159-
3. /Users/leahawasser/opt/miniconda3/envs/pdm/bin/python3.9 (3.9)
159+
3. ../miniconda3/envs/pdm/bin/python3.9 (3.9)
160160
4. /usr/bin/python3 (3.8)
161161
Please select (0): 3
162-
Using Python interpreter: /Users/leahawasser/opt/miniconda3/envs/pdm/bin/python3.9 (3.9)
162+
Using Python interpreter: ../miniconda3/envs/pdm/bin/python3.9 (3.9)
163163
Is the project a library that will be uploaded to PyPI [y/n] (n): y
164164
Project name (example4_pdm): examplePy
165165
Project version (0.1.0): 0.1.00
@@ -232,15 +232,15 @@ venv.with_pip = False
232232
Home configuration (/Users/leahawasser/Library/Preferences/pdm/config.toml):
233233
234234
Project configuration (/Users/leahawasser/Documents/GitHub/pyos/examplePy/example4_pdm/.pdm.toml):
235-
python.path = /Users/leahawasser/opt/miniconda3/envs/pdm/bin/python3.9
235+
python.path = ../miniconda3/envs/pdm/bin/python3.9
236236
```
237237

238238
```
239239
➜ pdm info
240240
PDM version:
241241
2.4.0
242242
Python Interpreter:
243-
/Users/leahawasser/opt/miniconda3/envs/pdm/bin/python3.9 (3.9)
243+
../miniconda3/envs/pdm/bin/python3.9 (3.9)
244244
Project Root:
245245
/Users/leahawasser/Documents/GitHub/pyos/examplePy/example4_pdm
246246
Project Packages: # this is the __pypackages__ dir if you have one

example4_pdm/examplePy/__init__.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'''
2-
The __init__.py file is required to import the directory as a package, and
3-
can start empty.
2+
The __init__.py file is required to import the directory as a package.
3+
It can start as an empty file.
44
5-
It is used for....
65
'''
76

8-
7+
from .module1 import add_values

example4_pdm/examplePy/module1.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ def add_values(num1, num2):
1919
num 1 and num 2 added together
2020
2121
"""
22+
print("Example 4 install")
2223
return num1 + num2

example4_pdm/requirements.txt

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1 @@
1-
# nbsphinx setup
2-
nbsphinx
3-
pandoc # if you don't install this tutorials wont' build
4-
5-
# for sphinx gallery only
6-
sphinx-gallery
7-
pillow
8-
seaborn
9-
10-
# theme and syntax
11-
myst_parser
12-
furo
1+
pdm

example6_pdm_meson/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file doesn't need to be committed to version control
2+
# it is specific to your individual computer
3+
.pdm.toml
4+
# If you have enabled pep 582 you can also ignore this directory
5+
__pypackages__/
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22
[binaries]
3-
python = '/Users/leahawasser/opt/miniconda3/envs/pdm/bin/python3.9'
3+
python = '/Users/leahawasser/opt/miniconda3/envs/pdm_meson/bin/python'

example6_pdm_meson/.pdm.toml

-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
[python]
2-
path = "/Users/leahawasser/opt/miniconda3/envs/pdm/bin/python3.9"

example6_pdm_meson/README.md

+140-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,152 @@
11
# Pure python meson example using PDM
22

3-
TO build with `build` you need to install meson python
4-
`pip install meson-python`
3+
4+
## Requirements
5+
When combining `pdm` and `meson-python` install requirements become
6+
important. This is not clearly documented as far as I can tell.
7+
8+
## Build dependencies
9+
10+
You will need to install the following dependencies to use these tools together.
11+
12+
Build is needed if you want to run `python3 -m build` to build your project.
13+
Ninja is needed for meson-python to run.
14+
15+
# TODO create envt file for this?
16+
```bash
17+
conda install -c conda-forge pdm build meson-python ninja
18+
```
19+
20+
NOTE: You can use pip to install all of these tools if you are a pip user!
21+
22+
NOTE: PEP 517?? doesn't specify whether the front end of the back end need to be aware of the dist/ directory where your build outputs will bestored. As such there is a bug using meson-python and PDM.
23+
PDM by default cleans / deletes any dist/ directory and tries to place your
24+
SDist and wheel files in that directory.
25+
26+
`Meson-Python` by default does not create that directory for you.
27+
28+
An easy work around for this is:
29+
30+
```bash
31+
# Create a dist directory
32+
$ mkdir dist
33+
# Now build your package - by invoking the -no-clean flag, pdm will not remove
34+
# the directory that you created above.
35+
$ pdm build --no-clean
36+
```
537

638
To build with meson run:
739
`python -m build`
840

9-
This creates a build using meson - to run this you need to have ninja installed in your envt.
10-
`pip install --no-build-isolation .`
41+
## Build and install package in editable mode
1142

12-
`pdm build` doesn't work currently
43+
You can also install/build using pip. This creates a build using meson.
44+
45+
`pip install --no-build-isolation .`
1346

1447

48+
Install the package from the whl.
1549
```bash
1650
python -m pip install --no-deps dist/*.whl
1751
```
52+
53+
## Environments
54+
55+
PDM has several options for managing environments.
56+
One is following pep xxx it will create a __pypackgages__ directory. it will
57+
assume that the packages needed to build and install your package are in that
58+
local directory. However, you can also set the environment that you wish to
59+
use.
60+
61+
Below yo uuse pdm info to see what environment pdm is using. Notice that it is
62+
using the `__pypackages__` directory
63+
```
64+
➜ pdm info
65+
PDM version:
66+
2.4.0
67+
Python Interpreter:
68+
../miniconda3/envs/pdm/bin/python3.9 (3.9)
69+
Project Root:
70+
../examplePy/example6_pdm_meson
71+
Project Packages:
72+
../examplePy/example6_pdm_meson/__pypackages__/3.9
73+
```
74+
75+
```
76+
➜ which python
77+
../miniconda3/envs/pdm_meson/bin/python
78+
79+
➜ pdm use ../miniconda3/envs/pdm_meson/bin/python
80+
Using Python interpreter: ../miniconda3/envs/pdm_meson/bin/python (3.9)
81+
(pdm_meson)
82+
83+
➜ pdm info
84+
PDM version:
85+
2.4.0
86+
Python Interpreter:
87+
.../miniconda3/envs/pdm_meson/bin/python (3.9)
88+
Project Root:
89+
../examplePy/example6_pdm_meson
90+
Project Packages:
91+
None
92+
```
93+
## __pypackages__ PEP 582
94+
95+
So i somehow told pdm to use pypackages and it definitely is getting confused
96+
bewteen using conda vs that directory.
97+
98+
questions about pypackages
99+
100+
* how does it interact (or not interact) with conda envts? (and pip)
101+
102+
## Managing deps
103+
104+
When you add a dependency it also installed your package in editable mode.
105+
```bash
106+
❯ pdm add requests
107+
Adding packages to default dependencies: requests
108+
Inside an active virtualenv ../miniconda3/envs/pdm_meson, reusing it.
109+
🔒 Lock successful
110+
Changes are written to pdm.lock.
111+
Changes are written to pyproject.toml.
112+
All packages are synced to date, nothing to do.
113+
Installing the project as an editable package...
114+
✔ Install examplePy 0.1.00 successful
115+
116+
🎉 All complete!
117+
```
118+
119+
Weird - it says it installed examplepy but it's not available via conda-list
120+
```
121+
UNKNOWN 0.0.0 ../examplePy/example6_pdm_meson
122+
```
123+
unknown 0.0.0 pypi_0 pypi
124+
125+
It's definitely installing the package as "unknown".
126+
```python
127+
>>> import pkg_resources
128+
>>> installed_packages = pkg_resources.working_set
129+
>>> installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
130+
... for i in installed_packages])
131+
>>> print(installed_packages_list)
132+
['blinker==1.5', 'brotlipy==0.7.0', 'build==0.7.0', 'cachecontrol==0.12.11', 'cached-property==1.5.2', 'certifi==2022.12.7', 'cffi==1.15.1', 'charset-normalizer==3.0.1', 'click==8.1.3', 'colorama==0.4.6', 'cryptography==38.0.4', 'distlib==0.3.6', 'filelock==3.9.0', 'findpython==0.2.2', 'idna==3.4', 'importlib-metadata==6.0.0', 'installer==0.6.0', 'lockfile==0.12.2', 'markdown-it-py==2.1.0', 'mdurl==0.1.0', 'meson-python==0.12.0', 'meson==1.0.0', 'msgpack==1.0.3', 'packaging==23.0', 'pdm-pep517==1.0.6', 'pdm==2.4.0', 'pep517==0.13.0', 'pip==22.3.1', 'platformdirs==2.6.2', 'pycparser==2.21', 'pygments==2.14.0', 'pyopenssl==23.0.0', 'pyproject-hooks==1.0.0', 'pyproject-metadata==0.6.1', 'pysocks==1.7.1', 'python-dotenv==0.21.1', 'requests-toolbelt==0.10.1', 'requests==2.28.2', 'resolvelib==0.9.0', 'rich==13.3.0', 'setuptools==65.6.3', 'shellingham==1.5.0.post1', 'tomli==2.0.1', 'tomlkit==0.11.6', 'typing-extensions==4.4.0', 'unearth==0.7.2', 'unknown==0.0.0', 'urllib3==1.26.14', 'virtualenv==20.17.1', 'wheel==0.37.1', 'zipp==3.11.0']
133+
134+
```
135+
## Conda
136+
137+
# remove envt
138+
conda remove --name pdm_meson --all
139+
140+
# Create envt
141+
conda create -n myenv python=3.9
142+
143+
# View packages in your python console
144+
>>> import pkg_resources
145+
installed_packages = pkg_resources.working_set
146+
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
147+
for i in installed_packages])
148+
print(installed_packages_list)
149+
150+
151+
import os
152+
print(os.environ['CONDA_DEFAULT_ENV'])

example6_pdm_meson/examplePy/module1.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ def add_values(num1, num2):
1919
num 1 and num 2 added together
2020
2121
"""
22+
print("i'm local, friends")
2223
return num1 + num2

0 commit comments

Comments
 (0)