Repository: pypa/pipx (python)

Issue:
pipx help identifies itself as __main__.py if executed using `python3 -m pipx`
<!-- Thank you for filing a bug! Please feel free to answer as much or as little of this template as you can. -->

**Describe the bug**
<!-- Please be as detailed as possible! -->
When executing pipx using `python3 -m pipx`, getting help with `--help` shows `usage: __main__.py` instead of `usage: pipx` 

**How to reproduce**
<!-- If possible, include output of `pipx --verbose ...` -->
`python3 -m pipx --help`
or using a subcommand, e.g.
`python3 -m pipx ensurepath --help`

**Expected behavior**
<!-- What should have happened? -->
Help text should start with:
`usage: pipx`
Help text instead starts with:
`usage: __main__.py`

This is probably a minor bug, but users may encounter it, for example, before executing `python3 -m pipx ensurepath` (as our installation directions recommend) if they first type `python3 -m pipx ensurepath --help`.

It could probably be easily fixed by adding `prog="pipx"` as an argument to `parser = argparse.ArgumentParser()` inside `get_command_parser()` in `main.py`.

Pull request:
Change the program name to `path/to/python -m pipx` when running as `python -m pipx`
<!-- add an 'x' in the brackets below -->
* [x] I have added an entry to `docs/changelog.md`

## Summary of changes

Change the program name to `path/to/python -m pipx` when running as `python -m pipx`.

Closes #433

Before:

```shell
$ python -m pipx -h
usage: pipx [-h] [--version]
            {install,inject,upgrade,upgrade-all,uninstall,uninstall-all,reinstall,reinstall-all,list,run,runpip,ensurepath,environment,completions} ...
```

After:

```shell
$ python -m pipx -h
usage: /usr/local/bin/python -m pipx [-h] [--version]
                                     {install,inject,upgrade,upgrade-all,uninstall,uninstall-all,reinstall,reinstall-all,list,run,runpip,ensurepath,environment,completions}
                                     ...
```

## Test plan
<!-- provide evidence of testing, preferably with command(s) that can be copy+pasted by others -->
Tested by running
```
$ /usr/local/bin/python -m pipx -h | grep "/usr/local/bin/python -m pipx"
```


Patch:
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..1230149
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,6 @@
+version: 2
+updates:
+  - package-ecosystem: "github-actions"
+    directory: "/"
+    schedule:
+      interval: "daily"
diff --git a/.github/workflows/publish_docs.yml b/.github/workflows/publish_docs.yml
index ef44282..f1bdf7d 100644
--- a/.github/workflows/publish_docs.yml
+++ b/.github/workflows/publish_docs.yml
@@ -13,9 +13,9 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Checkout main
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
       - name: Set up Python ${{ env.default-python }}
-        uses: actions/setup-python@v2
+        uses: actions/setup-python@v4
         with:
           python-version: ${{ env.default-python }}
       - name: Install nox
@@ -27,6 +27,6 @@ jobs:
           nox --error-on-missing-interpreters --non-interactive --session build_docs
       - name: Deploy docs
         if: ${{ success() }}
-        uses: mhausenblas/mkdocs-deploy-gh-pages@1.13
+        uses: mhausenblas/mkdocs-deploy-gh-pages@1.24
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6fbf86e..c90652e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 ## dev
 - Add `pipx uninject` command (#820)
+- [docs] Fix `pipx run` examples and update Python versions used by `pipx install` examples
+- [docs] Add an example for installation from source with extras
+
+- Change the program name to `path/to/python -m pipx` when running as `python -m pipx`
 
 ## 1.1.0
 
diff --git a/README.md b/README.md
index 47bc179..9e67943 100644
--- a/README.md
+++ b/README.md
@@ -164,6 +164,12 @@ pipx install git+https://github.com/psf/black.git@ce14fa8b497bae2b50ec48b3bd7022
 pipx install https://github.com/psf/black/archive/18.9b0.zip  # install a release
 ```
 
+The pip syntax with `egg` must be used when installing extras:
+
+```
+pipx install "git+https://github.com/psf/black.git#egg=black[jupyter]"
+```
+
 ### Walkthrough: Running an Application in a Temporary Virtual Environment
 
 This is an alternative to `pipx install`.
diff --git a/docs/examples.md b/docs/examples.md
index a6b93d2..ef4f1d9 100644
--- a/docs/examples.md
+++ b/docs/examples.md
@@ -2,8 +2,8 @@
 
 ```
 pipx install pycowsay
-pipx install --python python3.6 pycowsay
 pipx install --python python3.7 pycowsay
+pipx install --python python3.8 pycowsay
 pipx install git+https://github.com/psf/black
 pipx install git+https://github.com/psf/black.git@branch-name
 pipx install git+https://github.com/psf/black.git@git-hash
@@ -23,8 +23,8 @@ pipx enables you to test various combinations of Python versions and package ver
 ```
 pipx run BINARY  # latest version of binary is run with python3
 pipx run --spec PACKAGE==2.0.0 BINARY  # specific version of package is run
-pipx run --python 3.4 BINARY  # Installed and invoked with specific Python version
-pipx run --python 3.7 --spec PACKAGE=1.7.3 BINARY
+pipx run --python python3.7 BINARY  # Installed and invoked with specific Python version
+pipx run --python python3.9 --spec PACKAGE=1.7.3 BINARY
 pipx run --spec git+https://url.git BINARY  # latest version on default branch is run
 pipx run --spec git+https://url.git@branch BINARY
 pipx run --spec git+https://url.git@hash BINARY
diff --git a/src/pipx/main.py b/src/pipx/main.py
index 345e39e..f04e1f1 100644
--- a/src/pipx/main.py
+++ b/src/pipx/main.py
@@ -39,6 +39,18 @@ def print_version() -> None:
     print(__version__)
 
 
+def prog_name() -> str:
+    try:
+        prog = os.path.basename(sys.argv[0])
+        if prog == "__main__.py":
+            return f"{sys.executable} -m pipx"
+        else:
+            return prog
+    except Exception:
+        pass
+    return "pipx"
+
+
 SPEC_HELP = textwrap.dedent(
     """\
     The package name or specific installation source passed to pip.
@@ -669,7 +681,7 @@ def get_command_parser() -> argparse.ArgumentParser:
     completer_venvs = InstalledVenvsCompleter(venv_container)
 
     parser = argparse.ArgumentParser(
-        prog="pipx",
+        prog=prog_name(),
         formatter_class=LineWrapRawTextHelpFormatter,
         description=PIPX_DESCRIPTION,
     )


Test patch:
diff --git a/.github/workflows/create_tests_package_lists.yml b/.github/workflows/create_tests_package_lists.yml
index e8dbaa4..70bc86f 100644
--- a/.github/workflows/create_tests_package_lists.yml
+++ b/.github/workflows/create_tests_package_lists.yml
@@ -12,9 +12,9 @@ jobs:
         python-version: [3.7, 3.8, 3.9, "3.10"]
 
     steps:
-    - uses: actions/checkout@v2
+    - uses: actions/checkout@v3
     - name: Set up Python ${{ matrix.python-version }}
-      uses: actions/setup-python@v2
+      uses: actions/setup-python@v4
       with:
         python-version: ${{ matrix.python-version }}
     - name: Upgrade pip, Install nox
@@ -25,7 +25,7 @@ jobs:
       run: |
         nox --non-interactive --session create_test_package_list-${{ matrix.python-version }} -- ./new_tests_packages
     - name: Store reports as artifacts
-      uses: actions/upload-artifact@v2
+      uses: actions/upload-artifact@v3
       with:
         name: lists
         path: ./new_tests_packages
diff --git a/.github/workflows/exhaustive_package_test.yml b/.github/workflows/exhaustive_package_test.yml
index 97011de..3f4c3a3 100644
--- a/.github/workflows/exhaustive_package_test.yml
+++ b/.github/workflows/exhaustive_package_test.yml
@@ -13,9 +13,9 @@ jobs:
         python-version: [3.7, 3.8, 3.9, "3.10"]
 
     steps:
-    - uses: actions/checkout@v2
+    - uses: actions/checkout@v3
     - name: Set up Python ${{ matrix.python-version }}
-      uses: actions/setup-python@v2
+      uses: actions/setup-python@v4
       with:
         python-version: ${{ matrix.python-version }}
     - name: Upgrade pip, Install nox
@@ -27,7 +27,7 @@ jobs:
       run: |
         nox --non-interactive --session test_all_packages-${{ matrix.python-version }}
     - name: Store reports as artifacts
-      uses: actions/upload-artifact@v2
+      uses: actions/upload-artifact@v3
       with:
         name: reports-raw
         path: reports
@@ -39,7 +39,7 @@ jobs:
 
     steps:
     - name: Get report artifacts
-      uses: actions/download-artifact@v2
+      uses: actions/download-artifact@v3
       with:
         name: reports-raw
     - name: Collate reports
@@ -57,7 +57,7 @@ jobs:
         cat all_packages_deps_errors_* > all_deps_errors_lf.txt
         tr -d '\r' < all_deps_errors_lf.txt > reports/all_deps_errors.txt
     - name: Store collated and raw reports as artifacts
-      uses: actions/upload-artifact@v2
+      uses: actions/upload-artifact@v3
       with:
         name: reports-final
         path: reports
diff --git a/.github/workflows/publish-testpypi.yml b/.github/workflows/publish-testpypi.yml
index 494f995..2124ca2 100644
--- a/.github/workflows/publish-testpypi.yml
+++ b/.github/workflows/publish-testpypi.yml
@@ -19,9 +19,9 @@ jobs:
     runs-on: ubuntu-latest
     steps:
     - name: Checkout ${{ github.ref }}
-      uses: actions/checkout@v2
+      uses: actions/checkout@v3
     - name: Set up Python ${{ env.default-python }}
-      uses: actions/setup-python@v2
+      uses: actions/setup-python@v4
       with:
         python-version: ${{ env.default-python }}
     - name: Upgrade pip, Install nox
@@ -32,7 +32,7 @@ jobs:
       run: |
         nox --error-on-missing-interpreters --non-interactive --session build
     - name: Publish to Test PyPi
-      uses: pypa/gh-action-pypi-publish@v1.4.1
+      uses: pypa/gh-action-pypi-publish@v1.5.0
       with:
         user: __token__
         password: ${{ secrets.test_pypi_password }}
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index ab6949a..b838fd5 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -20,9 +20,9 @@ jobs:
   lint:
     runs-on: ubuntu-latest
     steps:
-    - uses: actions/checkout@v2
+    - uses: actions/checkout@v3
     - name: Set up Python ${{ env.default-python }}
-      uses: actions/setup-python@v2
+      uses: actions/setup-python@v4
       with:
         python-version: ${{ env.default-python }}
     - name: Upgrade pip, Install nox
@@ -36,9 +36,9 @@ jobs:
   verify-docs:
     runs-on: ubuntu-latest
     steps:
-    - uses: actions/checkout@v2
+    - uses: actions/checkout@v3
     - name: Set up Python ${{ env.default-python }}
-      uses: actions/setup-python@v2
+      uses: actions/setup-python@v4
       with:
         python-version: ${{ env.default-python }}
     - name: Upgrade pip, Install nox
@@ -63,9 +63,9 @@ jobs:
             python-version: "3.10"
 
     steps:
-    - uses: actions/checkout@v2
+    - uses: actions/checkout@v3
     - name: Set up Python ${{ matrix.python-version }}
-      uses: actions/setup-python@v2
+      uses: actions/setup-python@v4
       with:
         python-version: ${{ matrix.python-version }}
     - name: Get pip cache dir
@@ -73,12 +73,12 @@ jobs:
       run: |
         echo "::set-output name=dir::$(pip cache dir)"
     - name: Persistent Github pip cache
-      uses: actions/cache@v2
+      uses: actions/cache@v3
       with:
         path: ${{ steps.pip-cache.outputs.dir }}
         key: ${{ runner.os }}-pip${{ matrix.python-version }}
     - name: Persistent .pipx_tests/package_cache
-      uses: actions/cache@v2
+      uses: actions/cache@v3
       with:
         path: ${{ github.workspace }}/.pipx_tests/package_cache/${{ matrix.python-version }}
         key: pipx-tests-package-cache-${{ runner.os }}-${{ matrix.python-version }}
@@ -97,9 +97,9 @@ jobs:
     runs-on: ubuntu-latest
     steps:
     - name: Checkout ${{ github.ref }}
-      uses: actions/checkout@v2
+      uses: actions/checkout@v3
     - name: Set up Python ${{ env.default-python }}
-      uses: actions/setup-python@v2
+      uses: actions/setup-python@v4
       with:
         python-version: ${{ env.default-python }}
     - name: Upgrade pip, Install nox
@@ -110,7 +110,7 @@ jobs:
       run: |
         nox --error-on-missing-interpreters --non-interactive --session build
     - name: Publish to PyPi
-      uses: pypa/gh-action-pypi-publish@v1.4.1
+      uses: pypa/gh-action-pypi-publish@v1.5.0
       with:
         user: __token__
         password: ${{ secrets.pypi_password }}
diff --git a/tests/test_main.py b/tests/test_main.py
index ca5fbf1..fa15e6f 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -26,3 +26,16 @@ def test_version(monkeypatch, capsys):
     captured = capsys.readouterr()
     mock_exit.assert_called_with(0)
     assert main.__version__ in captured.out.strip()
+
+
+@pytest.mark.parametrize(
+    ("argv", "executable", "expected"),
+    [
+        ("/usr/bin/pipx", "", "pipx"),
+        ("__main__.py", "/usr/bin/python", "/usr/bin/python -m pipx"),
+    ],
+)
+def test_prog_name(monkeypatch, argv, executable, expected):
+    monkeypatch.setattr("pipx.main.sys.argv", [argv])
+    monkeypatch.setattr("pipx.main.sys.executable", executable)
+    assert main.prog_name() == expected