@@ -9,22 +9,6 @@ uploaded to a package index such as :term:`pypi.org` and installed with
99 `cusy seminar: Advanced Python
1010 <https://cusy.io/en/our-training-courses/advanced-python> `_
1111
12- Some of the following commands require a new version of pip, so you should make
13- sure you have the latest version installed:
14-
15-
16- .. tab :: Linux/macOS
17-
18- .. code-block :: console
19-
20- $ python3 -m pip install --upgrade pip
21-
22- .. tab :: Windows
23-
24- .. code-block :: ps1
25-
26- > python - m pip install -- upgrade pip
27-
2812Structure
2913---------
3014
@@ -453,53 +437,93 @@ For more instructions in :file:`Manifest.in`, see `MANIFEST.in commands
453437.. note ::
454438 If you want files and directories from :file: `MANIFEST.in ` to be installed as
455439 well, for example if they are runtime-relevant data, you can specify this
456- with ``include_package_data=True `` in your ``setup() `` call.
440+ with ``include_package_data=True `` in your :func: `setup ` call.
441+
442+ .. _uv-package-structure :
443+
444+ Create package structure
445+ ------------------------
446+
447+ With :samp: `uv init --package { MYPACK } ` you can easily create an initial file
448+ structure for packages.
449+
450+ .. code-block :: console
451+
452+ $ uv init --package mypack
453+ $ tree mypack -a
454+ mypack
455+ ├── .git
456+ │ └── ...
457+ ├── .gitignore
458+ ├── .python-version
459+ ├── README.md
460+ ├── pyproject.toml
461+ └── src
462+ └── mypack
463+ └── __init__.py
464+
465+ :file: `mypack/pyproject.toml `
466+ The file :file: `pyproject.toml ` contains a ``scripts `` entry point
467+ ``mypack:main ``:
468+
469+ .. literalinclude :: mypack/pyproject.toml
470+ :caption: mypack/pyproject.toml
471+ :emphasize-lines: 12-13
472+
473+ :file: `mypack/src/mypack/__init__.py `
474+ The module defines a CLI function :func: `main `:
475+
476+ .. literalinclude :: mypack/src/mypack/__init__.py
477+ :caption: mypack/src/mypack/__init__.py
478+
479+ It can be called with ``uv run ``:
480+
481+ .. code-block :: console
482+
483+ $ uv run mypack
484+ Hello from mypack!
485+
486+ .. note ::
487+ If necessary, ``uv run `` creates a :ref: `virtual Python environment
488+ <venv>` in the :file: `.venv ` folder before :func: `main ` is executed.
489+
490+ .. _uv-build :
457491
458492Build
459493-----
460494
461495The next step is to create distribution packages for the package. These are
462496archives that can be uploaded to the :term: `Python Package Index ` (:term: `PyPI `)
463- and installed by :term: `pip `.
464-
465- Make sure you have the latest version of ``build `` installed:
466-
467- Now run the command in the same directory where :file: `pyproject.toml ` is
468- located:
497+ and installed by :term: `pip `. Now execute the command in the same directory
498+ where :file: `pyproject.toml ` is located:
469499
470500.. tab :: Linux/macOS
471501
472502 .. code-block :: console
473503
474- $ python -m pip install build
475- $ cd /PATH/TO/YOUR/DISTRIBUTION_PACKAGE
476- $ rm -rf build dist
477- $ python -m build
504+ $ uv build
505+ Building source distribution...
506+ Building wheel from source distribution...
507+ Successfully built dist/mypack-0.1.0.tar.gz and dist/mypack-0.1.0-py3-none-any.whl
478508
479509 .. tab :: Windows
480510
481511 .. code-block :: ps1
482512
483- > python - m pip install build
484- > cd C:\PATH\TO\YOUR\DISTRIBUTION_PACKAGE
485- > rm - rf build dist
486- > python - m build
513+ > uv build
514+ Building source distribution...
515+ Building wheel from source distribution...
516+ Successfully built dist / mypack - 0.1 . 0. tar.gz and dist / mypack - 0.1 . 0 - py3 - none - any.whl
487517
488- The second line ensures that a clean build is created without artefacts from
489- previous builds. The third line should output a lot of text and create two files
490- in the ``dist `` directory when finished:
518+ :file: `dist/mypack-0.1.0-py3-none-any.whl `
519+ is a build distribution. :term: `pip ` prefers to install build distributions
520+ and only uses the source distributions if no suitable build distribution is
521+ available. You should always upload a source distribution and provide build
522+ distributions for the platforms with which your project is compatible. In
523+ this case, our example package is compatible with Python on every platform,
524+ so only one build distribution is required:
491525
492- .. code-block :: console
493-
494- dist
495- ├── dataprep-0.1.0-py3-none-any.whl
496- └── dataprep-0.1.0.tar.gz
497-
498- :file: `dataprep-0.1.0-py3-none-any.whl `
499- is a binary distribution format with the suffix :file: `..whl `, where the
500- filename is composed as follows:
501-
502- ``dataprep ``
526+ ``mypack ``
503527 is the normalised package name
504528 ``0.1.0 ``
505529 is the version of the distribution package
@@ -514,16 +538,14 @@ in the ``dist`` directory when finished:
514538 other hand only for chips with the x86 instruction set and a 64-bit
515539 architecture
516540
517- :file: `dataprep -0.1.0.tar.gz `
541+ :file: `mypack -0.1.0.tar.gz `
518542 is a :term: `source distribution `.
519543
520544.. seealso ::
521- The reference for the file names can be found in `File name convention
522- <https://peps.python.org/pep-0427/#file-name-convention> `_.
523-
524- For more information on ``sdist ``, see `Creating a Source Distribution
525- <https://docs.python.org/2/distutils/sourcedist.html#creating-a-source-distribution> `__
526- and :pep: `376 `.
545+ For more information on ``sdist ``, see `Core metadata specifications
546+ <https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata> `_
547+ and `PyPA specifications
548+ <https://packaging.python.org/en/latest/specifications/> `_.
527549
528550Testing
529551-------
0 commit comments