From 003603cb98778602d68262e234cfb3371d1ced1b Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 5 Dec 2022 14:53:05 +0100 Subject: [PATCH 1/3] pip: Add support for pyproject.toml --- pip/flatpak-pip-generator | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pip/flatpak-pip-generator b/pip/flatpak-pip-generator index ba4ca75d..eb3b8599 100755 --- a/pip/flatpak-pip-generator +++ b/pip/flatpak-pip-generator @@ -28,6 +28,8 @@ parser.add_argument('--cleanup', choices=['scripts', 'all'], help='Select what to clean up after build') parser.add_argument('--requirements-file', '-r', help='Specify requirements.txt file') +parser.add_argument('--pyproject-file', + help='Specify pyproject.toml file') parser.add_argument('--build-only', action='store_const', dest='cleanup', const='all', help='Clean up all files after build') @@ -48,6 +50,15 @@ parser.add_argument('--yaml', action='store_true', help='Use YAML as output format instead of JSON') opts = parser.parse_args() +if opts.pyproject_file: + try: + from tomllib import load as toml_load + except ModuleNotFoundError: + try: + from tomli import load as toml_load + except ModuleNotFoundError: + exit('tomli modules is not installed. Run "pip install tomli"') + if opts.yaml: try: import yaml @@ -158,6 +169,16 @@ if opts.requirements_file: except FileNotFoundError: pass +elif opts.pyproject_file: + pyproject_file = os.path.expanduser(opts.pyproject_file) + with open(pyproject_file, "rb") as f: + pyproject_data = toml_load(f) + dependencies = pyproject_data.get("project", {}).get("dependencies", []) + packages = list(requirements.parse('\n'.join(dependencies))) + with tempfile.NamedTemporaryFile('w', delete=False, prefix='requirements.') as req_file: + req_file.write('\n'.join(dependencies)) + requirements_file = req_file.name + elif opts.packages: packages = list(requirements.parse('\n'.join(opts.packages))) with tempfile.NamedTemporaryFile('w', delete=False, prefix='requirements.') as req_file: From d3c2cb85b3b775aaed8838378c319b5f0f85e676 Mon Sep 17 00:00:00 2001 From: JakobDev Date: Mon, 5 Dec 2022 14:53:05 +0100 Subject: [PATCH 2/3] pip: Add support for pyproject.toml --- pip/flatpak-pip-generator | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pip/flatpak-pip-generator b/pip/flatpak-pip-generator index 2dfc6e55..2f0f427f 100755 --- a/pip/flatpak-pip-generator +++ b/pip/flatpak-pip-generator @@ -28,6 +28,8 @@ parser.add_argument('--cleanup', choices=['scripts', 'all'], help='Select what to clean up after build') parser.add_argument('--requirements-file', '-r', help='Specify requirements.txt file') +parser.add_argument('--pyproject-file', + help='Specify pyproject.toml file') parser.add_argument('--build-only', action='store_const', dest='cleanup', const='all', help='Clean up all files after build') @@ -57,6 +59,15 @@ parser.add_argument('--ignore-errors', action='store_true', help='Ignore errors when downloading packages') opts = parser.parse_args() +if opts.pyproject_file: + try: + from tomllib import load as toml_load + except ModuleNotFoundError: + try: + from tomli import load as toml_load + except ModuleNotFoundError: + exit('tomli modules is not installed. Run "pip install tomli"') + if opts.yaml: try: import yaml @@ -167,6 +178,16 @@ if opts.requirements_file: except FileNotFoundError: pass +elif opts.pyproject_file: + pyproject_file = os.path.expanduser(opts.pyproject_file) + with open(pyproject_file, "rb") as f: + pyproject_data = toml_load(f) + dependencies = pyproject_data.get("project", {}).get("dependencies", []) + packages = list(requirements.parse('\n'.join(dependencies))) + with tempfile.NamedTemporaryFile('w', delete=False, prefix='requirements.') as req_file: + req_file.write('\n'.join(dependencies)) + requirements_file = req_file.name + elif opts.packages: packages = list(requirements.parse('\n'.join(opts.packages))) with tempfile.NamedTemporaryFile('w', delete=False, prefix='requirements.') as req_file: From 9f7a089a8371ff835ed2d670b5330262d1998230 Mon Sep 17 00:00:00 2001 From: ENDrain Date: Wed, 14 Jun 2023 22:46:17 +0300 Subject: [PATCH 3/3] pip: Add support for pyproject.toml Added: error thorwn if both --requirements-file and --pyproject-file are present Added: readme entry for --pyproject-file Fixed: readme entry for --requirements-file now warns about mutual exclusivity with --pyproject-file --- pip/flatpak-pip-generator | 3 +++ pip/readme.md | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pip/flatpak-pip-generator b/pip/flatpak-pip-generator index 2f0f427f..3f99faea 100755 --- a/pip/flatpak-pip-generator +++ b/pip/flatpak-pip-generator @@ -59,6 +59,9 @@ parser.add_argument('--ignore-errors', action='store_true', help='Ignore errors when downloading packages') opts = parser.parse_args() +if opts.requirements_file and opts.pyproject_file: + exit('Can\'t use both requirements and pyproject files at the same time') + if opts.pyproject_file: try: from tomllib import load as toml_load diff --git a/pip/readme.md b/pip/readme.md index ec253224..9f2f3a95 100644 --- a/pip/readme.md +++ b/pip/readme.md @@ -43,7 +43,8 @@ You can use that in your manifest like * `--python2`: Build with Python 2. Note that you will have to build [the Python 2 shared-module](https://github.com/flathub/shared-modules/tree/master/python2.7) as it is not in any runtime. * `--cleanup=(scripts|all)`: Add `cleanup` to the manifest. This is used when the packages installed are only used at build time. * `--build-only`: Alias to `--cleanup=all`. -* `--requirements-file=`, `-r`: Reads the list of packages from `requirements.txt` file. +* `--requirements-file=`, `-r`: Reads the list of packages from `requirements.txt` file. Mutually exclusive with `--pyproject-file`. +* `--pyproject-file=`: Reads the list of packages from `pyproject.toml` file. Mutually exclusive with `--requirements-file` or `r`. * `--checker-data`: This adds `x-checker-data` to modules so you will be notified when new releases happen. See [flatpak-external-data-checker](https://github.com/flathub/flatpak-external-data-checker) for more details. * `--runtime=`: Runs `pip` inside of a specific Flatpak runtime instead of on your host. Highly recommended for reproducability and portability. Examples would be `org.freedesktop.Sdk//22.08` or `org.gnome.Sdk/aarch64/43`. * `--ignore-errors=`: Allow the generation of empty or otherwise broken files when downloading packages fails.