#16 [F30] Fedora CI: Run mock on the current Fedora version (or 31 if less than 31)
Closed 4 years ago by churchyard. Opened 4 years ago by churchyard.
rpms/ churchyard/pyproject-rpm-macros native_ci  into  f30

file modified
+1 -1
@@ -108,7 +108,7 @@ 

      %check

      %tox

      %if %{with integration_test}

-     %tox -e % {default_toxenv}-integration

+     %tox -e %{default_toxenv}-integration

      %endif

  

  If you wish to provide custom `tox` flags or arguments, add them after `--`:

file modified
+1 -2
@@ -5,7 +5,7 @@ 

  

  

  %pyproject_install() %{expand:\\\

- %{__python3} -m pip install   --root %{buildroot}  --strip-file-prefix %{buildroot} --no-deps  --disable-pip-version-check --progress-bar off --verbose --ignore-installed --no-warn-script-location ./*.whl

+ %{__python3} -m pip install --root %{buildroot} --no-deps --disable-pip-version-check --progress-bar off --verbose --ignore-installed --no-warn-script-location ./*.whl

  if [ -d %{buildroot}%{_bindir} ]; then

    pathfix.py -pni "%{__python3} %{py3_shbang_opts}" %{buildroot}%{_bindir}/*

  fi
@@ -24,7 +24,6 @@ 

  %{-e:%{expand:%global toxenv %{-e*}}}

  echo 'python3-devel'

  echo 'python3dist(packaging)'

- echo 'python3dist(pip) >= 19'

  echo 'python3dist(pytoml)'

  # setuptools assumes no pre-existing dist-info

  rm -rfv *.dist-info/

file modified
+19 -5
@@ -6,7 +6,7 @@ 

  

  # Keep the version at zero and increment only release

  Version:        0

- Release:        5%{?dist}

+ Release:        6%{?dist}

  

  Source0:        macros.pyproject

  Source1:        pyproject_buildrequires.py
@@ -21,17 +21,28 @@ 

  

  BuildArch:      noarch

  

- # We keep them here for now to avoid one loop of %%generate_buildrequires

- # And to allow the other macros without %%pyproject_buildrequires (e.g. on Fedora 30)

- # But those are also always in the output of %%generate_buildrequires

- # in order to be removable in the future

  Requires: python3-pip >= 19

  Requires: python3-devel

  

+ # We keep these here for now to avoid one loop of %%generate_buildrequires

+ # But those are also always in the output of %%generate_buildrequires

+ # in order to be removable in the future

+ Requires: python3dist(packaging)

+ Requires: python3dist(pytoml)

+ 

+ # This is not output from %%generate_buildrequires to work around:

+ #   https://github.com/rpm-software-management/mock/issues/336

+ Requires: (python3dist(importlib-metadata) if python3 < 3.8)

+ 

  %if %{with tests}

  BuildRequires: python3dist(pytest)

  BuildRequires: python3dist(pyyaml)

  BuildRequires: python3dist(packaging)

+ %if 0%{fedora} < 32

+ # The %%if should not be needed, it works around:

+ #   https://github.com/rpm-software-management/mock/issues/336

+ BuildRequires: (python3dist(importlib-metadata) if python3 < 3.8)

+ %endif

  BuildRequires: python3dist(pytoml)

  BuildRequires: python3dist(pip)

  BuildRequires: python3dist(setuptools)
@@ -76,6 +87,9 @@ 

  %license LICENSE

  

  %changelog

+ * Fri Jul 26 2019 Petr Viktorin <pviktori@redhat.com> - 0-6

+ - Use importlib_metadata rather than pip freeze

+ 

  * Fri Jul 26 2019 Miro Hrončok <mhroncok@redhat.com> - 0-5

  - Allow to fetch test dependencies from tox

  - Add %%tox macro to invoke tests

file modified
+18 -20
@@ -26,7 +26,10 @@ 

      from packaging.requirements import Requirement, InvalidRequirement

      from packaging.version import Version

      from packaging.utils import canonicalize_name, canonicalize_version

-     import pip

+     try:

+         import importlib.metadata as importlib_metadata

+     except ImportError:

+         import importlib_metadata

  except ImportError as e:

      print_err('Import error:', e)

      # already echoed by the %pyproject_buildrequires macro
@@ -44,14 +47,8 @@ 

  

  class Requirements:

      """Requirement printer"""

-     def __init__(self, freeze_output, extras=''):

-         self.installed_packages = {}

-         for line in freeze_output.splitlines():

-             line = line.strip()

-             if line.startswith('#'):

-                 continue

-             name, version = line.split('==')

-             self.installed_packages[name.strip()] = Version(version)

+     def __init__(self, get_installed_version, extras=''):

+         self.get_installed_version = get_installed_version

  

          self.marker_env = {'extra': extras}

  
@@ -77,7 +74,11 @@ 

              print_err(f'Ignoring alien requirement:', requirement_str)

              return

  

-         installed = self.installed_packages.get(requirement.name)

+         try:

+             installed = self.get_installed_version(requirement.name)

+         except importlib_metadata.PackageNotFoundError:

+             print_err(f'Requirement not satisfied: {requirement_str}')

+             installed = None

          if installed and installed in requirement.specifier:

              print_err(f'Requirement satisfied: {requirement_str}')

              print_err(f'   (installed: {requirement.name} {installed})')
@@ -203,9 +204,14 @@ 

  

  

  def generate_requires(

-     freeze_output, *, include_runtime=False, toxenv=None, extras='',

+     *, include_runtime=False, toxenv=None, extras='',

+     get_installed_version=importlib_metadata.version,  # for dep injection

  ):

-     requirements = Requirements(freeze_output, extras=extras)

+     """Generate the BuildRequires for the project in the current directory

+ 

+     This is the main Python entry point.

+     """

+     requirements = Requirements(get_installed_version, extras=extras)

  

      try:

          backend = get_backend(requirements)
@@ -259,16 +265,8 @@ 

          print_err('-x (--extras) are only useful with -r (--runtime)')

          exit(1)

  

-     freeze_output = subprocess.run(

-         [sys.executable, '-I', '-m', 'pip', 'freeze', '--all'],

-         encoding='utf-8',

-         stdout=subprocess.PIPE,

-         check=True,

-     ).stdout

- 

      try:

          generate_requires(

-             freeze_output,

              include_runtime=args.runtime,

              toxenv=args.toxenv,

              extras=args.extras,

@@ -6,6 +6,11 @@ 

  

  from pyproject_buildrequires import generate_requires

  

+ try:

+     import importlib.metadata as importlib_metadata

+ except ImportError:

+     import importlib_metadata

+ 

  testcases = {}

  with Path(__file__).parent.joinpath('testcases.yaml').open() as f:

      testcases = yaml.safe_load(f)
@@ -26,9 +31,17 @@ 

          if filename in case:

              cwd.joinpath(filename).write_text(case[filename])

  

+     def get_installed_version(dist_name):

+         try:

+             return str(case['installed'][dist_name])

+         except (KeyError, TypeError):

+             raise importlib_metadata.PackageNotFoundError(

+                 f'info not found for {dist_name}'

+             )

+ 

      try:

          generate_requires(

-             case['freeze_output'],

+             get_installed_version=get_installed_version,

              include_runtime=case.get('include_runtime', False),

              extras=case.get('extras', ''),

              toxenv=case.get('toxenv', None),

file modified
+43 -44
@@ -1,5 +1,5 @@ 

  No pyproject.toml, nothing installed:

-   freeze_output: |

+   installed:

      # empty

    expected: |

      python3dist(setuptools) >= 40.8
@@ -7,7 +7,7 @@ 

    result: 0

  

  Nothing installed yet:

-   freeze_output: |

+   installed:

      # empty

    pyproject.toml: |

      # empty
@@ -17,9 +17,9 @@ 

    result: 0

  

  Insufficient version of setuptools:

-   freeze_output: |

-     setuptools==5

-     wheel==1

+   installed:

+     setuptools: 5

+     wheel: 1

    pyproject.toml: |

      # empty

    expected: |
@@ -28,9 +28,9 @@ 

    result: 0

  

  Empty pyproject.toml, empty setup.py:

-   freeze_output: |

-     setuptools==50

-     wheel==1

+   installed:

+     setuptools: 50

+     wheel: 1

    setup.py: |

    expected: |

      python3dist(setuptools) >= 40.8
@@ -39,9 +39,9 @@ 

    result: 0

  

  Default build system, empty setup.py:

-   freeze_output: |

-     setuptools==50

-     wheel==1

+   installed:

+     setuptools: 50

+     wheel: 1

    pyproject.toml: |

      # empty

    setup.py: |
@@ -52,24 +52,24 @@ 

    result: 0

  

  Erroring setup.py:

-   freeze_output: |

-     setuptools==50

-     wheel==1

+   installed:

+     setuptools: 50

+     wheel: 1

    setup.py: |

      exit(77)

    result: 77

  

  Bad character in version:

-   freeze_output: |

+   installed: {}

    pyproject.toml: |

      [build-system]

      requires = ["pkg == 0.$.^.*"]

    except: ValueError

  

  Build system dependencies in pyproject.toml:

-   freeze_output: |

-     setuptools==50

-     wheel==1

+   installed:

+     setuptools: 50

+     wheel: 1

    pyproject.toml: |

      [build-system]

      requires = [
@@ -100,9 +100,9 @@ 

    result: 0

  

  Default build system, build dependencies in setup.py:

-   freeze_output: |

-     setuptools==50

-     wheel==1

+   installed:

+     setuptools: 50

+     wheel: 1

    setup.py: |

      from setuptools import setup

      setup(
@@ -120,10 +120,10 @@ 

    result: 0

  

  Default build system, run dependencies in setup.py:

-   freeze_output: |

-     setuptools==50

-     wheel==1

-     pyyaml==1

+   installed:

+     setuptools: 50

+     wheel: 1

+     pyyaml: 1

    include_runtime: true

    setup.py: |

      from setuptools import setup
@@ -143,10 +143,10 @@ 

    result: 0

  

  Run dependencies with extras (not selected):

-   freeze_output: |

-     setuptools==50

-     wheel==1

-     pyyaml==1

+   installed:

+     setuptools: 50

+     wheel: 1

+     pyyaml: 1

    include_runtime: true

    setup.py: &pytest_setup_py |

          # slightly abriged copy of pytest's setup.py
@@ -200,10 +200,10 @@ 

    result: 0

  

  Run dependencies with extras (selected):

-   freeze_output: |

-     setuptools==50

-     wheel==1

-     pyyaml==1

+   installed:

+     setuptools: 50

+     wheel: 1

+     pyyaml: 1

    include_runtime: true

    extras: testing

    setup.py: *pytest_setup_py
@@ -227,10 +227,10 @@ 

  

  Run dependencies with multiple extras:

    xfail: requirement.marker.evaluate seems to not support multiple extras

-   freeze_output: |

-     setuptools==50

-     wheel==1

-     pyyaml==1

+   installed:

+     setuptools: 50

+     wheel: 1

+     pyyaml: 1

    include_runtime: true

    extras: testing,more-testing, even-more-testing , cool-feature

    setup.py: |
@@ -246,19 +246,18 @@ 

    expected: |

      python3dist(setuptools) >= 40.8

      python3dist(wheel)

-     python3dist(wheel)

      python3dist(dep1)

      python3dist(dep2)

      python3dist(dep3)

      python3dist(dep4)

    result: 0

  

- Tox depndencies:

-   freeze_output: |

-     setuptools==50

-     wheel==1

-     tox==3.5.3

-     tox-current-env==0.0.2

+ Tox dependencies:

+   installed:

+     setuptools: 50

+     wheel: 1

+     tox: 3.5.3

+     tox-current-env: 0.0.2

    toxenv: py3

    setup.py: |

      from setuptools import setup

file modified
+16 -5
@@ -1,12 +1,20 @@ 

  #!/usr/bin/bash -eux

+ . /etc/os-release

+ fedora=$VERSION_ID

  

- config="/tmp/fedora-rawhide-x86_64-ci.cfg"

+ # we don't have dynamic BuildRequires on Fedora 30

+ # so we at least test that we can build in a Fedora 31 mock

+ if [ $fedora -lt 31 ]; then

+   fedora=31

+ fi

+ 

+ config="/tmp/fedora-${fedora}-x86_64-ci.cfg"

  

  # create mock config if not present

  # this makes sure tested version of pyproject-rpm-macros is available

  # TODO: check if it has precedence if the release was not bumped in tested PR

  if [ ! -f $config ]; then

-   original="/etc/mock/fedora-rawhide-x86_64.cfg"

+   original="/etc/mock/fedora-${fedora}-x86_64.cfg"

    split=$(sed -n '/\[fedora\]/=' $original | head -n1)

    head -n$(($split-1)) $original > $config

    cat /etc/yum.repos.d/test-pyproject-rpm-macros.repo >> $config
@@ -23,14 +31,17 @@ 

  rpmbuild -bs ${1}.spec

  

  # build the SRPM in mock

+ res=0

  mock -r $config --enablerepo=local init

- mock -r $config --enablerepo=local ~/rpmbuild/SRPMS/${1}-*.src.rpm

+ mock -r $config --enablerepo=local ~/rpmbuild/SRPMS/${1}-*.src.rpm || res=$?

  

  # move the results to the artifacts directory, so we can examine them

  artifacts=${TEST_ARTIFACTS:-/tmp/artifacts}

- pushd /var/lib/mock/fedora-rawhide-x86_64/result

- mv *.rpm ${artifacts}/

+ pushd /var/lib/mock/fedora-*-x86_64/result

+ mv *.rpm ${artifacts}/ || :

  for log in *.log; do

   mv ${log} ${artifacts}/${1}-${log}

  done

  popd

+ 

+ exit $res

@@ -0,0 +1,46 @@ 

+ %global pypi_name clikit

+ Name:           python-%{pypi_name}

+ Version:        0.3.1

+ Release:        1%{?dist}

+ Summary:        Builds beautiful and testable command line interfaces

+ 

+ License:        MIT

+ URL:            https://github.com/sdispater/clikit

+ Source0:        %{pypi_source}

+ 

+ BuildArch:      noarch

+ BuildRequires:  pyproject-rpm-macros

+ 

+ %description

+ %{summary}.

+ 

+ 

+ %package -n python3-%{pypi_name}

+ Summary:        %{summary}

+ %{?python_provide:%python_provide python3-%{pypi_name}}

+ 

+ %description -n python3-%{pypi_name}

+ %{summary}.

+ 

+ 

+ %prep

+ %autosetup -p1 -n %{pypi_name}-%{version}

+ 

+ 

+ %generate_buildrequires

+ %pyproject_buildrequires

+ 

+ 

+ %build

+ %pyproject_wheel

+ 

+ 

+ %install

+ %pyproject_install

+ 

+ 

+ %files -n python3-%{pypi_name}

+ %doc README.md

+ %license LICENSE

+ %{python3_sitelib}/%{pypi_name}/

+ %{python3_sitelib}/%{pypi_name}-%{version}.dist-info/

file modified
+2 -2
@@ -1,6 +1,6 @@ 

  %global pypi_name pluggy

  Name:           python-%{pypi_name}

- Version:        0.12.0

+ Version:        0.13.0

  Release:        1%{?dist}

  Summary:        The plugin manager stripped of pytest specific details

  
@@ -28,7 +28,7 @@ 

  

  

  %generate_buildrequires

- %pyproject_buildrequires -e %{toxenv}-pytestrelease

+ %pyproject_buildrequires -t

  

  

  %build

file modified
+3
@@ -22,6 +22,9 @@ 

      - pluggy:

          dir: .

          run: ./mocktest.sh python-pluggy

+     - clikit:

+         dir: .

+         run: ./mocktest.sh python-clikit

      required_packages:

      - mock

      - rpmdevtools

no initial comment

8 new commits added

  • Fedora CI: Run mock on the current Fedora version (or 31 if less than 31)
  • Bump release
  • Don't use --strip-file-prefix with pip, the custom option is gone
  • Fedora CI: Publish the mock logs even when it fails
  • Use importlib_metadata rather than pip freeze
  • Fedora CI: Update pluggy to avoid a missing dependency on importlib_metadata
  • Add test that uses poetry
  • Documentation typo
4 years ago

Pull-Request has been closed by churchyard

4 years ago