### Configuring Console Scripts for Examples in setup.py (Python) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This snippet demonstrates how to add new examples as console scripts within the `entry_points` section of the `setup.py` file. Each entry maps a command-line name to its corresponding Python main function, making the example executable directly from the terminal after package installation. ```python entry_points={ "console_scripts": [ "chat-demo=examples.chat.chat:main", "echo-demo=examples.echo.echo:main", "ping-demo=examples.ping.ping:main", "identify-demo=examples.identify.identify:main", ], } ``` -------------------------------- ### Installing libp2p and Starting Ping Server (Console) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.ping.rst This snippet demonstrates how to install the `libp2p` library using pip and then initiate the `ping-demo` application, which acts as a ping server. It also provides the command to be run in a separate console for the client to connect, showing the server's waiting state. ```console $ python -m pip install libp2p Collecting libp2p ... Successfully installed libp2p-x.x.x $ ping-demo Run this from the same folder in another console: ping-demo -p 8001 -d /ip4/127.0.0.1/tcp/8000/p2p/QmXfptdHU6hqG95JswxYVUH4bphcK8y18mhFcgUQFe6fCN Waiting for incoming connection... ``` -------------------------------- ### Installing libp2p and Starting Identify Host (Console) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.identify.rst This snippet demonstrates how to install the `libp2p` library using pip and then initiate the `identify-demo` script as the first host. It shows the expected output, including the command to run on a second console to connect to this host. ```console $ python -m pip install libp2p Collecting libp2p ... Successfully installed libp2p-x.x.x $ identify-demo First host listening. Run this from another console: identify-demo -p 8889 -d /ip4/0.0.0.0/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM Waiting for incoming identify request... ``` -------------------------------- ### Installing libp2p and Starting Initial PubSub Chat Node (Console) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.pubsub.rst This snippet demonstrates how to install the `libp2p` library using pip and then initiate the first instance of the PubSub chat application. It shows the console output, including the assigned peer ID, listening address, and the command needed to connect a second peer to this node. ```console $ python -m pip install libp2p Collecting libp2p ... Successfully installed libp2p-x.x.x $ pubsub-demo 2025-04-06 23:59:17,471 - pubsub-demo - INFO - Running pubsub chat example... 2025-04-06 23:59:17,471 - pubsub-demo - INFO - Your selected topic is: pubsub-chat 2025-04-06 23:59:17,472 - pubsub-demo - INFO - Using random available port: 33269 2025-04-06 23:59:17,490 - pubsub-demo - INFO - Node started with peer ID: QmcJnocH1d1tz3Zp4MotVDjNfNFawXHw2dpB9tMYGTXJp7 2025-04-06 23:59:17,490 - pubsub-demo - INFO - Listening on: /ip4/0.0.0.0/tcp/33269 2025-04-06 23:59:17,490 - pubsub-demo - INFO - Initializing PubSub and GossipSub... 2025-04-06 23:59:17,491 - pubsub-demo - INFO - Pubsub and GossipSub services started. 2025-04-06 23:59:17,491 - pubsub-demo - INFO - Pubsub ready. 2025-04-06 23:59:17,491 - pubsub-demo - INFO - Subscribed to topic: pubsub-chat 2025-04-06 23:59:17,491 - pubsub-demo - INFO - Run this script in another console with: pubsub-demo -d /ip4/127.0.0.1/tcp/33269/p2p/QmcJnocH1d1tz3Zp4MotVDjNfNFawXHw2dpB9tMYGTXJp7 2025-04-06 23:59:17,491 - pubsub-demo - INFO - Waiting for peers... Type messages to send (press Enter to send): ``` -------------------------------- ### Running Identify-Push Dialer Process (Console) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.identify_push.rst This snippet shows the execution of the `identify-push-listener-dialer-demo` in dialer mode, connecting to a previously started listener. It illustrates the dialer host's setup, its connection to the listener, and the successful pushing of identify information, completing the interactive example. ```Console $ identify-push-listener-dialer-demo -d /ip4/0.0.0.0/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM ==== Starting Identify-Push Dialer on port 8889 ==== Dialer host ready! Listening on: /ip4/0.0.0.0/tcp/8889/p2p/QmZyXwVuTaBcDeRsSkJpOpWrSt Connecting to peer: QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM Successfully connected to listener! Pushing identify information to listener... Identify push completed successfully! Example completed successfully! ``` -------------------------------- ### Example py-libp2p Log Output Source: https://github.com/libp2p/py-libp2p/blob/main/docs/getting_started.rst This provides a concrete example of a py-libp2p log message, demonstrating how the timestamp - module_name - level - message format appears in practice. It shows a DEBUG level message from the libp2p.identity.identify module. ```text 2024-01-01 12:00:00,123 - libp2p.identity.identify - DEBUG - Starting identify protocol ``` -------------------------------- ### Installing py-libp2p Package (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/install.rst This command uses pip, Python's package installer, to download and install the `libp2p` library into the currently active virtual environment. This is the final step to make the `py-libp2p` library available for use in your Python projects. ```sh python -m pip install libp2p ``` -------------------------------- ### Installing libp2p Python Library Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.chat.rst This snippet demonstrates how to install the `libp2p` library using `pip`, the Python package installer. It shows the command to execute and the expected output upon successful installation, which is a prerequisite for running the chat demo. ```console $ python -m pip install libp2p Collecting libp2p ... Successfully installed libp2p-x.x.x ``` -------------------------------- ### Setting Up py-libp2p Development Environment on Linux with virtualenv (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst These commands provide an alternative setup for the `py-libp2p` development environment on Linux using `virtualenv`. It navigates into the project directory, creates and activates a virtual environment with a specified Python interpreter, installs project dependencies in editable mode, and sets up pre-commit hooks. ```sh cd py-libp2p virtualenv -p python venv . venv/bin/activate python -m pip install -e ".[dev]" pre-commit install ``` -------------------------------- ### Installing libp2p and Running Echo Server - Console Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.echo.rst This snippet demonstrates how to install the `libp2p` library using pip and then initiate the `echo-demo` application, which acts as the server, waiting for incoming connections. It shows the output of the installation process and the server's initial state, including the peer address for client connection. ```console $ python -m pip install libp2p Collecting libp2p ... Successfully installed libp2p-x.x.x $ echo-demo Run this from the same folder in another console: echo-demo -p 8001 -d /ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAmAsbxRR1HiGJRNVPQLNMeNsBCsXT3rDjoYBQzgzNpM5mJ Waiting for incoming connection... ``` -------------------------------- ### Starting libp2p Chat Demo (First Instance) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.chat.rst This snippet shows how to start the first instance of the `libp2p` chat demo. It provides the initial command to run and the output, which includes the connection string for a second peer to connect to this instance. ```console $ chat-demo Run this from the same folder in another console: chat-demo -p 8001 -d /ip4/127.0.0.1/tcp/8000/p2p/QmPouApKqyxJDy6YT21EXNS6efuNzvJ3W3kqRQxkQ77GFJ Waiting for incoming connection... ``` -------------------------------- ### Enabling Module-Specific Debug Logging Source: https://github.com/libp2p/py-libp2p/blob/main/docs/getting_started.rst These examples show how to enable debug logging for specific py-libp2p modules by setting the LIBP2P_DEBUG environment variable with a module name and log level (e.g., identity.identify:DEBUG). It also illustrates how to configure logging for multiple modules with different levels using a comma-separated list. ```bash export LIBP2P_DEBUG=identity.identify:DEBUG ``` ```cmd set LIBP2P_DEBUG=identity.identify:DEBUG ``` ```powershell $env:LIBP2P_DEBUG="identity.identify:DEBUG" ``` ```bash export LIBP2P_DEBUG=identity.identify:DEBUG,transport:INFO ``` ```cmd set LIBP2P_DEBUG=identity.identify:DEBUG,transport:INFO ``` ```powershell $env:LIBP2P_DEBUG="identity.identify:DEBUG,transport:INFO" ``` -------------------------------- ### Creating Python Virtual Environment (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/install.rst This command initializes a new Python virtual environment named 'venv' in the current directory. Virtual environments are crucial for isolating project dependencies and avoiding conflicts with system-wide Python packages. ```sh python -m venv venv ``` -------------------------------- ### Activating Test Environment and Running Example (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This shell command sequence activates a temporary virtual environment created by `make package-test` and then executes a specific example, `identify-demo`, within that environment. This is part of the package smoke test to verify the example's functionality post-installation. ```sh source /tmp/tmpb9ybjgtg/package-smoke-test/bin/activate (package-smoke-test) $ identify-demo ``` -------------------------------- ### Setting Up py-libp2p Development Environment on macOS with virtualenv (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst These commands provide an alternative setup for the `py-libp2p` development environment on macOS using `virtualenv`. It navigates into the project directory, creates and activates a virtual environment with a specified Python interpreter, installs project dependencies in editable mode, and sets up pre-commit hooks. ```sh cd py-libp2p virtualenv -p python venv . venv/bin/activate python -m pip install -e ".[dev]" pre-commit install ``` -------------------------------- ### Installing and Verifying Git on Windows (PowerShell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst These commands install Git using the Windows Package Manager (`winget`) and then verify its successful installation by checking the Git version. Git is essential for cloning the `py-libp2p` repository and managing source control. ```powershell winget install --id Git.Git -e git --version ``` -------------------------------- ### Installing libp2p and Running Basic Identify-Push Demo (Console) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.identify_push.rst This snippet demonstrates the installation of the `libp2p` library using pip and then executes the `identify-push-demo`. It shows the console output of two hosts connecting and one pushing its identity information to the other, confirming successful protocol operation. ```Console $ python -m pip install libp2p Collecting libp2p ... Successfully installed libp2p-x.x.x $ identify-push-demo ==== Starting Identify-Push Example ==== Host 1 listening on /ip4/127.0.0.1/tcp/xxxxx/p2p/QmAbCdEfGhIjKlMnOpQrStUvWxYz Peer ID: QmAbCdEfGhIjKlMnOpQrStUvWxYz Host 2 listening on /ip4/127.0.0.1/tcp/xxxxx/p2p/QmZyXwVuTaBcDeRsSkJpOpWrSt Peer ID: QmZyXwVuTaBcDeRsSkJpOpWrSt Connecting Host 2 to Host 1... Host 2 successfully connected to Host 1 Host 1 pushing identify information to Host 2... Identify push completed successfully! Example completed successfully! ``` -------------------------------- ### Running Echo Client and Demonstrating Communication - Console Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.echo.rst This snippet shows how to run the `echo-demo` application as a client, connecting to a previously started server using its multiaddress. It illustrates the command-line arguments required for connection and displays the successful exchange of 'hi, there!' between the client and server, confirming the protocol's functionality. ```console $ echo-demo -p 8001 -d /ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAmAsbxRR1HiGJRNVPQLNMeNsBCsXT3rDjoYBQzgzNpM5mJ I am 16Uiu2HAmE3N7KauPTmHddYPsbMcBp2C6XAmprELX3YcFEN9iXiBu Sent: hi, there! Got: hi, there! ``` -------------------------------- ### Enabling Debug Logging in py-libp2p (Bash) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/getting_started.rst This snippet demonstrates how to enable debug logging for py-libp2p modules using the `LIBP2P_DEBUG` environment variable. It provides methods for setting the variable for the current shell session or for a single command execution across Unix-like systems and Windows (Command Prompt and PowerShell). ```bash # Method 1: Using export (persists for the shell session) # On Unix-like systems (Linux, macOS): export LIBP2P_DEBUG=DEBUG # On Windows (Command Prompt): set LIBP2P_DEBUG=DEBUG # On Windows (PowerShell): $env:LIBP2P_DEBUG="DEBUG" # Method 2: Setting for a single command # On Unix-like systems: LIBP2P_DEBUG=DEBUG python your_script.py # On Windows (Command Prompt): set LIBP2P_DEBUG=DEBUG && python your_script.py # On Windows (PowerShell): ``` -------------------------------- ### Activating Virtual Environment on Windows CMD (Batch) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/install.rst This command activates the Python virtual environment for users on Windows using the Command Prompt. Executing this batch script sets up the necessary environment variables to use the Python interpreter and packages from the 'venv' environment. ```batch venv\Scripts\activate.bat ``` -------------------------------- ### Understanding py-libp2p Log Format Source: https://github.com/libp2p/py-libp2p/blob/main/docs/getting_started.rst This snippet illustrates the standard format of log messages generated by py-libp2p, which includes a timestamp, module name, log level, and the actual message. This format helps in parsing and analyzing log data effectively. ```text timestamp - module_name - level - message ``` -------------------------------- ### Installing and Verifying Make on Windows via Chocolatey (PowerShell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst These commands install `make` using Chocolatey, a package manager for Windows, and then verify its installation by checking the `make` version. `make` is required for running certain build and test commands in the `py-libp2p` project. ```powershell choco install make make --version ``` -------------------------------- ### Activating Virtual Environment on Windows PowerShell Source: https://github.com/libp2p/py-libp2p/blob/main/docs/install.rst This command activates the Python virtual environment for users on Windows using PowerShell. Running this script configures the PowerShell session to correctly reference the Python interpreter and libraries installed within the 'venv' environment. ```powershell venv\Scripts\Activate.ps1 ``` -------------------------------- ### Activating Virtual Environment on Linux/macOS (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/install.rst This command activates the Python virtual environment on Linux and macOS systems. Activation modifies the shell's PATH environment variable, ensuring that Python commands and installed packages within 'venv' are prioritized. ```sh source venv/bin/activate ``` -------------------------------- ### Enabling General Debug Logging and Suppressing Output Source: https://github.com/libp2p/py-libp2p/blob/main/docs/getting_started.rst This section demonstrates how to enable general debug logging for py-libp2p applications by setting the LIBP2P_DEBUG environment variable to "DEBUG". It also provides methods to suppress console output by redirecting logs to /dev/null on Unix-like systems or nul on Windows, ensuring only file-based logging or no console output. ```powershell $env:LIBP2P_DEBUG="DEBUG"; python your_script.py ``` ```bash LIBP2P_DEBUG=DEBUG python your_script.py 2>/dev/null ``` ```cmd set LIBP2P_DEBUG=DEBUG && python your_script.py >nul 2>&1 ``` ```powershell $env:LIBP2P_DEBUG="DEBUG"; python your_script.py *> $null ``` -------------------------------- ### Installing and Verifying CMake on Windows (PowerShell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst These commands install CMake using the Windows Package Manager (`winget`) and then verify its successful installation by checking the CMake version. CMake is a prerequisite for building `py-libp2p` and should be added to the system PATH during installation. ```powershell winget install --id Kitware.CMake -e cmake --version ``` -------------------------------- ### Setting Up py-libp2p Development Environment on Linux with venv (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst These commands set up the `py-libp2p` development environment on Linux using Python's built-in `venv`. It navigates into the project directory, creates and activates a virtual environment, installs project dependencies in editable mode, and sets up pre-commit hooks for code style enforcement. ```sh cd py-libp2p python3 -m venv ./venv . venv/bin/activate python3 -m pip install -e ".[dev]" pre-commit install ``` -------------------------------- ### Connecting to Identify Host and Receiving Peer Info (Console) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.identify.rst This snippet shows the console command to run the `identify-demo` script as a dialer, connecting to the previously started host. It displays the output of the identify protocol exchange, including the peer's public key, listen addresses, supported protocols, and agent version. ```console $ identify-demo -p 8889 -d /ip4/0.0.0.0/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM dialer (host_b) listening on /ip4/0.0.0.0/tcp/8889 Second host connecting to peer: QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM Starting identify protocol... Identify response: Public Key (Base64): CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDC6c/oNPP9X13NDQ3Xrlp3zOj+ErXIWb/A4JGwWchiDBwMhMslEX3ct8CqI0BqUYKuwdFjowqqopOJ3cS2MlqtGaiP6Dg9bvGqSDoD37BpNaRVNcebRxtB0nam9SQy3PYLbHAmz0vR4ToSiL9OLRORnGOxCtHBuR8ZZ5vS0JEni8eQMpNa7IuXwyStnuty/QjugOZudBNgYSr8+9gH722KTjput5IRL7BrpIdd4HNXGVRm4b9BjNowvHu404x3a/ifeNblpy/FbYyFJEW0looygKF7hpRHhRbRKIDZt2BqOfT1sFkbqsHE85oY859+VMzP61YELgvGwai2r7KcjkW/AgMBAAE= Listen Addresses: ['/ip4/0.0.0.0/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM'] Protocols: ['/ipfs/id/1.0.0', '/ipfs/ping/1.0.0'] Observed Address: ['/ip4/127.0.0.1/tcp/38082'] Protocol Version: ipfs/0.1.0 Agent Version: py-libp2p/0.2.0 ``` -------------------------------- ### Starting Identify-Push Listener Process (Console) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.identify_push.rst This snippet initiates the interactive `identify-push-listener-dialer-demo` in listener mode. It displays the listener host's readiness, its listening address, and provides the command required to run the corresponding dialer process in a separate terminal. ```Console $ identify-push-listener-dialer-demo ==== Starting Identify-Push Listener on port 8888 ==== Listener host ready! Listening on: /ip4/0.0.0.0/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM Peer ID: QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM Run dialer with command: identify-push-listener-dialer-demo -d /ip4/0.0.0.0/tcp/8888/p2p/QmUiN4R3fNrCoQugGgmmb3v35neMEjKFNrsbNGVDsRHWpM Waiting for incoming connections... (Ctrl+C to exit) ``` -------------------------------- ### Configuring Custom Log File Paths Source: https://github.com/libp2p/py-libp2p/blob/main/docs/getting_started.rst This section provides methods to specify a custom log file location for py-libp2p by setting the LIBP2P_DEBUG_FILE environment variable. It covers both persistent settings for a shell session and temporary settings for a single command execution, demonstrating usage across Unix-like systems and Windows. ```bash export LIBP2P_DEBUG_FILE=/path/to/your/logfile.log ``` ```cmd set LIBP2P_DEBUG_FILE=C:\path\to\your\logfile.log ``` ```powershell $env:LIBP2P_DEBUG_FILE="C:\path\to\your\logfile.log" ``` ```bash LIBP2P_DEBUG=DEBUG LIBP2P_DEBUG_FILE=/path/to/your/logfile.log python your_script.py ``` ```cmd set LIBP2P_DEBUG=DEBUG && set LIBP2P_DEBUG_FILE=C:\path\to\your\logfile.log && python your_script.py ``` ```powershell $env:LIBP2P_DEBUG="DEBUG"; $env:LIBP2P_DEBUG_FILE="C:\path\to\your\logfile.log"; python your_script.py ``` -------------------------------- ### Installing Linux Development Prerequisites (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command installs essential development dependencies on Debian-based Linux systems using `apt-get`. It includes `cmake` for build configuration, `pkg-config` for managing compile/link flags, and `libgmp-dev` for the GNU Multiprecision Arithmetic Library. ```sh sudo apt-get install cmake pkg-config libgmp-dev ``` -------------------------------- ### Installing py-libp2p Development Dependencies on Windows (PowerShell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command installs the `py-libp2p` project and its development dependencies within the active virtual environment. The `-e` flag installs the package in editable mode, allowing changes to the source code to be reflected without reinstallation. ```powershell pip install -e ".[dev]" ``` -------------------------------- ### Setting Up py-libp2p Development Environment on macOS with venv (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst These commands set up the `py-libp2p` development environment on macOS using Python's built-in `venv`. It navigates into the project directory, creates and activates a virtual environment, installs project dependencies in editable mode, and sets up pre-commit hooks for code style enforcement. ```sh cd py-libp2p python3 -m venv ./venv . venv/bin/activate python3 -m pip install -e ".[dev]" pre-commit install ``` -------------------------------- ### Installing macOS Development Prerequisites (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command installs essential development dependencies on macOS using Homebrew. It includes `cmake` for build configuration, `pkgconfig` for managing compile/link flags, and `gmp` for the GNU Multiprecision Arithmetic Library. ```sh brew install cmake pkgconfig gmp ``` -------------------------------- ### Sending Ping Request (Console) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.ping.rst This snippet shows how to run the `ping-demo` application as a client, connecting to a previously started ping server. It sends a ping request to the specified multiaddress and displays the received pong response from the peer, confirming successful communication. ```console $ ping-demo -p 8001 -d /ip4/127.0.0.1/tcp/8000/p2p/QmXfptdHU6hqG95JswxYVUH4bphcK8y18mhFcgUQFe6fCN sending ping to QmXfptdHU6hqG95JswxYVUH4bphcK8y18mhFcgUQFe6fCN received pong from QmXfptdHU6hqG95JswxYVUH4bphcK8y18mhFcgUQFe6fCN ``` -------------------------------- ### Verifying Python Installation on Windows (PowerShell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command checks the installed Python version on Windows. It's used to confirm that Python 3.11+ is correctly installed and accessible from the PowerShell environment, which is a prerequisite for `py-libp2p` development. ```powershell python --version ``` -------------------------------- ### Running All py-libp2p Tests (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command executes the entire test suite for the `py-libp2p` project. It's a common way to verify the codebase's integrity and ensure that all components are working as expected after setup or changes. ```sh make test ``` -------------------------------- ### Installing py-libp2p Dependencies with GMP Linking on macOS (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command installs `py-libp2p` development dependencies on macOS, specifically ensuring that the build process correctly links against the `gmp` library. It sets `CFLAGS` and `LDFLAGS` environment variables using `pkg-config` to provide the necessary compiler and linker flags for GMP. ```sh CFLAGS="`pkg-config --cflags gmp`" LDFLAGS="`pkg-config --libs gmp`" python3 -m pip install -e ".[dev]" ``` -------------------------------- ### Creating Virtual Environment on Windows (PowerShell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst These commands create a Python virtual environment named `venv` and then activate it. Using a virtual environment isolates project dependencies from the system-wide Python installation, preventing conflicts. ```powershell python -m venv venv .\venv\Scripts\activate ``` -------------------------------- ### Connecting a Second PubSub Chat Node (Console) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.pubsub.rst This snippet illustrates how to launch a second instance of the PubSub chat application and connect it to an already running peer using its multiaddress. The console output confirms the connection, demonstrating how new nodes join the decentralized chat network. ```console $ pubsub-demo -d /ip4/127.0.0.1/tcp/33269/p2p/QmcJnocH1d1tz3Zp4MotVDjNfNFawXHw2dpB9tMYGTXJp7 2025-04-07 00:00:59,845 - pubsub-demo - INFO - Running pubsub chat example... 2025-04-07 00:00:59,846 - pubsub-demo - INFO - Your selected topic is: pubsub-chat 2025-04-07 00:00:59,846 - pubsub-demo - INFO - Using random available port: 51977 2025-04-07 00:00:59,864 - pubsub-demo - INFO - Node started with peer ID: QmYQKCm95Ut1aXsjHmWVYqdaVbno1eKTYC8KbEVjqUaKaQ 2025-04-07 00:00:59,864 - pubsub-demo - INFO - Listening on: /ip4/0.0.0.0/tcp/51977 2025-04-07 00:00:59,864 - pubsub-demo - INFO - Initializing PubSub and GossipSub... 2025-04-07 00:00:59,864 - pubsub-demo - INFO - Pubsub and GossipSub services started. 2025-04-07 00:00:59,865 - pubsub-demo - INFO - Pubsub ready. 2025-04-07 00:00:59,865 - pubsub-demo - INFO - Subscribed to topic: pubsub-chat 2025-04-07 00:00:59,866 - pubsub-demo - INFO - Connecting to peer: QmcJnocH1d1tz3Zp4MotVDjNfNFawXHw2dpB9tMYGTXJp7 using protocols: MultiAddrKeys() 2025-04-07 00:00:59,866 - pubsub-demo - INFO - Run this script in another console with: pubsub-demo -d /ip4/127.0.0.1/tcp/51977/p2p/QmYQKCm95Ut1aXsjHmWVYqdaVbno1eKTYC8KbEVjqUaKaQ 2025-04-07 00:00:59,881 - pubsub-demo - INFO - Connected to peer: QmcJnocH1d1tz3Zp4MotVDjNfNFawXHw2dpB9tMYGTXJp7 Type messages to send (press Enter to send): ``` -------------------------------- ### Cloning py-libp2p Repository on Windows (PowerShell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst These commands clone the `py-libp2p` repository from GitHub to your local machine and then navigate into the newly cloned directory. This is the initial step for setting up the development environment on Windows. ```powershell git clone git@github.com:your-github-username/py-libp2p.git cd py-libp2p ``` -------------------------------- ### Preparing for Release and Running Package Tests (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command sequence ensures the `main` branch is up-to-date and then initiates a package test. It's a crucial step before a release to verify the integrity and functionality of the package that will be published. ```sh git checkout main && git pull make package-test ``` -------------------------------- ### Transitioning from Beta to Stable Release (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command is used when the current project version is in a beta stage. Executing it will transition the project to a stable release, automating the version bump process. ```Shell make release bump=stage ``` -------------------------------- ### Executing Full Release Process (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command automates the entire release process. It bumps the version, creates a git commit and tag, builds the package, pushes changes to GitHub, and uploads the new package to PyPI, using the specified version part for the bump. ```sh make release bump=$$VERSION_PART_TO_BUMP$$ ``` -------------------------------- ### Cloning py-libp2p Repository (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command clones the `py-libp2p` repository from GitHub to your local machine. Replace `your-github-username` with your actual GitHub username after forking the repository. This is the initial step to set up the development environment. ```sh git clone git@github.com:your-github-username/py-libp2p.git ``` -------------------------------- ### Connecting to libp2p Chat Demo (Second Instance) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/examples.chat.rst This snippet illustrates how to connect a second instance of the `libp2p` chat demo to an already running instance. It uses the provided multiaddress to establish a peer-to-peer connection, enabling message exchange between the two terminals. ```console $ chat-demo -p 8001 -d /ip4/127.0.0.1/tcp/8000/p2p/QmPouApKqyxJDy6YT21EXNS6efuNzvJ3W3kqRQxkQ77GFJ Connected to peer /ip4/127.0.0.1/tcp/8000 ``` -------------------------------- ### Running py-libp2p Tests on Windows with pytest (PowerShell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command executes the `py-libp2p` test suite using `pytest` with verbose output. Running tests is a crucial step to verify that the development environment is correctly set up and all dependencies are functioning as expected. ```powershell pytest -v ``` -------------------------------- ### Building Release Notes with Version Bump (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command builds the final release notes, incorporating the specified version part to be bumped (e.g., `major`, `minor`, `patch`). It's executed before the version number is officially updated and ensures the release notes reflect the correct versioning. ```sh make notes bump=$$VERSION_PART_TO_BUMP$$ ``` -------------------------------- ### Running py-libp2p Tests on Windows with make (Git Bash) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command executes the `py-libp2p` test suite using `make` when operating within a Git Bash environment on Windows. It provides an alternative way to run tests, often encapsulating `pytest` or other test runners. ```bash make test ``` -------------------------------- ### Previewing Release Notes with Towncrier (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command uses the `towncrier` tool to generate a draft of the release notes. It allows developers to review the upcoming release notes based on news fragments before finalizing the release. ```sh towncrier --draft ``` -------------------------------- ### Running py-libp2p Code Linting (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command triggers the code linting process for the `py-libp2p` project, typically using `pre-commit` hooks. It helps enforce consistent code style and identify potential issues, ensuring code quality before commits. ```sh make lint ``` -------------------------------- ### Previewing Version Bump Result (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst This command allows users to see what the result of a version bump operation would be without actually applying the change. It's useful for verifying the next version number based on current settings. ```Shell bump-my-version show-bump ``` -------------------------------- ### Issuing a Specific Unstable Version (Shell) Source: https://github.com/libp2p/py-libp2p/blob/main/docs/contributing.rst When the current project version is stable, this command allows explicitly setting a new unstable version (e.g., alpha or beta). It requires specifying the full new version string as an argument. ```Shell make release bump="--new-version 4.0.0-alpha.1" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.