100 Commits
Author SHA1 Message Date
Karolina Surma 2d98f31955 Run tests with Python 3.15 2025-12-22 11:09:22 +01:00
Karolina Surma 8794d0963f Add a newline at the end of the specfile (fixes #65) 2025-12-22 11:09:03 +01:00
Karolina Surma 26bddd8ce3 Bump version 0.12.2 -> 0.13.0 2025-07-31 10:17:42 +02:00
Karolina SurmaandKarolina Surma f1cc06e490 Get rid of "pypi" prefix from the config values
Now there are two possible sources to read metadata from,
one of them entirely local without any involvement of PyPI.
Change the values accordingly.
2025-07-23 10:40:36 +02:00
Karolina SurmaandKarolina Surma 40b55ee132 Generate specfiles for packages built locally
With `pyp2spec <pkgname> --path /pth/to/artifacts` a specfile will be
now generated from data available in sdist and wheel.
The `--path` option takes as a value a directory where the built artifacts
are stored.
2025-07-23 10:40:36 +02:00
Karolina Surma 2afd5176ad Port to PEP 639 2025-07-02 13:58:55 +02:00
Karolina Surma 63af6bcbc5 Delete a leftover unused cassette 2025-07-02 13:58:39 +02:00
Karolina Surma 0a226320df Bump version 0.11.1 -> 0.12.0 2025-03-03 11:11:39 +01:00
Karolina Surma e89b4168c5 Update the list of trove license classifiers 2025-02-27 10:38:37 +01:00
Karolina SurmaandKarolina Surma 4a36396d23 Read extras first from provides_extra, then requires_dist (closes #57) 2025-02-25 14:56:22 +01:00
Karolina Surma d552ce37c9 Improve passing of CLI args in pyp2conf (closes #56) 2025-02-25 10:54:28 +01:00
Karolina SurmaandKarolina Surma c762cc39a9 Run CI on pushes to main, otherwise on PRs 2025-02-25 09:22:23 +01:00
Karolina SurmaandKarolina Surma fa92c916dc Pass the dictionary of CLI options rather than one by one 2025-02-25 09:22:23 +01:00
Karolina SurmaandKarolina Surma ba55c5a90a Create spec files with pyproject declarative buildsystem
This is an experimental build system added to rpm 4.20
and provisionally added to pyproject macros.
See:
https://rpm-software-management.github.io/rpm/manual/buildsystem.html
and
https://src.fedoraproject.org/rpms/pyproject-rpm-macros
(section: Provisional: Declarative Buildsystem (RPM 4.20+))
2025-02-25 09:22:23 +01:00
Karolina SurmaandKarolina Surma 3c6a738744 Account with package names ending with digits 2025-02-24 14:39:55 +01:00
Karolina SurmaandKarolina Surma 2cca4d3844 Support compat packages (Closes #15)
When specified on command line, a compat package for a given version
will be created.
pyp2spec will create a specfile for the latest version matching the
compat one, e.g. for `pytest --compat 7` it will create specfile for
version 7.4.4; for `pytest --compat 7.2` - 7.2.2.
It is possible to specify both compat and specific version, e.g.:
`pytest --compat 7 --version 7.3.0`
2025-02-24 14:39:55 +01:00
Karolina Surma fc17319634 Document pyp2spec is available in Fedora 2025-02-11 14:20:10 +01:00
Karolina Surma 6750d3fd9e Split the megafunction create_config_contents
The new create_package_from_source takes care of creating the package object
and the "old" create_config_contents only modifies the bits needed for
the full config file.
2025-02-07 19:52:06 +01:00
Karolina Surma db55a78169 More issues found by ruff 2025-02-07 19:52:06 +01:00
Karolina Surma 706096ef12 The fallback value of version is an empty string, not None 2025-02-07 19:52:06 +01:00
Karolina Surma 605d008762 Rework resolve_url so it's more legible 2025-02-07 19:52:06 +01:00
Karolina Surma 1376e0ba49 Raise an exception if there's no package name in metadata
That's an error state that can't be allowed to proceed further.
2025-02-07 19:52:06 +01:00
Karolina Surma e4795439e7 Bump packaging to at least 24.2 for support of PEP 639
This version is present in Fedora 41, 42, 43.
The compat bits could be removed.
2025-02-07 19:52:06 +01:00
Karolina Surma c8d456d577 Raise an exception when source is anything else than PyPI 2025-02-07 19:52:06 +01:00
Karolina Surma eb09c25aca Use type annotations for clearer understanding of the functions
Adapt ruff as a linter for the job.
2025-02-07 19:52:06 +01:00
Karolina Surma 77491e8a8e Define the package information in a dataclass
This serves as a sort of contract, as opposed to a plain dictionary.
This enables control over all of the attributes and makes it reasonably
sure nothing gets unexpectedly mixed in.
2025-02-07 13:43:41 +01:00
Karolina Surma a7d50639ee Remove rogue debug print 2025-01-29 16:37:10 +01:00
Karolina Surma 343dbf2603 Remove rogue imports 2025-01-24 17:03:37 +01:00
Karolina Surma 0fd8122e6c Unify two very similar functions 2025-01-24 17:03:22 +01:00
Karolina Surma 30d5e96947 Look for the well-known project URL keys
According to the official specification:
https://packaging.python.org/en/latest/specifications/well-known-project-urls/
project URLs' labels can be normalized and then searched for the
matches.
Attempt to find "homepage" and "source" first, and only return other
project URL values if these are not found.
2025-01-24 17:02:08 +01:00
Karolina Surma 833c8e7f8f Rename the functions to clearly indicate what they do 2025-01-17 15:14:50 +01:00
Karolina Surma ca996379a7 Correct the syntax and make linter happy 2025-01-10 17:35:13 +01:00
Karolina Surma e3161dfde1 Test with Python 3.14 2025-01-10 17:19:24 +01:00
Karolina Surma 20138c9bd6 Wrap click.secho to predefined functions - better readability 2025-01-10 17:12:23 +01:00
Karolina Surma b39221c813 pyp2conf: create a package based on core metadata if available
The refactor contains changes:
- core metadata coming from the Metadata file are the canonical source
  of truth to gather package info
- the archive metadata are still obtained from PyPI API, as core
  metadata don't include any information about them
- OOP approach is refactored to the functional one to achieve clearer
  design of multiple data sources and better testability of the
  particular functions
- pyp2conf now contains only the logic of the actual data assembly, all
  the helper methods are moved to the pypi_loaders, utils and
  license_processor
2025-01-10 17:11:53 +01:00
Karolina Surma 68ba134aa9 Bump version 0.11.0 -> 0.11.1 2024-11-21 17:55:12 +01:00
Karolina Surma cdd333ec7d Bring back the legacy sdist filename processing
(Effectively revert the removals done to implement PEP 625).
The removal was too haste and broke the users.

This reverts commit 9747b76c4f
and builds on top of the changes in between.
2024-11-21 17:55:12 +01:00
Karolina Surma a724cdb771 Bump version 0.10.0 -> 0.11.0 2024-10-22 19:08:24 +02:00
Karolina Surma 706ce6bbe1 Ignore all files generated by the tool 2024-10-22 19:08:24 +02:00
Karolina Surma 840324354f Test all the conf2spec functions 2024-10-22 19:08:24 +02:00
Karolina Surma 59b51e13f5 Move the name normalizing functions to utils
They are used in both scripts.
2024-10-22 19:08:24 +02:00
Karolina Surma 99fc8ca32f Separate loading of the config file from validating
This will help with testing the particular conf2spec functions.
2024-10-22 19:08:24 +02:00
Karolina Surma 5d0cba4788 Move RPM-specific computations to conf2spec
pyp2conf shouldn't be so heavy with RPM-specific data.
The data stored in the config file are the ones read from either the
PyPI API or Metadata file.
Everything related to transformations to specfiles is now stored in
conf2spec. It reads the config data and converts them to RPM-specific
format.
Ideally, if pyproject-rpm-macros become obsolete and a new system comes
in place, the only changes would be applicable on the side of conf2spec.
2024-10-22 17:52:24 +02:00
Karolina Surma 9747b76c4f Implement PEP 625
The sdist filenames are now standardized:
- distribution name is normalized similarly to the project names, but
  with "_" instead of "-"
- version string is expected to be PEP 440 compliant
- the supported file extension is tar.gz, zip is gone
2024-10-22 17:52:24 +02:00
Karolina Surma 942fd407a6 Update the example specfile output 2024-10-22 17:52:24 +02:00
Karolina Surma dde452901a Remove the obsolete code regarding description
A placeholder is always filled in.
2024-10-22 17:52:24 +02:00
Karolina Surma e997edff90 No more raising errors when detected licenses are invalid 2024-10-22 17:52:24 +02:00
Karolina Surma db7f375440 Update the test configs and expected outputs
Always test the whole config contents even if the test is about a single
feature.
This ensures no regressions are accidentally introduced and ensures
wanted updates when recreating cassettes.
2024-10-22 17:52:24 +02:00
Karolina SurmaandKarolina Surma 2ab284a2f4 Name attributes storing data from PyPI with 'pypi' prefix
Disambiguate the source of the used/read data, so that it's clear
what comes from PyPI API.
With the Core Metadata parser added, this is necessary.
2024-10-22 15:28:04 +02:00
Karolina SurmaandKarolina Surma 76b32aef49 Add the license presence assertion (closes: #49)
If "License-File" is present in Metadata file, we can safely add the
`-l` flag to %pyproject_save_files. The flag asserts that at least
one license file is marked as %license in the %files section
when there are none specified manually.
Not all build backends expose the field yet, which was oficially added
to Core Metadata 2.4 with PEP 639.
2024-10-22 15:28:04 +02:00
Karolina Surma bf70f16f6c Bump version 0.9.0 -> 0.10.0 2024-10-10 11:05:50 +02:00
Karolina Surma 41cdaf2a55 Decolorize some of the info statements coming from the application
Yellow - operating on the discovered information
Magenta - requires attention, not bad per se
Red - something bad has happened

Also, done cosmetic changes to the printed sentences, ain't noboody got
time to read novels.
2024-10-10 09:49:42 +02:00
Karolina Surma e828452064 Display the detected SPDX identifiers and their validity in Fedora 2024-10-10 09:49:42 +02:00
Karolina Surma 3163be3ab8 Don't error, just print a warning if the found license is invalid
Also, remove -l CLI option to provide the license manually.
Whoever needs that, can edit the resulting specfile.

Fixes: #47
2024-10-10 09:49:42 +02:00
Karolina Surma 45d5029a39 Remove unnecessary test configs
The differentiating bits were removed from the production code.
Annotate the remaining files and fields relevant for tests
(why do we test those)
2024-10-10 09:49:42 +02:00
Karolina Surma 0f744ae3ba Document automode 2024-10-10 09:49:42 +02:00
Karolina Surma 32fc2f1f07 Differentiate %pyproject_save_files based on the automode setting
For automated environments, we want to ensure buildability of the
created specfile, hence adding `"*" +auto` to %pyproject_save_files.
In the real Fedora packages, the valid argument to %pyproject_save_files
is a list of module names.
For now there's no automatic way to discover what modules the package
contains, so when a human user invokes pyp2spec, we want to generate a
file with placeholder (...) for them to fill in after the package
inspection.
2024-10-10 09:49:42 +02:00
Karolina Surma 0c516749a7 Differentiate the %check depending on the automode setting
- Utilize the new macro %_pyproject_check_import_allow_no_modules to allow
passing check in automated environments, even when the package doesn't
contain any Python modules (fixes #31).
2024-10-10 09:49:42 +02:00
Karolina Surma 098b1e05ab Introduce automode, remove the standalone top-level CLI option
First step to gather the defaults useful for automated build
environments but not so great to the human packagers, under one
umbrella.
2024-10-10 09:49:42 +02:00
Karolina Surma f68bd81433 Test on Python 3.13 2024-10-01 12:30:27 +02:00
Karolina Surma 423d49c1de Remove the binary files-related config options
Until they're autodetectable, we don't want them.
2024-10-01 12:29:53 +02:00
Karolina Surma 279ffe66b9 Remove doc-related config options
There's no automatic way to detect them.
Packagers are encouraged to inspect the package and add them as needed.
2024-10-01 12:29:52 +02:00
Karolina Surma c751c8895a Remove the license-related config options
The main Python build backends can discover the license files
automatically.
We don't need bits to manually add them.
2024-10-01 12:29:52 +02:00
Karolina Surma b5959eaeac Remove the test-related config options
This can't be detected automatically yet.
2024-10-01 12:29:52 +02:00
Karolina Surma ae075944f9 Remove remaining parts concerning the manual build requirements 2024-10-01 12:29:52 +02:00
Karolina Surma 19c1aab1a7 Remove the option to add custom Summary and Description
They're either detected from the package metadata
or filled in with a sane default for automated use.
The actual users can edit the resulting files.
2024-10-01 12:29:52 +02:00
Karolina Surma 540738c257 Migrate to pyproject.toml
No need to define the package in two config files.
2024-10-01 09:34:10 +02:00
Karolina Surma 661fb9b770 Bump version 0.8.0 -> 0.9.0 2024-04-11 15:56:08 +02:00
Karolina SurmaandKarolina Surma ce099be238 Create spec files for alternative Python versions (closes #16)
This feature is useful when creating packages for Centos Stream and RHEL
which contain multiple Python stacks and make it possible to build packages for
them.
2024-04-11 12:40:05 +02:00
Karolina Surma 39c562f019 Bump version 0.7.0 -> 0.8.0 2023-10-11 11:11:01 +02:00
Karolina SurmaandKarolina Surma a3be9eb968 Add the changelog entry 2023-10-11 10:47:49 +02:00
Karolina SurmaandKarolina Surma 55ef64fa8f Remove the CLI option to set archful packages
It's discovered automatically now.
If the users need to change more in the resulting files, they can edit them.
2023-10-11 10:47:49 +02:00
Karolina SurmaandKarolina Surma f6e4b0b4ba Determine if package is archful by parsing the wheel name
Packages on PyPI publish wheels which contain an abi tag informing
whether a package contains extensions compiled for a specific
architecture or not.
pyp2conf reads this information and saves it in the config file.
conf2spec automatically adds `gcc` to the generated specfile in case
package is archful.
2023-10-11 10:47:49 +02:00
Karolina SurmaandKarolina Surma ba868ae3ce Remove obsolete bits allowing to add manual build requirements
We only want to add what's detectable from the package metadata.
2023-10-11 10:47:49 +02:00
Karolina SurmaandKarolina Surma b7c1cdb63f Add extras to %pyproject_buildrequires
Use the newly added `extras` config key, containing a list of all
detected package extras.
2023-10-10 15:55:20 +02:00
Karolina SurmaandKarolina Surma 4244c2a3ae Remove obsolete bits allowing to manually define extras
They were partially defunct, made no actual sense and need to be
forgotten without mercy.
Generating extras for %pyproject_buildrequires (-x foo) will be improved.
For tox dependencies (-t), the users can manually add it to the resulting
spec file.
2023-10-10 15:55:20 +02:00
Karolina SurmaandKarolina Surma 641195404c Automatically detect extras from the PyPI metadata
Create extra subpackages for all of the detected upstream extras.
Due to PyPI API limitations, if an extra is defined as empty
(i.e. without any requirements), it won't be detected.
2023-10-10 15:55:20 +02:00
Karolina SurmaandKarolina Surma ce93424dce Save session as an attribute of a PypiPackage object
Don't send session as a method parameter through multiple layers.
Increase readability of methods' signatures.
2023-10-10 10:36:20 +02:00
Karolina SurmaandKarolina Surma d07ce850d9 Use versioned package JSON API from PyPI
This ensures fetching the metadata belonging to the correct package
version (fixes #41).
Reference:
https://warehouse.pypa.io/api-reference/json.html#get--pypi--project_name---version--json
2023-10-10 10:36:20 +02:00
Karolina SurmaandKarolina Surma d6fbd6f595 Save version as an attribute of a PypiPackage object
It is an inherent package property rather than an external factor.
It is the key differentiator for obtaining the package metadata (they
must match the given version release).
2023-10-10 10:36:20 +02:00
Karolina Surma 954ccd974b Remove the unused import from tests 2023-09-20 16:27:20 +02:00
Karolina Surma 5dd064b89c Pass the correct envnames to the GH action 2023-09-01 16:37:04 +02:00
Karolina SurmaandKarolina Surma 741a14aa9b Handle exceptions better throughout the app
Instead of raising multiple sys.exit's throughout the code,
each function either returns a proper value or raises a meaningful
custom error.
The custom errors are caught in each script's main(),
the error message is printed for user and the script exits.
2023-09-01 11:27:51 +02:00
Karolina Surma f8a1c500d3 Remove the unnecessary -dev suffix in 312 tox env 2023-09-01 11:26:00 +02:00
Karolina Surma 900dfc1a6d Run tox on project's CI 2023-06-02 15:10:47 +02:00
Karolina Surma b0d5969da6 Add tox configuration 2023-06-02 15:10:47 +02:00
Karolina Surma 316a6818d9 Lowest supported Python version is 3.9
importlib.resources.files() API isn't available in the older Pythons.
2023-06-02 09:45:40 +02:00
Karolina SurmaandKarolina Surma d8bb58ad49 Use the recommended importlib.resources.files() API to open package resources 2023-05-31 11:23:45 +02:00
Karolina Surma 0f603d69c9 Bump version 0.6.1 -> 0.7.0 2023-05-03 15:58:24 +02:00
Karolina SurmaandKarolina Surma f7cc4af5d1 Display the license string which failed to be parsed 2023-05-03 10:14:08 +02:00
Karolina SurmaandKarolina Surma 3c631c1f86 Include all the test files in the sdist 2023-05-03 10:14:08 +02:00
Karolina SurmaandKarolina Surma 740c252083 Update examples README to reflect the new specfile outcome 2023-05-03 10:14:08 +02:00
Karolina SurmaandKarolina Surma ebd1b81075 Move to rpmautospec macros for changelog and release
rpmautospec has been present in Fedora since F35 and it's currently
a recommended way of handling the changelog and release specfile
entries: https://fedoraproject.org/wiki/Changes/rpmautospec
2023-04-25 16:24:37 +02:00
Karolina SurmaandKarolina Surma 238faa40d6 Exit script correctly on a non-existing package (fixes #30) 2023-04-25 16:24:37 +02:00
Karolina SurmaandKarolina Surma dce4344006 Convert Python license classifiers to SPDX expressions
Alongside with the license-related code the tests were significantly
refactored to run offline. The changes are intertwined and so shipped in
a single commit.
The licensing changes:
- updated Trove-Fedora mappings (removed Callaway expressions, added
  SPDX)
- delegated the compliance check of Fedora licenses to a source
  maintained by the Fedora Legal team
- the logic of license processing was moved to a dedicated module:
  license_processor

The testing changes:
- moved betamax configuration to conftest.py to achieve a reliable global setting
- mocked fedora licensing data and PyPI package data to stop making
  unnecessary requests - most of the betamax cassettes were deleted
- several tests rewritten, many added
- regenerated remaining betamax cassettes

This is a best-effort solution which can't (nor aims to) cover all edge-cases.
Unless Python adopts SPDX standard, this will always be an approximation.
2023-04-25 10:17:47 +02:00
Karolina Surma 83a3568192 Bump version 0.6.0 -> 0.6.1 2022-08-01 14:14:57 +02:00
Karolina Surma dd292eb93c Include LICENSE-MIT-0 in the sdist and fix license metadata 2022-08-01 14:14:44 +02:00
Karolina Surma d9705f8536 Bump version 0.5.0 -> 0.6.0 2022-08-01 13:20:42 +02:00
Karolina Surma e580d544ae Add instructions how to record cassettes when needed 2022-08-01 12:59:24 +02:00
Karolina Surma 1ace5ce889 Normalize PyPI projects' name
- Replace underscores and dots  with dashes in projects' names
Projects like sphinx_design result in python-sphinx-design.spec
and python3-sphinx-design built RPM name.
- Convert uppercase characters to lowercase
Projects like Pello result in python-pello.spec and python3-pello
built RPM name.
This conforms better with package naming guidelines:
https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#_naming
2022-08-01 12:59:24 +02:00