Commit Graph

39 Commits

Author SHA1 Message Date
Miro Hrončok
32790fff20 Pass PYTHONDONTWRITEBYTECODE=1 to %tox to avoid packaged PYTEST bytecode 2020-12-04 10:50:58 +01:00
Miro Hrončok
38ef5fb85b Allow multiple -e in %pyproject_buildrequires 2020-11-04 18:35:22 +01:00
Lumir Balhar
c5d2f62b23 Use --verbose and --force when removing RECORD and REQUESTED files 2020-10-01 09:28:21 +02:00
Lumir Balhar
efdfb4727f Automatically remove dist-info/REQUESTED files together with RECORD 2020-10-01 09:28:21 +02:00
Lumir Balhar
8d5b3ac22f Restructure %pyproject_install to remove duplicated for loop 2020-09-25 12:24:50 +00:00
Lumir Balhar
894e21291e Preprocess dist-info/RECORD file in %install and remove it.
According to PEP 627, the RECORD file is optional and
doesn't make sense to keep it for system packages. Moreover,
its absence should indicate to other tools like pip that
they should not touch such packages.

Now, we process content of all RECORD files to one
pyproject-record (JSON) which is then used in
%pyproject_save_files. That way, we can remove the original
files in %pyproject_install and keep their content for
later.

PEP 627: https://www.python.org/dev/peps/pep-0627/#optional-record-file
2020-09-25 12:24:50 +00:00
Miro Hrončok
b4fd1c2e74 Only require toml for projects with pyproject.toml
Pros:

 - projects without pyproject.toml will have 1 less dependency
 - toml will be buildable with pyproject-rpm-macros out of the box
 - easier bootstrap sequence (in theory)

Cons:

 - projects with pyproject.toml will have 1 more %generate_buildrequires round
2020-09-07 09:48:27 +02:00
Miro Hrončok
1e199ca6f4 Make code in $PWD importable from %pyproject_buildrequires
In %pyproject_buildrequires, don't run python with -I but -s.

This allows projects used by the script itself, such as packaging or toml,
to be packaged using the macros, using "self" -- i.e. the code from $PWD.
2020-09-04 21:47:35 +00:00
Tomas Hrnciar
a506123afe Replace pathfix with py3_shebang_fix
%pyproject_install currently has:
`pathfix%{python3_version}.py -pni "%{__python3}" -k%{?py3_shbang_opts: -a%{py3_shbang_opts_nodash}} %{buildroot}%{_bindir}/*`

We should replace it with `%py3_shebang_fix %{buildroot}%{_bindir}/*` which expands to:
~~~~
  if [ -f /usr/bin/pathfix%{python3_version}.py ]; then
    pathfix=/usr/bin/pathfix%{python3_version}.py
  else
    # older versions of Python don't have it and must BR /usr/bin/pathfix.py from python3-devel explicitly
    pathfix=/usr/bin/pathfix.py
  fi
  $pathfix -pni %{__python3} -k%{?py3_shebang_flags:a %py3_shebang_flags}} %{buildroot}%{_bindir}/*
~~~~

Mainly so that we:
 - switch to %py3_shebang_flags
 - have only one place to fix the invocation

Fixes: rhbz#1868347
2020-09-04 18:24:30 +02:00
Miro Hrončok
a613e176e3 Handle Python Extras in %pyproject_buildrequires on Fedora 33+
There is a slight problem when reporting that a dependency with extra is satisfied.
In fact, we only check the "base" dependency.
This can lead to a problem when a dependency is wrongly assumed as present
and the script proceeds to the "next stage" without restarting --
if the next stage tries to use (import) the missing dependency,
the script would crash.

However, that might be a very unlikely set of events and if such case ever happens,
we'll workaround it or fix it.
2020-08-20 15:30:49 +02:00
Lumir Balhar
cb8e334272 Use python -m tox instead of just tox
This way, macros can use whatever Python has tox module available
instead of only the main one which owns /usr/bin/tox.
2020-08-10 12:04:22 +02:00
Lumir Balhar
5561755a00 Make %pyproject_buildrequires more universal
so it can work with any non-main Python version and generate
proper dependencies.
2020-08-10 12:04:22 +02:00
Lumir Balhar
64e45518ef Use versioned pathfixX.Y.py script
so pyproject-rpm-macros can depend on any pythonX.Y-devel package
2020-08-10 12:04:22 +02:00
Tomas Hrnciar
1fc1c18fd9 Removes bindir parameter from script
This parameter is not necessary anymore with +auto argument replacing +bindir.
2020-08-06 15:26:37 +02:00
Miro Hrončok
7e5adc9c02 Fix a copy paste error in %pyproject_extras_subpkg definition
Also, add a comment for unreadable RPM expression.

This is a fixup of cb4e43c670
2020-08-04 15:17:16 +02:00
Miro Hrončok
cb4e43c670 Implement %pyproject_extras_subpkg 2020-07-29 17:40:37 +02:00
Miro Hrončok
37216e779e Set HOSTNAME to prevent tox 3.17+ from a DNS query
Tox calls socket.getfqdn() and that call does a DNS query.
In mock with disabled networking, it takes a minute until that times out.
When a spec file uses %pyproject_buildrequires -t and %tox, it is a 3 minute delay.

Since 3.17, tox does not call socket.getfqdn() when HOSTNAME variable is set to a value:

https://github.com/tox-dev/tox/pull/1616

The value is only used in result log, so setting it to "rpmbuild"
actually makes the logs more reproducible as well.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1856356
when tox is used in %pyproject_buildrequires -t or %tox.
2020-07-15 13:24:40 +02:00
Miro Hrončok
ed5dd772f3 Switch from upstream deprecated pytoml to toml 2020-06-23 11:09:03 +00:00
Tomas Hrnciar
19f84b1f4c Adapt pyproject_install macro to PEP 610
With changes in PEP 610 there is new file direct_url.json created, since it is not useful
for us we prevent it's creation. This commit changes %pyproject_install macro to install wheel using
name instead of path.

This commit also includes new test to check if file direct_url.json wasn't created.

https://discuss.python.org/t/pep-610-usage-guidelines-for-linux-distributions/4012
2020-05-07 13:08:22 +02:00
Miro Hrončok
95ba8376f5 Handle extracting debuginfo from extension modules
Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1806625

Upstream issue for a proper fix https://github.com/pypa/pip/issues/7555

Co-Authored-By: Petr Viktorin <pviktori@redhat.com>
2020-04-16 15:45:48 +02:00
Patrik Kopkan
2800b49530 Add %pyproject_save_files macro
This macro save generates file section to %pyproject_files. It should
simplify %files section and allow to build by some automatic machinery

Supposed use case in Fedora:
    %install
    %pyproject_install
    %pyproject_save_files requests _requests

    %files -n python3-requests -f %{pyproject_files}
    %doc README.rst
    %license LICENSE

Automatic build of arbitrary packages (e.g. in Copr):
    %install
    %pyproject_install
    %pyproject_save_files * +bindir // save all modules with executables

    %files -n python3-requests -f %{pyproject_files}

Co-Authored-By: Miro Hrončok <miro@hroncok.cz>
2020-04-15 16:45:10 +02:00
Miro Hrončok
dbb90f5dc1 Preserve existing flags in shebangs of Python files in /usr/bin
Use pathfix.py with -k and -a flags

Solves problems like https://bugzilla.redhat.com/show_bug.cgi?id=1335203
2020-02-07 18:35:06 +01:00
Patrik Kopkan
49a323e46e create directory in $PWD for built wheel
It is little bit more explicit than installing wheels from $PWD.
2019-11-21 13:12:18 +01:00
Anna Khaitovich
8cce1fad47 Remove stray __pycache__ directory from /usr/bin when running %pyproject_install
Solves bz#1739848
2019-11-14 11:40:28 +01:00
Miro Hrončok
102626373e Move a verbose line of %pyproject_buildrequires from stdout to stderr
The `rm -v` command prints the output to stderr, polluting the generated buildrequires

  $ rm -rfv pytest_harvest.dist-info/
  removed 'pytest_harvest.dist-info/METADATA'
  removed 'pytest_harvest.dist-info/LICENSE'
  removed 'pytest_harvest.dist-info/top_level.txt'
  removed 'pytest_harvest.dist-info/entry_points.txt'
  removed directory 'pytest_harvest.dist-info/'

This can lead to RPM errors:

  error: Dependency tokens must begin with alpha-numeric, '_' or '/': 'pytest_harvest.dist-info/METADATA'

Or bogus dependencies -- the SRPM requires "removed" and "directory".

See https://github.com/rpm-software-management/rpm/pull/889
2019-10-08 13:01:08 +02:00
Miro Hrončok
97d785b58d Don't use --strip-file-prefix with pip, the custom option is gone 2019-09-20 01:32:33 +02:00
Petr Viktorin
d262d909f5 Use importlib_metadata rather than pip freeze 2019-09-18 16:16:17 +02:00
Miro Hrončok
31ef675ff5 Support spaces in %toxenv 2019-08-21 18:01:31 +02:00
Miro Hrončok
fda0a23075 -t means "use tox", -e means "use this toxenv", -e implies -t
Further fixes
2019-08-13 14:42:21 +02:00
Miro Hrončok
ec073171f3 Add %tox macro to invoke tests 2019-07-29 14:42:53 +02:00
Miro Hrončok
0124d2a76f Define and save %toxenv for further use 2019-07-26 17:26:11 +02:00
Miro Hrončok
8a60635881 Allow to fetch test dependencies from tox 2019-07-26 15:07:11 +02:00
Petr Viktorin
d6e6bb7dfb Allow specifying extras for build dependencies 2019-07-18 10:50:13 +02:00
Petr Viktorin
bc156c4460 Generate run-time requirements for tests 2019-07-18 08:59:44 +02:00
Petr Viktorin
50645e10a3 Refactor and add tests 2019-07-17 15:57:02 +02:00
Miro Hrončok
fdf511644e Add %pyproject_buildrequires 2019-07-05 11:28:55 +02:00
Miro Hrončok
a94281a5df %pyproject_install: Add --no-warn-script-location
Otherwise you see:

    WARNING: The scripts py.test and pytest are installed in '/builddir/build/BUILDROOT/pytest-4.6.4-1.fc31.x86_64/usr/bin' which is not on PATH.
      Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

And that is not relevant for us.
2019-07-02 13:58:24 +02:00
Miro Hrončok
253976c0e7 Fix shell syntax in the install macro
This was the error:

    /var/tmp/rpm-tmp.UmO2Gv: line 45: syntax error near unexpected token `fi
2019-07-02 13:57:24 +02:00
Patrik Kopkan
162b0ca345 initial import (#1717389) 2019-07-02 12:41:04 +02:00