1
1
# Pure python meson example using PDM
2
2
3
- TO build with ` build ` you need to install meson python
4
- ` pip install meson-python `
3
+
4
+ ## Requirements
5
+ When combining both pdm and meson-python, install requirements become
6
+ important. this is not clearly documented so far in any of the docs.
7
+
8
+ For pdm use:
9
+
10
+ # TODO create envt file for this?
11
+ ``` bash
12
+ conda install -c conda-forge pdm
13
+ conda install -c conda-forge build
14
+ # or install from main given the directory bug
15
+ conda install -c conda-forge meson-python
16
+ conda install -c conda-forge ninja
17
+
18
+ ```
19
+
20
+ You could use pip to install all of these tools if you are a pip user!
21
+
22
+ ToO build with ` build ` you need to install meson python
23
+ ` pip install meson-python `
24
+
25
+ NOTE: currently there is a bug between meson-python and pdm.
26
+ PDm by default cleans / deletes any dist/ directory and tries to place your
27
+ SDist and wheel files in that directoy.
28
+
29
+ Meson Python by default does not create that directory for you.
30
+
31
+ An easy work around for this is:
32
+
33
+ ``` bash
34
+ # Create a dist directory
35
+ $ mkdir dist
36
+ # Now build your package - by invoking the -no-clean flag, pdm will not remove
37
+ # the directory that you created above.
38
+ $ pdm build --no-clean
39
+ ```
5
40
6
41
To build with meson run:
7
42
` python -m build `
8
43
9
- This creates a build using meson - to run this you need to have ninja installed in your envt.
44
+ ## Build and install package
45
+ This creates a build using meson - to run this you need to have ninja
46
+ installed in your envt.
10
47
` pip install --no-build-isolation . `
11
48
12
49
` pdm build ` doesn't work currently
@@ -15,3 +52,101 @@ This creates a build using meson - to run this you need to have ninja installed
15
52
``` bash
16
53
python -m pip install --no-deps dist/* .whl
17
54
```
55
+
56
+
57
+ ## Environments
58
+
59
+ Pdm has several options for managing environments.
60
+ One is following pep xxx it will create a __ pypackgages__ directory. it will
61
+ assume that the packages needed to build and install your package are in that
62
+ local directory. However, you can also set the environment that you wish to
63
+ use.
64
+
65
+ Below yo uuse pdm info to see what environment pdm is using. Notice that it is
66
+ using the ` __pypackages__ ` directory
67
+ ```
68
+ ➜ pdm info
69
+ PDM version:
70
+ 2.4.0
71
+ Python Interpreter:
72
+ ../miniconda3/envs/pdm/bin/python3.9 (3.9)
73
+ Project Root:
74
+ ../examplePy/example6_pdm_meson
75
+ Project Packages:
76
+ ../examplePy/example6_pdm_meson/__pypackages__/3.9
77
+ ```
78
+
79
+ ```
80
+ ➜ which python
81
+ ../miniconda3/envs/pdm_meson/bin/python
82
+
83
+ ➜ pdm use ../miniconda3/envs/pdm_meson/bin/python
84
+ Using Python interpreter: /Users/leahawasser/opt/miniconda3/envs/pdm_meson/bin/python (3.9)
85
+ (pdm_meson)
86
+
87
+ ➜ pdm info
88
+ PDM version:
89
+ 2.4.0
90
+ Python Interpreter:
91
+ /Users/leahawasser/opt/miniconda3/envs/pdm_meson/bin/python (3.9)
92
+ Project Root:
93
+ /Users/leahawasser/Documents/GitHub/pyos/examplePy/example6_pdm_meson
94
+ Project Packages:
95
+ None
96
+ ```
97
+ ## __ pypackages__ PEP 582
98
+
99
+ So i somehow told pdm to use pypackages and it definitely is getting confused
100
+ bewteen using conda vs that directory.
101
+
102
+ questions about pypackages
103
+
104
+ * how does it interact (or not interact) with conda envts? (and pip)
105
+
106
+ ## Managing deps
107
+
108
+ When you add a dependency it also installed your package in editable mode.
109
+ ``` bash
110
+ ❯ pdm add requests
111
+ Adding packages to default dependencies: requests
112
+ Inside an active virtualenv ../miniconda3/envs/pdm_meson, reusing it.
113
+ 🔒 Lock successful
114
+ Changes are written to pdm.lock.
115
+ Changes are written to pyproject.toml.
116
+ All packages are synced to date, nothing to do.
117
+ Installing the project as an editable package...
118
+ ✔ Install examplePy 0.1.00 successful
119
+
120
+ 🎉 All complete!
121
+ ```
122
+
123
+ Weird - it says it installed examplepy but it's not availbale via conda-list
124
+ ```
125
+ UNKNOWN 0.0.0 /Users/leahawasser/Documents/GitHub/pyos/examplePy/example6_pdm_meson
126
+ ```
127
+ unknown 0.0.0 pypi_0 pypi
128
+
129
+ It's definitely installing the package as "unknown".
130
+ ``` python
131
+ >> > import pkg_resources
132
+ >> > installed_packages = pkg_resources.working_set
133
+ >> > installed_packages_list = sorted ([" %s ==%s " % (i.key, i.version)
134
+ ... for i in installed_packages])
135
+ >> > print (installed_packages_list)
136
+ ['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']
137
+
138
+ ```
139
+ ## Conda
140
+
141
+ # remove envt
142
+ conda remove --name pdm_meson --all
143
+
144
+ # Create envt
145
+ conda create -n myenv python=3.9
146
+
147
+ # View packages in your python console
148
+ >>> import pkg_resources
149
+ installed_packages = pkg_resources.working_set
150
+ installed_packages_list = sorted([ "%s==%s" % (i.key, i.version)
151
+ for i in installed_packages] )
152
+ print(installed_packages_list)
0 commit comments