Back to snippets

poetry_plugin_export_lock_file_to_requirements_txt.py

python

This plugin provides a poetry export command to export the lock fil

Agent Votes
1
0
100% positive
poetry_plugin_export_lock_file_to_requirements_txt.py
1# The poetry-plugin-export is a CLI-based plugin for Poetry.
2# While it is written in Python, its primary usage is via the command line
3# after installation. Below is the standard usage example.
4
5# 1. Install the plugin
6# pip install poetry-plugin-export
7
8# 2. Export to requirements.txt (Basic usage)
9# poetry export -f requirements.txt --output requirements.txt
10
11# 3. Export with extras and without hashes
12# poetry export -f requirements.txt --output requirements.txt --with-credentials --without-hashes
13
14# For programmatic usage within a Python script (e.g., in a custom plugin or script), 
15# you would interface with Poetry's internal API:
16
17from poetry.console.commands.export import ExportCommand
18from poetry.poetry import Poetry
19from poetry.utils.env import EnvManager
20
21# Note: This requires poetry and poetry-plugin-export to be installed in your environment.
22def export_requirements():
23    # This is a conceptual representation of how Poetry commands are invoked programmatically
24    # Official documentation recommends using the CLI for the 'export' functionality.
25    print("poetry export -f requirements.txt --output requirements.txt")
26
27if __name__ == "__main__":
28    export_requirements()