Skip to content

Commit b4db7f8

Browse files
authored
Package/PublishOnPyPI: choose source distribution and wheel separately (#319)
2 parents a4830d6 + a0f29bf commit b4db7f8

6 files changed

Lines changed: 213 additions & 20 deletions

File tree

‎.github/workflows/CompletePipeline.yml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ on:
177177
required: false
178178
default: 'true'
179179
type: string
180+
package_sdist:
181+
description: "If 'true', build a source distribution (*.tar.gz)."
182+
required: false
183+
default: 'true'
184+
type: string
185+
package_wheel:
186+
description: "If 'true', build a wheel (*.whl)."
187+
required: false
188+
default: 'true'
189+
type: string
180190
pypi_url:
181191
description: 'Base URL of the package registry, which is checked for an existing release.'
182192
required: false
@@ -192,6 +202,16 @@ on:
192202
required: false
193203
default: 'false'
194204
type: string
205+
pypi_publish_sdist:
206+
description: "If 'true', publish the source distribution (*.tar.gz). Default changes to 'false' with @r10."
207+
required: false
208+
default: 'true'
209+
type: string
210+
pypi_publish_wheel:
211+
description: "If 'true', publish the wheel (*.whl)."
212+
required: false
213+
default: 'true'
214+
type: string
195215
cleanup:
196216
description: 'Cleanup artifacts afterwards.'
197217
required: false
@@ -334,6 +354,8 @@ jobs:
334354
with:
335355
python_version: ${{ needs.UnitTestingParams.outputs.python_version }}
336356
artifact: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).package_all }}
357+
package_sdist: ${{ inputs.package_sdist }}
358+
package_wheel: ${{ inputs.package_wheel }}
337359

338360
Install:
339361
uses: pyTooling/Actions/.github/workflows/InstallPackage.yml@dev
@@ -556,6 +578,8 @@ jobs:
556578
dry_run: ${{ inputs.pypi_dry_run }}
557579
pypi_upload_url: ${{ inputs.pypi_upload_url }}
558580
pypi_compliant: ${{ needs.Package.outputs.pypi_compliant }}
581+
publish_sdist: ${{ inputs.pypi_publish_sdist }}
582+
publish_wheel: ${{ inputs.pypi_publish_wheel }}
559583
cleanup: ${{ inputs.cleanup }}
560584
secrets:
561585
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

‎.github/workflows/Package.yml‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ on:
4444
description: 'Name of the package artifact.'
4545
required: true
4646
type: string
47+
package_sdist:
48+
description: "If 'true', build a source distribution (*.tar.gz)."
49+
required: false
50+
default: 'true'
51+
type: string
52+
package_wheel:
53+
description: "If 'true', build a wheel (*.whl)."
54+
required: false
55+
default: 'true'
56+
type: string
4757

4858
outputs:
4959
pypi_compliant:
@@ -78,11 +88,11 @@ jobs:
7888
run: python -m pip install --disable-pip-version-check build
7989

8090
- name: 🔨 [build] Build Python package (source distribution)
81-
if: inputs.requirements == ''
91+
if: inputs.requirements == '' && inputs.package_sdist == 'true'
8292
run: python -m build --sdist
8393

8494
- name: 🔨 [build] Build Python package (binary distribution - wheel)
85-
if: inputs.requirements == ''
95+
if: inputs.requirements == '' && inputs.package_wheel == 'true'
8696
run: python -m build --wheel
8797

8898
# build (not isolated)
@@ -92,11 +102,11 @@ jobs:
92102
run: python -m pip install --disable-pip-version-check build
93103

94104
- name: 🔨 [build - no-isolation] Build Python package (source distribution)
95-
if: inputs.requirements == 'no-isolation'
105+
if: inputs.requirements == 'no-isolation' && inputs.package_sdist == 'true'
96106
run: python -m build --no-isolation --sdist
97107

98108
- name: 🔨 [build - no-isolation] Build Python package (binary distribution - wheel)
99-
if: inputs.requirements == 'no-isolation'
109+
if: inputs.requirements == 'no-isolation' && inputs.package_wheel == 'true'
100110
run: python -m build --no-isolation --wheel
101111

102112
# setuptools
@@ -106,11 +116,11 @@ jobs:
106116
run: python -m pip install --disable-pip-version-check ${{ inputs.requirements }}
107117

108118
- name: 🔨 [setuptools] Build Python package (source distribution)
109-
if: inputs.requirements != '' && inputs.requirements != 'no-isolation'
119+
if: inputs.requirements != '' && inputs.requirements != 'no-isolation' && inputs.package_sdist == 'true'
110120
run: python setup.py sdist
111121

112122
- name: 🔨 [setuptools] Build Python package (binary distribution - wheel)
113-
if: inputs.requirements != '' && inputs.requirements != 'no-isolation'
123+
if: inputs.requirements != '' && inputs.requirements != 'no-isolation' && inputs.package_wheel == 'true'
114124
run: python setup.py bdist_wheel
115125

116126
- name: 🩺 Inspect packages for PyPI compliance

‎.github/workflows/PublishOnPyPI.yml‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ on:
6464
required: false
6565
default: 'true'
6666
type: string
67+
publish_sdist:
68+
description: "If 'true', publish the source distribution (*.tar.gz). Default changes to 'false' with @r10."
69+
required: false
70+
default: 'true'
71+
type: string
72+
publish_wheel:
73+
description: "If 'true', publish the wheel (*.whl)."
74+
required: false
75+
default: 'true'
76+
type: string
6777
secrets:
6878
PYPI_TOKEN:
6979
description: "Token for pushing releases to PyPI"
@@ -81,7 +91,7 @@ jobs:
8191
name: ${{ inputs.artifact }}
8292
path: dist
8393

84-
- name: 🔍 Check that the package is PyPI-compliant
94+
- name: 🕵️ Check that the package is PyPI-compliant
8595
if: inputs.pypi_compliant == 'false'
8696
run: |
8797
ANSI_LIGHT_RED=$'\x1b[91m'
@@ -107,19 +117,28 @@ jobs:
107117
- name: ⚙ Install dependencies for packaging and release
108118
run: python -m pip install --disable-pip-version-check ${{ inputs.requirements }}
109119

110-
- name: 🔎 Check Python packages instead of publishing them
111-
if: inputs.dry_run == 'true'
112-
run: twine check dist/*.whl dist/*.tar.gz
120+
- name: 🩺 Check Python wheel package instead of publishing it
121+
if: inputs.dry_run == 'true' && inputs.publish_wheel == 'true'
122+
run: twine check dist/*.whl
123+
124+
- name: 🩺 Check Python source package instead of publishing it
125+
if: inputs.dry_run == 'true' && inputs.publish_sdist == 'true'
126+
run: twine check dist/*.tar.gz
127+
128+
- name: ⚠ Nothing selected for publishing
129+
if: inputs.publish_wheel != 'true' && inputs.publish_sdist != 'true'
130+
run: |
131+
printf -- "::warning title=PublishOnPyPI::Nothing published or checked: 'publish_wheel' and 'publish_sdist' are both 'false'.\n"
113132
114133
- name: ⤴ Publish Python wheel package to PyPI
115-
if: inputs.dry_run != 'true'
134+
if: inputs.dry_run != 'true' && inputs.publish_wheel == 'true'
116135
env:
117136
TWINE_USERNAME: __token__
118137
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
119138
run: twine upload --repository-url "${{ inputs.pypi_upload_url }}" dist/*.whl
120139

121140
- name: ⤴ Publish Python source package to PyPI
122-
if: inputs.dry_run != 'true'
141+
if: inputs.dry_run != 'true' && inputs.publish_sdist == 'true'
123142
env:
124143
TWINE_USERNAME: __token__
125144
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

‎doc/JobTemplate/AllInOne/CompletePipeline.rst‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,10 @@ Parameter Summary
589589
+--------------------------------------------------------------------+----------+--------+----------------------------------------------------------------------------+
590590
| :ref:`JOBTMPL/CompletePipeline/Input/check_pypi_duplicate` | no | string | ``'true'`` |
591591
+--------------------------------------------------------------------+----------+--------+----------------------------------------------------------------------------+
592+
| :ref:`JOBTMPL/CompletePipeline/Input/package_sdist` | no | string | ``'true'`` |
593+
+--------------------------------------------------------------------+----------+--------+----------------------------------------------------------------------------+
594+
| :ref:`JOBTMPL/CompletePipeline/Input/package_wheel` | no | string | ``'true'`` |
595+
+--------------------------------------------------------------------+----------+--------+----------------------------------------------------------------------------+
592596
| :ref:`JOBTMPL/CompletePipeline/Input/pypi_url` | no | string | ``'https://pypi.org'`` |
593597
+--------------------------------------------------------------------+----------+--------+----------------------------------------------------------------------------+
594598
| :ref:`JOBTMPL/CompletePipeline/Input/apptest_python_version_list` | no | string | ``''`` |
@@ -615,6 +619,10 @@ Parameter Summary
615619
+--------------------------------------------------------------------+----------+--------+----------------------------------------------------------------------------+
616620
| :ref:`JOBTMPL/CompletePipeline/Input/pypi_dry_run` | no | string | ``'false'`` |
617621
+--------------------------------------------------------------------+----------+--------+----------------------------------------------------------------------------+
622+
| :ref:`JOBTMPL/CompletePipeline/Input/pypi_publish_sdist` | no | string | ``'true'`` |
623+
+--------------------------------------------------------------------+----------+--------+----------------------------------------------------------------------------+
624+
| :ref:`JOBTMPL/CompletePipeline/Input/pypi_publish_wheel` | no | string | ``'true'`` |
625+
+--------------------------------------------------------------------+----------+--------+----------------------------------------------------------------------------+
618626
| :ref:`JOBTMPL/CompletePipeline/Input/pypi_upload_url` | no | string | ``'https://upload.pypi.org/legacy/'`` |
619627
+--------------------------------------------------------------------+----------+--------+----------------------------------------------------------------------------+
620628
| :ref:`JOBTMPL/CompletePipeline/Input/cleanup` | no | string | ``'true'`` |
@@ -1186,6 +1194,32 @@ check_pypi_duplicate
11861194
``'false'`` - don't query PyPI, e.g. for a package that isn't published there.
11871195

11881196

1197+
.. _JOBTMPL/CompletePipeline/Input/package_sdist:
1198+
1199+
package_sdist
1200+
=============
1201+
1202+
:Type: string
1203+
:Required: no
1204+
:Default Value: ``'true'``
1205+
:Possible Values: ``'true'`` / ``'false'``
1206+
:Description: Build a source distribution (:file:`*.tar.gz`).
1207+
Forwarded to :ref:`JOBTMPL/Package/Input/package_sdist`.
1208+
1209+
1210+
.. _JOBTMPL/CompletePipeline/Input/package_wheel:
1211+
1212+
package_wheel
1213+
=============
1214+
1215+
:Type: string
1216+
:Required: no
1217+
:Default Value: ``'true'``
1218+
:Possible Values: ``'true'`` / ``'false'``
1219+
:Description: Build a wheel (:file:`*.whl`).
1220+
Forwarded to :ref:`JOBTMPL/Package/Input/package_wheel`.
1221+
1222+
11891223
.. _JOBTMPL/CompletePipeline/Input/pypi_url:
11901224

11911225
pypi_url
@@ -1219,6 +1253,36 @@ pypi_dry_run
12191253
``'false'`` - publish the packages; a package with direct references isn't tagged.
12201254

12211255

1256+
.. _JOBTMPL/CompletePipeline/Input/pypi_publish_sdist:
1257+
1258+
pypi_publish_sdist
1259+
==================
1260+
1261+
.. attention::
1262+
1263+
The default value will be changed to ``'false'`` in Actions ``@r10``.
1264+
1265+
:Type: string
1266+
:Required: no
1267+
:Default Value: ``'true'``
1268+
:Possible Values: ``'true'`` / ``'false'``
1269+
:Description: Publish the source distribution (:file:`*.tar.gz`) on a release tag.
1270+
Forwarded to :ref:`JOBTMPL/PublishOnPyPI/Input/publish_sdist`.
1271+
1272+
1273+
.. _JOBTMPL/CompletePipeline/Input/pypi_publish_wheel:
1274+
1275+
pypi_publish_wheel
1276+
==================
1277+
1278+
:Type: string
1279+
:Required: no
1280+
:Default Value: ``'true'``
1281+
:Possible Values: ``'true'`` / ``'false'``
1282+
:Description: Publish the wheel (:file:`*.whl`) on a release tag.
1283+
Forwarded to :ref:`JOBTMPL/PublishOnPyPI/Input/publish_wheel`.
1284+
1285+
12221286
.. _JOBTMPL/CompletePipeline/Input/pypi_upload_url:
12231287

12241288
pypi_upload_url

‎doc/JobTemplate/Package/Package.rst‎

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ as an artifact.
1212

1313
.. topic:: Features
1414

15-
* Package source code as wheel and source distribution.
15+
* Package source code as wheel and/or source distribution.
1616
* Support packaging using :term:`build` (recommended) or :pypi:`setuptools`.
1717
* Check the packages' metadata for direct references, which :term:`PyPI` rejects.
1818

@@ -29,13 +29,14 @@ as an artifact.
2929
* If parameter :ref:`JOBTMPL/Package/Input/requirements` is non-empty, use :pypi:`setuptools` for packaging and
3030
execute ``python setup.py ...``.
3131

32-
Both a source distribution and a wheel are built.
32+
A source distribution is built if :ref:`JOBTMPL/Package/Input/package_sdist` is ``'true'``, a wheel if
33+
:ref:`JOBTMPL/Package/Input/package_wheel` is ``'true'``; both are by default.
3334

34-
4. Check both packages' metadata (``Requires-Dist``) for direct references like
35+
4. Check the packages' metadata (``Requires-Dist``) for direct references like
3536
``name @ git+https://...``, which :term:`PyPI` rejects. Each reference is reported as a warning naming the
3637
requirement, its extras and the packages it appears in. The result is the output
3738
:ref:`JOBTMPL/Package/Output/pypi_compliant`.
38-
5. Upload both packages in a single artifact
39+
5. Upload the packages in a single artifact
3940
(:ref:`JOBTMPL/Package/Input/artifact`).
4041

4142
.. topic:: Job Execution
@@ -111,6 +112,10 @@ Parameter Summary
111112
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
112113
| :ref:`JOBTMPL/Package/Input/artifact` | yes | string | — — — — |
113114
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
115+
| :ref:`JOBTMPL/Package/Input/package_sdist` | no | string | ``'true'`` |
116+
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
117+
| :ref:`JOBTMPL/Package/Input/package_wheel` | no | string | ``'true'`` |
118+
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
114119

115120
.. rubric:: Goto :ref:`secrets <JOBTMPL/Package/Secrets>`
116121

@@ -169,6 +174,36 @@ artifact
169174
:Description: Name of the artifact containing the packaged Python code.
170175

171176

177+
.. _JOBTMPL/Package/Input/package_sdist:
178+
179+
package_sdist
180+
=============
181+
182+
:Type: string
183+
:Required: no
184+
:Default Value: ``'true'``
185+
:Possible Values: ``'true'`` / ``'false'``
186+
:Description: Build a source distribution (:file:`*.tar.gz`). |br|
187+
``'true'`` - the artifact contains the source distribution. |br|
188+
``'false'`` - no source distribution is built; :ref:`JOBTMPL/PublishOnPyPI/Input/publish_sdist` must
189+
be ``'false'`` too.
190+
191+
192+
.. _JOBTMPL/Package/Input/package_wheel:
193+
194+
package_wheel
195+
=============
196+
197+
:Type: string
198+
:Required: no
199+
:Default Value: ``'true'``
200+
:Possible Values: ``'true'`` / ``'false'``
201+
:Description: Build a wheel (:file:`*.whl`). |br|
202+
``'true'`` - the artifact contains the wheel. |br|
203+
``'false'`` - no wheel is built; :ref:`JOBTMPL/PublishOnPyPI/Input/publish_wheel` must be
204+
``'false'`` too, and jobs installing the wheel (e.g. :ref:`JOBTMPL/InstallPackage`) can't run.
205+
206+
172207
.. _JOBTMPL/Package/Secrets:
173208

174209
Secrets

0 commit comments

Comments
 (0)