|
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 `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 | +``` |
5 | 37 |
|
6 | 38 | To build with meson run:
|
7 | 39 | `python -m build`
|
8 | 40 |
|
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 |
11 | 42 |
|
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 .` |
13 | 46 |
|
14 | 47 |
|
| 48 | +Install the package from the whl. |
15 | 49 | ```bash
|
16 | 50 | python -m pip install --no-deps dist/*.whl
|
17 | 51 | ```
|
| 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']) |
0 commit comments