### Install from other data sources Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/installing-packages.rst Installs a package using a custom index URL, such as one served by a helper application. This example shows starting a helper and then installing. ```bash ./s3helper --port=7777 python -m pip install --extra-index-url http://localhost:7777 SomeProject ``` -------------------------------- ### Example INSTALLER File Content (pip) Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/recording-installed-packages.rst This snippet shows a common content for the INSTALLER file, indicating that 'pip' was the tool used for installation. This file is a single-line text file. ```text pip ``` -------------------------------- ### Example Installation Output Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/packaging-projects.rst This output indicates that your package was successfully collected and installed from TestPyPI. ```text Collecting example-package-YOUR-USERNAME-HERE Downloading https://test-files.pythonhosted.org/packages/.../example_package_YOUR_USERNAME_HERE_0.0.1-py3-none-any.whl Installing collected packages: example_package_YOUR_USERNAME_HERE Successfully installed example_package_YOUR_USERNAME_HERE-0.0.1 ``` -------------------------------- ### Example build-details.json Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/build-details/index.rst This is an example of the build-details.json file format. It provides build-specific information for a Python installation. ```json { "version": "3.14.0", "impl": "cpython", "abi": "cp314", "platform": "linux", "arch": "x86_64", "build_date": "2024-01-01T12:00:00Z" } ``` -------------------------------- ### Pip Installation Output Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/installing-using-pip-and-virtual-environments.rst Example output showing pip downloading and installing the 'requests' package and its dependencies. ```text Collecting requests Using cached requests-2.18.4-py2.py3-none-any.whl Collecting chardet<3.1.0,>=3.0.2 (from requests) Using cached chardet-3.0.4-py2.py3-none-any.whl Collecting urllib3<1.23,>=1.21.1 (from requests) Using cached urllib3-1.22-py2.py3-none-any.whl Collecting certifi>=2017.4.17 (from requests) Using cached certifi-2017.7.27.1-py2.py3-none-any.whl Collecting idna<2.7,>=2.5 (from requests) Using cached idna-2.6-py2.py3-none-any.whl Installing collected packages: chardet, urllib3, certifi, idna, requests Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22 ``` -------------------------------- ### Build and Preview Guide Source: https://github.com/pypa/packaging.python.org/blob/main/source/contribute.rst Builds the guide and serves it locally via an HTTP server. Access the guide at http://localhost:8000. ```bash nox -s preview ``` -------------------------------- ### Example INSTALLER File Content (Custom Tool) Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/recording-installed-packages.rst This snippet shows an alternative content for the INSTALLER file, indicating a custom installation tool named 'MegaCorp Cloud Install-O-Matic'. This file is a single-line text file. ```text MegaCorp Cloud Install-O-Matic ``` -------------------------------- ### Pipenv package installation output Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/managing-dependencies.rst Example output showing Pipenv creating a virtual environment, installing packages, and updating the Pipfile. ```text Creating a Pipfile for this project... Creating a virtualenv for this project... Using base prefix '/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6' New python executable in ~/.local/share/virtualenvs/tmp-agwWamBd/bin/python3.6 Also creating executable in ~/.local/share/virtualenvs/tmp-agwWamBd/bin/python Installing setuptools, pip, wheel...done. Virtualenv location: ~/.local/share/virtualenvs/tmp-agwWamBd Installing requests... Collecting requests Using cached requests-2.18.4-py2.py3-none-any.whl Collecting idna<2.7,>=2.5 (from requests) Using cached idna-2.6-py2.py3-none-any.whl Collecting urllib3<1.23,>=1.21.1 (from requests) Using cached urllib3-1.22-py2.py3-none-any.whl Collecting chardet<3.1.0,>=3.0.2 (from requests) Using cached chardet-3.0.4-py2.py3-none-any.whl Collecting certifi>=2017.4.17 (from requests) Using cached certifi-2017.7.27.1-py2.py3-none-any.whl Installing collected packages: idna, urllib3, chardet, certifi, requests Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22 Adding requests to Pipfile's [packages]... ``` -------------------------------- ### Install and Run a Package with pipx Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/installing-stand-alone-command-line-tools.rst Installs a specified package using pipx and makes its command-line applications globally available. The example shows installing and running the 'cowsay' application. ```console pipx install PACKAGE PACKAGE_APPLICATION [ARGS] ``` ```console pipx install cowsay installed package cowsay 6.1, installed using Python 3.12.2 These apps are now globally available - cowsay done! ✨ 🌟 ✨ cowsay -t moo ___ < moo > === \ \ ^__^ (oo)\\_______ (__)\\ )\/ || || ||----w | ``` -------------------------------- ### Install project using pip Source: https://github.com/pypa/packaging.python.org/blob/main/source/discussions/setup-py-deprecated.rst Use `pip install .` to install a project from the current directory, replacing `python setup.py install`. ```bash python -m pip install . ``` -------------------------------- ### Install pip using get-pip.py Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/installing-packages.rst Download and run the 'get-pip.py' script to install or upgrade pip, setuptools, and wheel. Use this if the 'ensurepip' method fails. Be cautious with system-managed Python installations. ```bash python get-pip.py ``` -------------------------------- ### Build wheels and install locally with pip Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/index-mirrors-and-caches.rst Use pip wheel to pre-build installation files for project requirements, then install locally using --no-index and --find-links. ```bash python3 -m pip wheel --wheel-dir=/tmp/wheelhouse SomeProject python3 -m pip install --no-index --find-links=/tmp/wheelhouse SomeProject ``` -------------------------------- ### Install pip, setuptools, and wheel on openSUSE Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/installing-using-linux-tools.rst Use this command to install pip, setuptools, and wheel on openSUSE systems. ```bash sudo zypper install python3-pip python3-setuptools python3-wheel ``` -------------------------------- ### Start Python Interpreter Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/packaging-projects.rst Launch the Python interpreter to test your installed package. ```bash python3 ``` ```bat py ``` -------------------------------- ### Pip version information Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/installing-using-pip-and-virtual-environments.rst Example output showing the installed pip version and its location within a virtual environment. ```text pip 23.3.1 from .../.venv/lib/python3.9/site-packages (python 3.9) ``` -------------------------------- ### Example RECORD File Content Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/recording-installed-packages.rst This snippet shows the typical format of a RECORD file, which lists installed files along with their hash and size. Entries can have empty hash and size fields, particularly for .pyc files and the RECORD file itself. ```text /usr/bin/black,sha256=iFlOnL32lIa-RKk-MDihcbJ37wxmRbE4xk6eVYVTTeU,220 ../../../bin/blackd,sha256=lCadt4mcU-B67O1gkQVh7-vsKgLpx6ny1le34Jz6UVo,221 __pycache__/black.cpython-38.pyc,, __pycache__/blackd.cpython-38.pyc,, black-19.10b0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 black-19.10b0.dist-info/licenses/LICENSE,sha256=nAQo8MO0d5hQz1vZbhGqqK_HLUqG1KNiI9erouWNbgA,1080 black-19.10b0.dist-info/METADATA,sha256=UN40nGoVVTSpvLrTBwNsXgZdZIwoKFSrrDDHP6B7-A0,58841 black-19.10b0.dist-info/RECORD,, black.py,sha256=45IF72OgNfF8WpeNHnxV2QGfbCLubV5Xjl55cI65kYs,140161 blackd.py,sha256=JCxaK4hLkMRwVfZMj8FRpRRYC0172-juKqbN22bISLE,6672 blib2to3/__init__.py,sha256=9_8wL9Scv8_Cs8HJyJHGvx1vwXErsuvlsAqNZLcJQR0,8 blib2to3/__pycache__/__init__.cpython-38.pyc,, blib2to3/__pycache__/pygram.cpython-38.pyc,sha256=zpXgX4FHDuoeIQKO_v0sRsB-RzQFsuoKoBYvraAdoJw,1512 blib2to3/__pycache__/pytree.cpython-38.pyc,sha256=LYLplXtG578ZjaFeoVuoX8rmxHn-BMAamCOsJMU1b9I,24910 blib2to3/pygram.py,sha256=mXpQPqHcamFwch0RkyJsb92Wd0kUP3TW7d-u9dWhCGY,2085 blib2to3/pytree.py,sha256=RWj3IL4U-Ljhkn4laN0C3p7IRdfvT3aIRjTV-x9hK1c,28530 ``` -------------------------------- ### Python Compatibility Tags Example Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/platform-compatibility-tags.rst An example list of supported compatibility tags for an installer running under CPython 3.3 on a linux_x86_64 system, ordered from most to least preferred. ```text cp33-cp33m-linux_x86_64 cp33-abi3-linux_x86_64 cp3-abi3-linux_x86_64 cp33-none-linux_x86_64* cp3-none-linux_x86_64* py33-none-linux_x86_64* py3-none-linux_x86_64* cp33-none-any cp3-none-any py33-none-any py3-none-any py32-none-any py31-none-any py30-none-any ``` -------------------------------- ### Example discovered Flask plugins Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/creating-and-discovering-plugins.rst Illustrates the expected output of the plugin discovery code when Flask-SQLAlchemy and Flask-Talisman are installed. ```python { 'flask_sqlalchemy': , 'flask_talisman': , } ``` -------------------------------- ### Example discovered plugins in namespace Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/creating-and-discovering-plugins.rst Shows the expected output when discovering plugins within a namespace package like 'myapp.plugins', assuming 'myapp.plugins.a' and 'myapp.plugins.b' are installed. ```python { 'a': , 'b': , } ``` -------------------------------- ### Install from requirements file Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/installing-packages.rst Installs packages listed in a requirements file. Use the appropriate command for your operating system. ```bash python3 -m pip install -r requirements.txt ``` ```bat py -m pip install -r requirements.txt ``` -------------------------------- ### Example Upload Output Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/packaging-projects.rst This is an example of the output you might see after successfully uploading your package archives. ```text Uploading distributions to https://test.pypi.org/legacy/ Enter your API token: Uploading example_package_YOUR_USERNAME_HERE-0.0.1-py3-none-any.whl 100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.2/8.2 kB • 00:01 • ? Uploading example_package_YOUR_USERNAME_HERE-0.0.1.tar.gz 100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.8/6.8 kB • 00:00 • ? ``` -------------------------------- ### Editable Install from Local Directory Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/direct-url.rst Perform an editable installation from a local directory. This command generates a direct_url.json file. ```bash pip install -e ./app ``` -------------------------------- ### Install project in editable mode using pip Source: https://github.com/pypa/packaging.python.org/blob/main/source/discussions/setup-py-deprecated.rst Use `pip install --editable .` for editable installs, replacing `python setup.py develop`. ```bash python -m pip install --editable . ``` -------------------------------- ### Install from Local Directory Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/direct-url.rst Install a distribution from a local directory path. This command generates a direct_url.json file. ```bash pip install ./app ``` ```bash pip install file:///home/user/app ``` -------------------------------- ### Install Package with Extras Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/installing-using-pip-and-virtual-environments.rst Installs a package along with its optional 'extras' dependencies, such as 'security' for requests. ```bash python3 -m pip install 'requests[security]' ``` ```bat py -m pip install "requests[security]" ``` -------------------------------- ### Install Pre-release Versions Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/installing-using-pip-and-virtual-environments.rst Installs pre-release versions of a package using the --pre flag. ```bash python3 -m pip install --pre requests ``` ```bat py -m pip install --pre requests ``` -------------------------------- ### Configure setup.py for PyPI README Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/making-a-pypi-friendly-readme.rst Example setup.py configuration to read a README.md file and set it as the long description with text/markdown content type for PyPI. ```python from setuptools import setup # read the contents of your README file from pathlib import Path this_directory = Path(__file__).parent long_description = (this_directory / "README.md").read_text() setup( name='an_example_package', # other arguments omitted long_description=long_description, long_description_content_type='text/markdown' ) ``` -------------------------------- ### Discover Flask plugins by naming convention Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/creating-and-discovering-plugins.rst Use pkgutil.iter_modules to find installed modules starting with 'flask_'. Requires no specific setup beyond having the plugins installed. ```python import importlib import pkgutil discovered_plugins = { name: importlib.import_module(name) for finder, name, ispkg in pkgutil.iter_modules() if name.startswith('flask_') } ``` -------------------------------- ### Example EXTERNALLY-MANAGED file content Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/externally-managed-environments.rst This INI file provides instructions to users attempting to install Python packages system-wide when the system is externally managed. It guides users towards using the distribution's package manager, virtual environments, or pipx. ```ini [externally-managed] Error=To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. If you wish to install a non-Debian packaged Python application, it may be easiest to use pipx install xyz, which will manage a virtual environment for you. Make sure you have pipx installed. See /usr/share/doc/python3.9/README.venv for more information. ``` -------------------------------- ### Setup.py with Dynamic Version Calculation Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/modernize-setup-py-project.rst An example setup.py file that dynamically calculates the version using an external toolkit. This requires the toolkit to be listed in pyproject.toml's build-system.requires. ```python import setuptools import some_build_toolkit # comes from the `some-build-toolkit` library def get_version(): version = some_build_toolkit.compute_version() return version setuptools.setup( name="my-project", version=get_version(), ) ``` -------------------------------- ### Minimal setup.py for legacy processes Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/modernize-setup-py-project.rst Use this when a process requires a setup.py file but all metadata is in pyproject.toml. This file can be left minimalistic. ```python import setuptools setuptools.setup() ``` -------------------------------- ### Get Preferred Installation Scheme Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/externally-managed-environments.rst Retrieves the preferred installation scheme for a given path type. Used to determine where packages should be installed. ```python sysconfig.get_preferred_scheme('prefix') ``` -------------------------------- ### Command-Line Interface Setup Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/creating-command-line-tools.rst Sets up the Typer application and registers the greet function as a command. This file acts as the entry point for the CLI. ```python import typer from .greet import greet app = typer.Typer() app.command()(greet) if __name__ == "__main__": app() ``` -------------------------------- ### Full Project Configuration Example Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/writing-pyproject-toml.rst A comprehensive example of project configuration including build system, project details, dependencies, authors, maintainers, URLs, scripts, and entry points. ```toml [build-system] requires = ["hatchling"] build-backend = "hatchling.build" [project] name = "spam-eggs" version = "2020.0.0" dependencies = [ "httpx", "gidgethub[httpx]>4.0.0", "django>2.1; os_name != 'nt'", "django>2.0; os_name == 'nt'", ] requires-python = ">=3.8" authors = [ {name = "Pradyun Gedam", email = "pradyun@example.com"}, {name = "Tzu-Ping Chung", email = "tzu-ping@example.com"}, {name = "Another person"}, {email = "different.person@example.com"}, ] maintainers = [ {name = "Brett Cannon", email = "brett@example.com"} ] description = "Lovely Spam! Wonderful Spam!" readme = "README.rst" license = "MIT" license-files = ["LICEN[CS]E.*"] keywords = ["egg", "bacon", "sausage", "tomatoes", "Lobster Thermidor"] classifiers = [ "Development Status :: 4 - Beta", "Programming Language :: Python" ] [project.optional-dependencies] gui = ["PyQt5"] cli = [ "rich", "click", ] [project.urls] Homepage = "https://example.com" Documentation = "https://readthedocs.org" Repository = "https://github.com/me/spam.git" "Bug Tracker" = "https://github.com/me/spam/issues" Changelog = "https://github.com/me/spam/blob/master/CHANGELOG.md" [project.scripts] spam-cli = "spam:main_cli" [project.gui-scripts] spam-gui = "spam:main_gui" [project.entry-points."spam.magical"] tomatoes = "spam:main_tomatoes" ``` -------------------------------- ### Install Compatible Version of a Package Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/installing-packages.rst Use the '~=' operator to install a version that is compatible with a specified version. For example, '~=1.4.2' installs any version '==1.4.*' that is also '>=1.4.2'. ```bash python3 -m pip install "SomeProject~=1.4.2" ``` ```bat py -m pip install "SomeProject~=1.4.2" ``` -------------------------------- ### Setuptools Build System Configuration Source: https://github.com/pypa/packaging.python.org/blob/main/source/shared/build-backend-tabs.rst Configure setuptools as your build backend. Use a recent version for compatibility. ```toml [build-system] requires = ["setuptools >= 77.0.3"] build-backend = "setuptools.build_meta" ``` -------------------------------- ### Install Nox for Local Building Source: https://github.com/pypa/packaging.python.org/blob/main/source/contribute.rst Install or upgrade the Nox build tool using pip. This is a prerequisite for building the guide locally. ```bash python -m pip install --user nox ``` -------------------------------- ### Setup.py with Static Metadata Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/modernize-setup-py-project.rst A basic setup.py file containing static project metadata. This can be fully replaced by the [project] table in pyproject.toml. ```python import setuptools setuptools.setup( name="my-project", version="1.2.3", ) ``` -------------------------------- ### Editable Install with VCS Dependency Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/distributing-packages-using-setuptools.rst Example of a requirements file to install a project and a specific dependency from a Version Control System (VCS) in editable mode. ```text -e . -e bar @ git+https://somerepo/bar.git ``` -------------------------------- ### Basic License Declaration in setup.cfg Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/licensing-examples-and-user-scenarios.rst This is the equivalent of the basic pyproject.toml example for projects using setup.cfg. It specifies a single SPDX license expression. ```ini [metadata] license = MIT ``` -------------------------------- ### Install build tools for README rendering Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/making-a-pypi-friendly-readme.rst Upgrade setuptools, wheel, and twine to ensure GitHub-flavored Markdown renders correctly on PyPI. Recommended for projects using Markdown for their README. ```bash python3 -m pip install --user --upgrade setuptools wheel twine ``` ```bat py -m pip install --user --upgrade setuptools wheel twine ``` -------------------------------- ### Get Default Python Scheme Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/externally-managed-environments.rst This function retrieves the default sysconfig scheme for the current Python installation. It's typically used by tools like pip to determine installation paths. ```python sysconfig.get_default_scheme() ``` -------------------------------- ### Editable Install with Local Directory Dependency Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/distributing-packages-using-setuptools.rst Example of a requirements file to install a project and a local directory dependency in editable mode. Ensure local paths are listed first to override PyPI fulfillment. ```text -e /path/to/project/bar -e . ``` -------------------------------- ### Example Entry Point Structure Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/creating-and-discovering-plugins.rst This illustrates the structure of a discovered entry point, showing its name, value, and group. ```python (EntryPoint(name='a', value='myapp_plugin_a', group='myapp.plugins'), ... ) ``` -------------------------------- ### Install from local src tree normally Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/installing-packages.rst Installs a project from a local source tree. Use the appropriate command for your operating system. ```bash python3 -m pip install ``` ```bat py -m pip install ``` -------------------------------- ### Get Standard Library Path Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/externally-managed-environments.rst Retrieves the path for the standard library installation. This is used to ensure compatibility and correct placement of core Python modules. ```python sysconfig.get_path("stdlib") ``` -------------------------------- ### Obsoletes-Dist Field Examples Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/core-metadata.rst Use Obsoletes-Dist to specify distributions that should not be installed alongside the current one. It supports simple names, version constraints, and environment markers. ```text Obsoletes-Dist: Gorgon ``` ```text Obsoletes-Dist: OtherProject (<3.0) ``` ```text Obsoletes-Dist: Foo; os_name == "posix" ``` -------------------------------- ### Appveyor Build Script Example Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/supporting-windows-using-appveyor.rst This batch script is a sample for setting up an SDK build environment within Appveyor. It is typically used in the 'install' section of appveyor.yml. ```bat @echo off setlocal REM Set up the build environment for the SDK REM Define the SDK version to install set SDK_VERSION=1.2.3 REM Download the SDK installer echo Downloading SDK version %SDK_VERSION%... curl -L -o sdk_installer.exe https://example.com/sdk/installer-%SDK_VERSION%.exe REM Run the installer silently echo Installing SDK... start /wait sdk_installer.exe /S /D=C:\SDK REM Add SDK to PATH set PATH=C:\SDK\bin;%PATH% REM Verify installation echo Verifying SDK installation... if exist C:\SDK\bin\sdk.exe ( echo SDK installed successfully. ) else ( echo SDK installation failed. exit /b 1 ) endlocal exit /b 0 ``` -------------------------------- ### Example ``build-details.json`` v1.0 Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/build-details/v1.0.rst This is an example of a ``build-details.json`` file conforming to version 1.0 of the specification. It outlines details about a Python package build. ```json { "version": "1.0", "requires_python": "3.7", "build_backend": "setuptools.build_meta", "build_type": "wheel", "module_name": "my_package", "dependencies": [ "requests>=2.20.0", "numpy==1.20.0" ], "entry_points": { "console_scripts": [ "my_cli = my_package.cli:main" ] }, "extra_data": { "config_file": "config.yaml" } } ``` -------------------------------- ### Build the Guide Locally with Nox Source: https://github.com/pypa/packaging.python.org/blob/main/source/contribute.rst Run the Nox build command in the project's root folder to generate the HTML output for the guide. The output will be located in the './build/html' directory. ```bash nox -s build ``` -------------------------------- ### Install and Use Build Package Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows.rst This snippet shows how to install the 'build' package and use it to create distribution archives from source. It's a prerequisite for publishing. ```yaml - name: Install pypa/build run: python -m pip install build - name: Build source and wheel run: python -m build --sdist --wheel --outdir dist/ ``` -------------------------------- ### Get Distribution Package Version Source: https://github.com/pypa/packaging.python.org/blob/main/source/discussions/versioning.rst Use `importlib.metadata.version` to retrieve the version of a locally installed distribution package. This is the standard library approach for runtime version access. ```python import importlib.metadata importlib.metadata.version("cryptography") ``` -------------------------------- ### Get Total Downloads for a Project Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/analyzing-pypi-package-downloads.rst This query retrieves the total number of downloads for a specific project installed via pip within the last 30 days. ```sql SELECT COUNT(*) AS num_downloads FROM `bigquery-public-data.pypi.file_downloads` WHERE file.project = 'pytest' AND details.installer.name = 'pip' -- Only query the last 30 days of history AND DATE(timestamp) BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY) AND CURRENT_DATE() ``` -------------------------------- ### Example Distribution Files Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/packaging-projects.rst Illustrates the typical output files generated in the 'dist' directory after building a Python package. ```text dist/ ├── example_package_YOUR_USERNAME_HERE-0.0.1-py3-none-any.whl └── example_package_YOUR_USERNAME_HERE-0.0.1.tar.gz ``` -------------------------------- ### Create README.md for Example Package Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/packaging-projects.rst This is a basic README.md file content for an example package, written in Markdown. It includes a title and a brief description, with a link to GitHub-flavored Markdown documentation. ```md # Example Package This is a simple example package. You can use [GitHub-flavored Markdown](https://guides.github.com/features/mastering-markdown/) to write your content. ``` -------------------------------- ### Flat Layout Example Source: https://github.com/pypa/packaging.python.org/blob/main/source/discussions/src-layout-vs-flat-layout.rst Illustrates the file structure of a project using a flat layout, where configuration and package files are in the top-level directory. ```text . ├── README.md ├── noxfile.py ├── pyproject.toml ├── setup.py ├── awesome_package/ │ ├── __init__.py │ └── module.py └── tools/ ├── generate_awesomeness.py └── decrease_world_suck.py ``` -------------------------------- ### Install Pipenv on Windows Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/managing-dependencies.rst Use this command to install Pipenv using pip for user-specific installations on Windows. ```bat py -m pip install --user pipenv ``` -------------------------------- ### Setuptools Configuration for Namespace Packages (setup.cfg) Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/packaging-namespace-packages.rst Configures setuptools to find and include specific namespace packages using setup.cfg. ```ini [options] package_dir = =src packages = find_namespace: [options.packages.find] where = src ``` -------------------------------- ### Install Pipenv on Unix/macOS Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/managing-dependencies.rst Use this command to install Pipenv using pip for user-specific installations on Unix-like systems. ```bash python3 -m pip install --user pipenv ``` -------------------------------- ### Install for User Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/externally-managed-environments.rst Installs packages for the current user only. This command utilizes the 'user' scheme for determining the installation directory. ```bash pip install --user ``` -------------------------------- ### Example Package Structure Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/packaging-namespace-packages.rst Illustrates a typical package structure that can be split into multiple distributions using namespace packages. ```text mynamespace/ __init__.py subpackage_a/ __init__.py ... subpackage_b/ __init__.py ... module_b.py pyproject.toml ``` -------------------------------- ### Install from local archive Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/installing-packages.rst Installs a package from a local source archive file. Use the appropriate command for your operating system. ```bash python3 -m pip install ./downloads/SomeProject-1.0.4.tar.gz ``` ```bat py -m pip install ./downloads/SomeProject-1.0.4.tar.gz ``` -------------------------------- ### Install with Prefix Path Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/externally-managed-environments.rst Installs packages to a specified prefix path. This command uses the 'prefix' scheme to determine the installation location. ```bash pip install --prefix=/some/path ``` -------------------------------- ### Install Package with PDF Support on Windows Source: https://github.com/pypa/packaging.python.org/blob/main/source/tutorials/installing-packages.rst Commands for installing a specific package with PDF extras on Windows. You can install a specific version or an editable version. ```bat py -m pip install "SomePackage[PDF]" ``` ```bat py -m pip install "SomePackage[PDF]==3.0" ``` ```bat py -m pip install -e ".[PDF]" ``` -------------------------------- ### Install a Package with Pip Source: https://github.com/pypa/packaging.python.org/blob/main/source/flow.rst End users can install your published package into their Python environment using pip. This is the standard method for installing packages from PyPI. ```bash python3 -m pip install package-name ``` -------------------------------- ### Install from HTTP URL Source: https://github.com/pypa/packaging.python.org/blob/main/source/specifications/direct-url.rst Use this command to install a distribution directly from a remote HTTP URL. This will generate a direct_url.json file. ```bash pip install https://example.com/app-1.0.tgz ``` ```bash pip install https://example.com/app-1.0.whl ``` -------------------------------- ### Install and Run Executable Script with pipx Source: https://github.com/pypa/packaging.python.org/blob/main/source/guides/creating-command-line-tools.rst Install a package and make its executable script available as a command. Test the command with various arguments. ```console $ cd path/to/greetings/ $ pipx install . ``` ```console $ greet Greetings, friend! $ greet --doctor Brennan Greetings, Dr. Brennan! $ greet --title Ms. Parks Greetings, Ms. Parks! $ greet --title Mr. Greetings, Mr. mr! ```