#207 Port to declarative setuptools configuration and pyproject.toml
Merged 2 years ago by decathorpe. Opened 2 years ago by decathorpe.
Unknown source main  into  main

file added
+9
@@ -0,0 +1,9 @@

+ [build-system]

+ requires = ["setuptools"]

Back in the day, this needed setuptools and wheel. But if it works without, so be it.

+ build-backend = "setuptools.build_meta"

+ 

+ [tool.black]

+ line-length = 120

+ target-version = ["py38"]

+ include = '\.pyi?$'

+ 

file added
+41
@@ -0,0 +1,41 @@

+ [metadata]

+ name = rust2rpm

+ version = attr: rust2rpm.__version__

+ description = Generate RPM packages for Rust crates

+ long_description = file: README.md

+ keywords = rpm, cargo, rust

+ license = MIT

+ url = https://pagure.io/fedora-rust/rust2rpm

+ author = Fedora Rust SIG

+ author_email = rust@lists.fedoraproject.org

+ classifiers =

+     Development Status :: 5 - Production/Stable

+     Intended Audience :: Developers

+     License :: OSI Approved :: MIT License

+     Operating System :: POSIX :: Linux

+     Programming Language :: Python :: 3 :: Only

+     Programming Language :: Python :: 3.8

+     Programming Language :: Python :: 3.9

+     Programming Language :: Python :: 3.10

+     Programming Language :: Python :: 3.11

+     Topic :: Software Development :: Build Tools

+     Topic :: System :: Software Distribution

+     Topic :: Utilities

+ 

+ [options]

+ include_package_data = True

+ packages = rust2rpm, rust2rpm.core

+ install_requires =

+     jinja2

+     pyparsing

+     requests

+     tqdm

+ 

+ [options.package_data]

+ rust2rpm = *.csv, templates/*.spec, templates/*.spec.inc

+ 

+ [options.entry_points]

+ console_scripts =

+     rust2rpm = rust2rpm.__main__:main

+     cargo-inspector = rust2rpm.core.inspector:main

+ 

file removed
-63
@@ -1,63 +0,0 @@

- from setuptools import setup

- 

- def read_version(path):

-     with open(path, 'rt') as f:

-         for line in f:

-             if line.startswith('__version__'):

-                 return line.split("'")[1]

-         raise IOError

- 

- version = read_version('rust2rpm/__init__.py')

- 

- ARGS = dict(

-     name="rust2rpm",

-     version=version,

-     description="Convert Rust crates to RPM",

-     license="MIT",

-     keywords="rust cargo rpm",

- 

-     packages=[

-         "rust2rpm",

-         "rust2rpm.core",

-     ],

-     package_data={

-         "rust2rpm": [

-             "spdx_to_fedora.csv",

-             "templates/*.spec",

-             "templates/*.spec.inc",

-         ],

-     },

-     entry_points={

-         "console_scripts": [

-             "rust2rpm = rust2rpm.__main__:main",

-             "cargo-inspector = rust2rpm.core.inspector:main",

-         ],

-     },

-     install_requires=[

-         # rust2rpm

-         "jinja2",

-         "requests",

-         "tqdm",

-     ],

- 

-     author="Igor Gnatenko",

-     author_email="ignatenkobrain@fedoraproject.org",

-     url="https://pagure.io/fedora-rust/rust2rpm",

-     classifiers=[

-         "Development Status :: 5 - Production/Stable",

-         "Intended Audience :: Developers",

-         "License :: OSI Approved :: MIT License",

-         "Operating System :: POSIX :: Linux",

-         "Programming Language :: Python :: 3 :: Only",

-         "Programming Language :: Python :: 3.8",

-         "Programming Language :: Python :: 3.9",

-         "Programming Language :: Python :: 3.10",

-         "Programming Language :: Python :: 3.11",

-         "Topic :: Software Development :: Build Tools",

-         "Topic :: System :: Software Distribution",

-         "Topic :: Utilities",

-     ],

- )

- 

- if __name__ == "__main__":

-     setup(**ARGS)

I've attempted to modernize our Python packaging a bit:

  • ported project configuration from setup.py to setup.cfg
  • added pyproject.toml and specified setuptools as our build tool
  • added configuration for black (not yet applied)

@churchyard it would be great if you could take a look at this, if you have the time. I haven't done python packaging in a while, so I needed to look at the docs for how to do this correctly ...

First I moved all our imperative setuptools configuration from setup.py to a declarative configuration in setup.cfg according to: https://setuptools.pypa.io/en/latest/userguide/declarative_config.html

Then I deleted the now-empty setup.py file and created a minimal pyproject.toml file: https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html

I'm pretty sure at least some of the settings that are in setup.cfg right now could be moved to pyproject.toml as well, but once I was at that point, the documentation wasn't really that great.

At least the way I've done it now, projects settings are in setup.cfg, while build / tool settings are in pyproject.toml, which seems like a nice separation of concerns.


I've tested that running pip install . --use-pep517 in a virtualenv already works without warnings or error messages. Though I'm not sure if it actually identifies "rust2rpm" and "rust2rpm.core" as different packages (or if it even needs to?), and since that's one of the main improvements that I want to make to the packaging of the next rust2rpm version, it would be great if that worked as expected from the python side of things :)

Though I'm not sure if it actually identifies "rust2rpm" and "rust2rpm.core" as different packages (or if it even needs to?)

It never did ;) And it does not need to.

Back in the day, this needed setuptools and wheel. But if it works without, so be it.

Thanks for taking a look!

It never did ;) And it does not need to.

Ok, good to know.

Back in the day, this needed setuptools and wheel. But if it works without, so be it.

I don't think it needs "wheel" to work:

rm -rf venv
python3 -m venv venv
source venv/bin/activate
pip install . --use-pep517       # works without errors
  • I've installed from the origin main branch with --use-pep517.
  • I've installed from your main branch with --use-pep517.
  • I've diffed the results
--- venv-origin/lib/python3.10/site-packages/rust2rpm-21.dist-info/METADATA 2022-07-23 12:08:38.286803164 +0200
+++ venv-pr/lib/python3.10/site-packages/rust2rpm-21.dist-info/METADATA 2022-07-23 12:08:53.780889455 +0200
@@ -1,12 +1,12 @@
 Metadata-Version: 2.1
 Name: rust2rpm
 Version: 21
-Summary: Convert Rust crates to RPM
+Summary: Generate RPM packages for Rust crates
 Home-page: https://pagure.io/fedora-rust/rust2rpm
-Author: Igor Gnatenko
-Author-email: ignatenkobrain@fedoraproject.org
+Author: Fedora Rust SIG
+Author-email: rust@lists.fedoraproject.org
 License: MIT
-Keywords: rust cargo rpm
+Keywords: rpm,cargo,rust
 Classifier: Development Status :: 5 - Production/Stable
 Classifier: Intended Audience :: Developers
 Classifier: License :: OSI Approved :: MIT License
@@ -21,6 +21,69 @@
 Classifier: Topic :: Utilities
 License-File: LICENSE
 Requires-Dist: jinja2
+Requires-Dist: pyparsing
 Requires-Dist: requests
 Requires-Dist: tqdm

+# rust2rpm
+
+rust2rpm is a tool... (the entire README omitted here)

The venv also differed because it newly has pyparsing. I see the change is a separate commit, so good.

No idea about the black configuration, I don't use it.

I don't think it needs "wheel" to work...

I suppose setuptools will generate the wheel requirement in the next step. It's nicely visible when building RPM packages. Possibly also visible when pip is told to be more verbose, but not sure.

Ah yes, I see this if I run pip install . --with-pep517 --verbose:

(...)
  Running command /home/deca/Workspace/rust2rpm/venv/bin/python3 /tmp/pip-standalone-pip-asdvz7z6/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-xi0noc9y/normal --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- wheel
  Collecting wheel
    Using cached wheel-0.37.1-py2.py3-none-any.whl (35 kB)
  Installing collected packages: wheel
  Successfully installed wheel-0.37.1
(...)

So should I add "wheel" to the build-system.requires list in pyproject.toml?

I've diffed the results

So I think the diff looks good? :) All the changed lines look like they were caused by intentional changes on my side.

So should I add "wheel" to the build-system.requires list in pyproject.toml?

No.

Pull-Request has been merged by decathorpe

2 years ago