From 77fd16f6a6a3a2b809166c347634b9d359fbca06 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Fri, 12 Aug 2022 08:33:18 +0200 Subject: [PATCH 01/12] Add pyproject.toml to intro --- README.rst | 82 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/README.rst b/README.rst index 833f779dc..c06e6d889 100644 --- a/README.rst +++ b/README.rst @@ -50,7 +50,8 @@ Example usage for ``pip-compile`` ================================= The ``pip-compile`` command lets you compile a ``requirements.txt`` file from -your dependencies, specified in either ``setup.py`` or ``requirements.in``. +your dependencies, specified in either ``pyproject.toml``, ``setup.cfg``, +``setup.py``, or ``requirements.in``. Run it with ``pip-compile`` or ``python -m piptools compile``. If you use multiple Python versions, you can also run ``py -X.Y -m piptools compile`` on @@ -67,39 +68,62 @@ available. To compile from scratch, first delete the existing ``requirements.txt`` file, or see `Updating requirements`_ for alternative approaches. -Requirements from ``setup.py`` ------------------------------- +Requirements from ``pyproject.toml`` +------------------------------------ -Suppose you have a Django project, and want to pin it for production. -If you have a ``setup.py`` with ``install_requires=['django']``, then run -``pip-compile`` without any arguments: +The ``pyproject.toml`` file is the +`latest standard `_ for configuring +packages and applications and recommended for new projects. ``pip-compile`` +supports both installing your ``project.dependencies`` as well as your +``project.optional-dependencies``. Thanks to the fact that this is an +official standard, you can use ``pip-compile`` to pin your dependencies +for projects based on modern standards-adhering packaging tools like +`Hatch `_ or `flit `_. + +Suppose you have a Django project that is packaged using ``Hatch``, and you +want to pin it for production. You also want to pin your development tools +into a separate pin file. You declare ``django`` as a dependency and create an +optional dependency ``dev`` that includes ``pytest``: + +.. code-block:: toml + + [build-system] + requires = ["hatchling"] + build-backend = "hatchling.build" + + [project] + name = "my-cool-django-app" + version = "42" + dependencies = ["django"] + + [project.optional-dependencies] + dev = ["pytest"] + +You can produce your pin files as easily as: .. code-block:: bash - $ pip-compile - # - # This file is autogenerated by pip-compile - # To update, run: - # - # pip-compile - # - asgiref==3.2.3 - # via django - django==3.0.3 - # via my_django_project (setup.py) - pytz==2019.3 - # via django - sqlparse==0.3.0 - # via django + $ pip-compile -o requirements.txt pyproject.toml + $ pip-compile --extra dev -o dev-requirements.txt pyproject.toml + +This is great for both pinning your applications, but also to keep the CI +of your open-source Python package stable. + +Requirements from ``setup.py`` and ``setup.cfg`` +------------------------------------------------ -``pip-compile`` will produce your ``requirements.txt``, with all the Django -dependencies (and all underlying dependencies) pinned. +``pip-compile`` has also full support for ``setup.py``- and +``setup.cfg``-based projects that drive setuptools. -Without ``setup.py`` --------------------- +Just define your dependencies and extras as usual and run +``pip-compile`` as above. -If you don't use ``setup.py`` (`it's easy to write one`_), you can create a -``requirements.in`` file to declare the Django dependency: +``requirements.in`` +------------------- + +You can also use plain text files for your requirements (e.g. if you don't +want your application to be a package). To use a ``requirements.in`` file to +declare the Django dependency: .. code-block:: ini @@ -129,15 +153,13 @@ Now, run ``pip-compile requirements.in``: And it will produce your ``requirements.txt``, with all the Django dependencies (and all underlying dependencies) pinned. -.. _it's easy to write one: https://packaging.python.org/guides/distributing-packages-using-setuptools/#configuring-your-project - .. _Updating requirements: Updating requirements --------------------- ``pip-compile`` generates a ``requirements.txt`` file using the latest versions -that fulfil the dependencies of ``setup.py`` or ``requirements.in``. +that fulfil the dependencies you specify in the supported files. If ``pip-compile`` finds an existing ``requirements.txt`` file that fulfils the dependencies then no changes will be made, even if updates are available. From b64f1c54ae5d01d60403729b1fec55b4cefbdcdf Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Aug 2022 11:41:01 +0200 Subject: [PATCH 02/12] Update README.rst Co-authored-by: Sviatoslav Sydorenko --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index c06e6d889..4266caeac 100644 --- a/README.rst +++ b/README.rst @@ -73,7 +73,7 @@ Requirements from ``pyproject.toml`` The ``pyproject.toml`` file is the `latest standard `_ for configuring -packages and applications and recommended for new projects. ``pip-compile`` +packages and applications, and is recommended for new projects. ``pip-compile`` supports both installing your ``project.dependencies`` as well as your ``project.optional-dependencies``. Thanks to the fact that this is an official standard, you can use ``pip-compile`` to pin your dependencies From 69e12893f4b637f789de17a55b0594cd4ee73eef Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Aug 2022 11:41:12 +0200 Subject: [PATCH 03/12] Update README.rst Co-authored-by: Sviatoslav Sydorenko --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 4266caeac..d6b87a866 100644 --- a/README.rst +++ b/README.rst @@ -76,8 +76,8 @@ The ``pyproject.toml`` file is the packages and applications, and is recommended for new projects. ``pip-compile`` supports both installing your ``project.dependencies`` as well as your ``project.optional-dependencies``. Thanks to the fact that this is an -official standard, you can use ``pip-compile`` to pin your dependencies -for projects based on modern standards-adhering packaging tools like +official standard, you can use ``pip-compile`` to pin the dependencies +in projects that use modern standards-adhering packaging tools like `Hatch `_ or `flit `_. Suppose you have a Django project that is packaged using ``Hatch``, and you From c013adad01acbc6d16a4f299a9fe22e78057a1b8 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Aug 2022 11:41:28 +0200 Subject: [PATCH 04/12] Update README.rst Co-authored-by: Sviatoslav Sydorenko --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index d6b87a866..e91f49dff 100644 --- a/README.rst +++ b/README.rst @@ -80,7 +80,7 @@ official standard, you can use ``pip-compile`` to pin the dependencies in projects that use modern standards-adhering packaging tools like `Hatch `_ or `flit `_. -Suppose you have a Django project that is packaged using ``Hatch``, and you +Suppose you have a Django application that is packaged using ``Hatch``, and you want to pin it for production. You also want to pin your development tools into a separate pin file. You declare ``django`` as a dependency and create an optional dependency ``dev`` that includes ``pytest``: From 8190222ba2bd4e16dcaaf86ff09589d5ca3d6ddd Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Aug 2022 11:41:41 +0200 Subject: [PATCH 05/12] Update README.rst Co-authored-by: Sviatoslav Sydorenko --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index e91f49dff..90f38fde1 100644 --- a/README.rst +++ b/README.rst @@ -82,7 +82,7 @@ in projects that use modern standards-adhering packaging tools like Suppose you have a Django application that is packaged using ``Hatch``, and you want to pin it for production. You also want to pin your development tools -into a separate pin file. You declare ``django`` as a dependency and create an +in a separate pin file. You declare ``django`` as a dependency and create an optional dependency ``dev`` that includes ``pytest``: .. code-block:: toml From 861d6259ab14f33f7549a7e46a64292a76c3491a Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Aug 2022 11:41:56 +0200 Subject: [PATCH 06/12] Update README.rst Co-authored-by: Sviatoslav Sydorenko --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 90f38fde1..93a96cd65 100644 --- a/README.rst +++ b/README.rst @@ -101,7 +101,7 @@ optional dependency ``dev`` that includes ``pytest``: You can produce your pin files as easily as: -.. code-block:: bash +.. code-block:: console $ pip-compile -o requirements.txt pyproject.toml $ pip-compile --extra dev -o dev-requirements.txt pyproject.toml From 442e9af2bcb8622eadb8df3cc0b1d89450c8e85c Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Aug 2022 11:42:25 +0200 Subject: [PATCH 07/12] Update README.rst Co-authored-by: Sviatoslav Sydorenko --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 93a96cd65..e5d65a006 100644 --- a/README.rst +++ b/README.rst @@ -113,7 +113,7 @@ Requirements from ``setup.py`` and ``setup.cfg`` ------------------------------------------------ ``pip-compile`` has also full support for ``setup.py``- and -``setup.cfg``-based projects that drive setuptools. +``setup.cfg``-based projects that use ``setuptools``. Just define your dependencies and extras as usual and run ``pip-compile`` as above. From e0a40e2dc29e21e3f41b12dcc31758e53b33d781 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Aug 2022 11:52:00 +0200 Subject: [PATCH 08/12] Update README.rst --- README.rst | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.rst b/README.rst index e5d65a006..ef27883d0 100644 --- a/README.rst +++ b/README.rst @@ -104,7 +104,50 @@ You can produce your pin files as easily as: .. code-block:: console $ pip-compile -o requirements.txt pyproject.toml + # + # This file is autogenerated by pip-compile with python 3.10 + # To update, run: + # + # pip-compile --output-file=requirements.txt pyproject.toml + # + + asgiref==3.5.2 + # via django + django==4.1 + # via my-cool-django-app (pyproject.toml) + sqlparse==0.4.2 + # via django $ pip-compile --extra dev -o dev-requirements.txt pyproject.toml + # + # This file is autogenerated by pip-compile with python 3.10 + # To update, run: + # + # pip-compile --extra=dev --output-file=dev-requirements.txt pyproject.toml + # + --index-url https://pypi.vm.ag/root/vrmd/+simple/ + + asgiref==3.5.2 + # via django + attrs==22.1.0 + # via pytest + django==4.1 + # via my-cool-django-app (pyproject.toml) + iniconfig==1.1.1 + # via pytest + packaging==21.3 + # via pytest + pluggy==1.0.0 + # via pytest + py==1.11.0 + # via pytest + pyparsing==3.0.9 + # via packaging + pytest==7.1.2 + # via my-cool-django-app (pyproject.toml) + sqlparse==0.4.2 + # via django + tomli==2.0.1 + # via pytest This is great for both pinning your applications, but also to keep the CI of your open-source Python package stable. From 97a638082fd6004b644ef4a844b69cde836b69f9 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Aug 2022 11:52:30 +0200 Subject: [PATCH 09/12] Update README.rst --- README.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/README.rst b/README.rst index ef27883d0..41853efd0 100644 --- a/README.rst +++ b/README.rst @@ -124,7 +124,6 @@ You can produce your pin files as easily as: # # pip-compile --extra=dev --output-file=dev-requirements.txt pyproject.toml # - --index-url https://pypi.vm.ag/root/vrmd/+simple/ asgiref==3.5.2 # via django From fd7e7f22644d9ffc509918dc0a3f6adedcf82c9e Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Aug 2022 11:53:03 +0200 Subject: [PATCH 10/12] Update README.rst --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 41853efd0..d2909b4f4 100644 --- a/README.rst +++ b/README.rst @@ -117,6 +117,7 @@ You can produce your pin files as easily as: # via my-cool-django-app (pyproject.toml) sqlparse==0.4.2 # via django + $ pip-compile --extra dev -o dev-requirements.txt pyproject.toml # # This file is autogenerated by pip-compile with python 3.10 From 66e5be58fc20b30470e84886f51f5cd230ab89eb Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Aug 2022 12:21:16 +0200 Subject: [PATCH 11/12] Update README.rst Co-authored-by: Albert Tugushev --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index d2909b4f4..3aabfed66 100644 --- a/README.rst +++ b/README.rst @@ -161,8 +161,8 @@ Requirements from ``setup.py`` and ``setup.cfg`` Just define your dependencies and extras as usual and run ``pip-compile`` as above. -``requirements.in`` -------------------- +Requirements from ``requirements.in`` +------------------------------------- You can also use plain text files for your requirements (e.g. if you don't want your application to be a package). To use a ``requirements.in`` file to From 5b7d68bb8ec221e9769eb693ed944dae759e2a6b Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Aug 2022 12:41:25 +0200 Subject: [PATCH 12/12] Update compile.py --- piptools/scripts/compile.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 28e16abf2..9424968ac 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -287,7 +287,10 @@ def cli( emit_options: bool, unsafe_package: Tuple[str, ...], ) -> None: - """Compiles requirements.txt from requirements.in specs.""" + """ + Compiles requirements.txt from requirements.in, pyproject.toml, setup.cfg, + or setup.py specs. + """ log.verbosity = verbose - quiet if len(src_files) == 0: