Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Update package section #781

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
99 changes: 43 additions & 56 deletions docs/tutorial/package.md
Expand Up @@ -44,41 +44,34 @@ cd ./rick-portal-gun

## Dependencies and environment

Add `typer[all]` to your dependencies:
Add `typer` to your dependencies:

<div class="termy">

```console
$ poetry add "typer[all]"
$ poetry add typer

// It creates a virtual environment for your project
Creating virtualenv rick-portal-gun-w31dJa0b-py3.10 in /home/rick/.cache/pypoetry/virtualenvs
Using version ^0.1.0 for typer
Using version ^0.12.0 for typer

Updating dependencies
Resolving dependencies... (1.2s)

Writing lock file

---> 100%

Package operations: 15 installs, 0 updates, 0 removals

- Installing zipp (3.1.0)
- Installing importlib-metadata (1.5.0)
- Installing pyparsing (2.4.6)
- Installing six (1.14.0)
- Installing attrs (19.3.0)
- Installing click (7.1.1)
- Installing colorama (0.4.3)
- Installing more-itertools (8.2.0)
- Installing packaging (20.3)
- Installing pluggy (0.13.1)
- Installing py (1.8.1)
- Installing shellingham (1.3.2)
- Installing wcwidth (0.1.8)
- Installing pytest (5.4.1)
- Installing typer (0.0.11)
Package operations: 8 installs, 0 updates, 0 removals

- Installing mdurl (0.1.2)
- Installing markdown-it-py (3.0.0)
- Installing pygments (2.17.2)
- Installing click (8.1.7)
- Installing rich (13.7.1)
- Installing shellingham (1.5.4)
- Installing typing-extensions (4.11.0)
- Installing typer (0.12.3)

Writing lock file

// Activate that new virtual environment
$ poetry shell
Expand All @@ -101,8 +94,7 @@ You can see that you have a generated project structure that looks like:
├── rick_portal_gun
│   └── __init__.py
└── tests
├── __init__.py
└── test_rick_portal_gun.py
└── __init__.py
```

## Create your app
Expand Down Expand Up @@ -175,14 +167,11 @@ rick-portal-gun = "rick_portal_gun.main:app"

[tool.poetry.dependencies]
python = "^3.10"
typer = {extras = ["all"], version = "^0.1.0"}

[tool.poetry.dev-dependencies]
pytest = "^5.2"
typer = "^0.12.0"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
```

Here's what that line means:
Expand Down Expand Up @@ -231,7 +220,7 @@ Installing dependencies from lock file

No dependencies to install or update

- Installing rick-portal-gun (0.1.0)
- Installing the current project: rick-portal-gun (0.1.0)
```

</div>
Expand All @@ -250,7 +239,7 @@ $ which rick-portal-gun
/home/rick/.cache/pypoetry/virtualenvs/rick-portal-gun-w31dJa0b-py3.10/bin/rick-portal-gun

// Try it
$ rick-portal-gun
$ rick-portal-gun --help

// You get all the standard help
Usage: rick-portal-gun [OPTIONS] COMMAND [ARGS]...
Expand Down Expand Up @@ -284,7 +273,6 @@ $ poetry build
Building rick-portal-gun (0.1.0)
- Building sdist
- Built rick-portal-gun-0.1.0.tar.gz

- Building wheel
- Built rick_portal_gun-0.1.0-py3-none-any.whl
```
Expand Down Expand Up @@ -312,7 +300,7 @@ Now you can open another terminal and install that package from the file for you
<div class="termy">

```console
$ pip install --user /home/rock/code/rick-portal-gun/dist/rick_portal_gun-0.1.0-py3-none-any.whl
$ pip install --user /home/rick/rick-portal-gun/dist/rick_portal_gun-0.1.0-py3-none-any.whl

---> 100%
```
Expand Down Expand Up @@ -347,7 +335,7 @@ Having it installed globally (and not in a single environment), you can now inst
```console
$ rick-portal-gun --install-completion

zsh completion installed in /home/user/.zshrc.
zsh completion installed in /home/rick/.zshrc.
Completion will take effect once you restart the terminal.
```

Expand Down Expand Up @@ -419,8 +407,7 @@ The file would live right beside `__init__.py`:
│ ├── __main__.py
│ └── main.py
└── tests
├── __init__.py
└── test_rick_portal_gun.py
└── __init__.py
```

No other file has to import it, you don't have to reference it in your `pyproject.toml` or anything else, it just works by default, as it is standard Python behavior.
Expand All @@ -437,7 +424,7 @@ Now, after installing your package, if you call it with `python -m` it will work
<div class="termy">

```console
$ python -m rick_portal_gun
$ python -m rick_portal_gun --help

Usage: __main__.py [OPTIONS] COMMAND [ARGS]...

Expand Down Expand Up @@ -487,7 +474,7 @@ app(prog_name="rick-portal-gun")
<div class="termy">

```console
$ python -m rick_portal_gun
$ python -m rick_portal_gun --help

Usage: rick-portal-gun [OPTIONS] COMMAND [ARGS]...

Expand Down Expand Up @@ -577,7 +564,6 @@ $ poetry publish --build
Building rick-portal-gun (0.1.0)
- Building sdist
- Built rick-portal-gun-0.1.0.tar.gz

- Building wheel
- Built rick_portal_gun-0.1.0-py3-none-any.whl

Expand All @@ -604,10 +590,10 @@ $ pip uninstall rick-portal-gun
Found existing installation: rick-portal-gun 0.1.0
Uninstalling rick-portal-gun-0.1.0:
Would remove:
/home/user/.local/bin/rick-portal-gun
/home/user/.local/lib/python3.10/site-packages/rick_portal_gun-0.1.0.dist-info/*
/home/user/.local/lib/python3.10/site-packages/rick_portal_gun/*
# Proceed (y/n)? $ y
/home/rick/.local/bin/rick-portal-gun
/home/rick/.local/lib/python3.10/site-packages/rick_portal_gun-0.1.0.dist-info/*
/home/rick/.local/lib/python3.10/site-packages/rick_portal_gun/*
# Proceed (Y/n)? $ Y
Successfully uninstalled rick-portal-gun-0.1.0
```

Expand All @@ -622,11 +608,16 @@ $ pip install --user rick-portal-gun

// Notice that it says "Downloading" 🚀
Collecting rick-portal-gun
Downloading rick_portal_gun-0.1.0-py3-none-any.whl (1.8 kB)
Requirement already satisfied: typer[all]<0.0.12,>=0.0.11 in ./.local/lib/python3.10/site-packages (from rick-portal-gun) (0.0.11)
Requirement already satisfied: click<7.2.0,>=7.1.1 in ./anaconda3/lib/python3.10/site-packages (from typer[all]<0.0.12,>=0.0.11->rick-portal-gun) (7.1.1)
Requirement already satisfied: colorama; extra == "all" in ./anaconda3/lib/python3.10/site-packages (from typer[all]<0.0.12,>=0.0.11->rick-portal-gun) (0.4.3)
Requirement already satisfied: shellingham; extra == "all" in ./anaconda3/lib/python3.10/site-packages (from typer[all]<0.0.12,>=0.0.11->rick-portal-gun) (1.3.1)
Downloading rick_portal_gun-0.1.0-py3-none-any.whl.metadata (435 bytes)
Requirement already satisfied: typer<0.13.0,>=0.12.3 in ./.local/lib/python3.10/site-packages (from rick-portal-gun==0.1.0) (0.12.3)
Requirement already satisfied: typing-extensions>=3.7.4.3 in ./.local/lib/python3.10/site-packages (from typer<0.13.0,>=0.12.3->rick-portal-gun==0.1.0) (4.11.0)
Requirement already satisfied: click>=8.0.0 in ./.local/lib/python3.10/site-packages (from typer<0.13.0,>=0.12.3->rick-portal-gun==0.1.0) (8.1.7)
Requirement already satisfied: shellingham>=1.3.0 in ./.local/lib/python3.10/site-packages (from typer<0.13.0,>=0.12.3->rick-portal-gun==0.1.0) (1.5.4)
Requirement already satisfied: rich>=10.11.0 in ./.local/lib/python3.10/site-packages (from typer<0.13.0,>=0.12.3->rick-portal-gun==0.1.0) (13.7.1)
Requirement already satisfied: pygments<3.0.0,>=2.13.0 in ./.local/lib/python3.10/site-packages (from rich>=10.11.0->typer<0.13.0,>=0.12.3->rick-portal-gun==0.1.0) (2.17.2)
Requirement already satisfied: markdown-it-py>=2.2.0 in ./.local/lib/python3.10/site-packages (from rich>=10.11.0->typer<0.13.0,>=0.12.3->rick-portal-gun==0.1.0) (3.0.0)
Requirement already satisfied: mdurl~=0.1 in ./.local/lib/python3.10/site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<0.13.0,>=0.12.3->rick-portal-gun==0.1.0) (0.1.2)
Downloading rick_portal_gun-0.1.0-py3-none-any.whl (1.8 kB)
kinuax marked this conversation as resolved.
Show resolved Hide resolved
Installing collected packages: rick-portal-gun
Successfully installed rick-portal-gun-0.1.0
```
Expand Down Expand Up @@ -686,14 +677,11 @@ rick-portal-gun = "rick_portal_gun.main:app"

[tool.poetry.dependencies]
python = "^3.10"
typer = {extras = ["all"], version = "^0.1.0"}

[tool.poetry.dev-dependencies]
pytest = "^5.2"
typer = "^0.12.0"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
```

And in the file `rick_portal_gun/__init__.py`:
Expand All @@ -714,7 +702,6 @@ $ poetry publish --build
Building rick-portal-gun (0.2.0)
- Building sdist
- Built rick-portal-gun-0.2.0.tar.gz

- Building wheel
- Built rick_portal_gun-0.2.0-py3-none-any.whl

Expand Down