-
-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add nFPM backend for building system packages (only the nfpm core bits) #19308
Merged
Merged
Changes from all commits
Commits
Show all changes
200 commits
Select commit
Hold shift + click to select a range
0473c1e
Add TraverseIfNotPackageTarget
cognifloyd 2343cd3
Add test for TraverseIfNotPackageTarget
cognifloyd 08c00f8
fmt
cognifloyd ec81f0a
Stub nFPM backend targets: nfpm_*_package
cognifloyd a899c11
Add nFPM common fields: arch, platform
cognifloyd 2ee0cd8
Add nFPM common fields: version
cognifloyd bf8ed64
Add nFPM version fields
cognifloyd 2d2320b
Add nFPM homepage and license fields
cognifloyd 8d6bcd9
Make mypy happy with help_text and enum usage
cognifloyd 1a4eb3f
Add stub files to hold the packager-specific nFPM metadata fields
cognifloyd 01e7935
Add nFPM 'maintainer'/'packager' fields
cognifloyd d48c62a
Add nFPM 'pkgbase' field for Archlinux packages
cognifloyd 5f83871
Add misc nFPM fields for rpm packages
cognifloyd 100cb63
Add nFPM fields for deb 'section' and 'priority'
cognifloyd 060c115
Add nFPM field for deb 'triggers'
cognifloyd e9580bf
Add nFPM subsystem
cognifloyd 202694a
add nfpm_alias to nfpm backend fields w/ _NfpmField Protocol for use
cognifloyd 0a29012
Separate tuples of nfpm target fields from target for reuse
cognifloyd fb277e3
Add nfpm package_name field
cognifloyd 00ca211
Add nfpm package field sets
cognifloyd f2d4256
Initial nfpm.yaml config generation
cognifloyd 54cc8ed
add rule to generate nfpm.yaml
cognifloyd a78d99c
Refactor: move nfpm fields files into subpackage
cognifloyd 8f4c2ba
Drop pointless re-lookup of value
cognifloyd c151c5b
stub nFPM package relationship fields (replaces, provides, depends, ...)
cognifloyd 39b0ea8
include description field in nFPM field set
cognifloyd b8a18ae
Add documentation for nfpm deb package relationship fields
cognifloyd 9625959
Add documentation for nfpm rpm package relationship fields
cognifloyd 4a0def1
Add documentation for nfpm apk package relationship fields
cognifloyd f74a963
Misc help string improvements for nfpm backend
cognifloyd 0509d47
Add documentation for nfpm archlinux package relationship fields
cognifloyd 470d0e6
Drop whitespace at end of lines
cognifloyd 4403067
Add nFPM compression fields for rpm and deb
cognifloyd b9c7b68
misc cleanups
cognifloyd 152464a
make mypy happy
cognifloyd d4e73ce
Move nfpm fields applicable to all targets to nfpm.fields.all
cognifloyd fcddf2b
Rename nfpm.field_set -> nfpm.field_sets
cognifloyd d5c1efd
Drop _NfpmField protocol (make config gen more robust)
cognifloyd fa9ae70
Add NfpmDependencies field
cognifloyd 4d7a4b7
Add NfpmRpmGhostContents field
cognifloyd 419fa83
Model nfpm_content_{file,symlink,dir}{,s} targets
cognifloyd 14edeba
always disable_globbing in nFPM contents
cognifloyd 889afdc
fix quote typos
cognifloyd a58ccbe
Document nFPM src+dst fields
cognifloyd 266940c
Add 'source' field for 'nfpm_content_file' target
cognifloyd a4e21e0
typo
cognifloyd 87044db
document the nfpm file_info fields
cognifloyd 1a675fc
Document nFPM content_type field
cognifloyd efee429
Allow nfpm file_mode to be specified as a string
cognifloyd c6c3ee0
clean up some docstrings
cognifloyd a6a2e19
clean up some nfpm content_type field docstring
cognifloyd 126c710
Add basic docs for remaining nfpm content fields
cognifloyd 631c376
Add basic docs for nfpm content targets
cognifloyd 47e7deb
mypy cleanups
cognifloyd 77be12a
Begin rules to gather nfpm contents
cognifloyd f46a371
Clean up some help_text/softwrap strings
cognifloyd b05648f
Simplify nFPM target field lists
cognifloyd c543c3b
Mark nFPM dst fields as required
cognifloyd a041e88
Use more succict TypedDict def
cognifloyd 2d2417a
Merge branch 'cognifloyd/package-deps-traversal' into 'cognifloyd/nfpm'
cognifloyd b9e1a14
Get transitive targets to generate nfpm config
cognifloyd 8c78955
populate nfpm.yaml contents array
cognifloyd 849f5ab
Handle OctalInt representation in nfpm.yaml
cognifloyd f6aa76e
Move nfpm content yaml types
cognifloyd da7d12d
use NfpmContent type in rpm field
cognifloyd 0759760
Cleanup TODO
cognifloyd dc41d85
clarify assumption comment
cognifloyd 2062359
Make the list of field set types reusable
cognifloyd 0527a70
Rename RequestNfpmPackageConfig -> NfpmPackageConfigRequest
cognifloyd 9dd2bf4
add default_file_extension to NfpmPackageFieldSet
cognifloyd d5d76b0
Move nfpm.generate_config_rules -> nfpm.util_rules.generate_config
cognifloyd 03e4206
Add logic to sort nfpm package deps by type
cognifloyd d110941
Begin building nfpm sandbox creation logic
cognifloyd daf7b14
Merge branch 'main' into cognifloyd/nfpm
cognifloyd 190c286
fmt & tailor
cognifloyd 3c066f1
Be more consistent in msg formatting
cognifloyd 4a94840
Add validation for NfpmContentFile target fields
cognifloyd aae8533
Update nFPM to v2.34.0
cognifloyd a56a7d3
collect/relocate nfpm_content_file sources in nfpm sandbox
cognifloyd 868ead0
Handle nfpm_content_files generator including overrides
cognifloyd f5f7af1
Finish nFPM sandbox generation
cognifloyd 124d80f
Move transitive_deps calculation into sandbox rule
cognifloyd 20affbf
Refactor some fields for better reuse
cognifloyd fe17876
Handle nfpm_content_symlinks generator including overrides
cognifloyd 1021c6c
Handle nfpm_content_dirs generator including overrides
cognifloyd 0a398f6
Finish nfpm_content_file handling in config generation rule
cognifloyd 6b7a179
Misc cleanup
cognifloyd 8d6f50e
Extract COMMON_NFPM_PACKAGE_FIELDS
cognifloyd f312f7b
Add NfpmOutputPathField
cognifloyd b229a72
Add packager var to nFPM field_sets
cognifloyd 78e506e
Drop NfpmPackageFieldSet.default_file_extension
cognifloyd d7c83a3
add package_nfpm_package rule
cognifloyd 6c8d5f9
Improve documentation for nfpm arch and platform fields
cognifloyd c6070da
Add support for deb predepends field
cognifloyd 5a2eebc
Add support for rpm prefixes field
cognifloyd bee5421
Add max value for NfpmContentFileModeField
cognifloyd 96ee6f7
Add link to upstream nFPM issue about SOURCE_DATE_EPOCH
cognifloyd 30174d0
fix: isort
cognifloyd 80c3a49
Improve docs for nFPM maintainer/packager fields
cognifloyd 8a2deb8
Partially implement nFPM sandbox validation
cognifloyd 5f624e2
Finish nfpm sandbox validation
cognifloyd 81fc0d9
whitespace fix
cognifloyd cd98f6d
Add scripts field to nfpm package targets
cognifloyd 2eddd8f
Document scripts fields of nfpm package targets
cognifloyd 98b968b
Improve docs for scripts fields of nfpm package targets
cognifloyd 8700dbd
type hint field values where None is not valid
cognifloyd f04ae14
type fixes for errors caught by mypy
cognifloyd 0b820da
Fix copy pasta in nFPM target_types_rules
cognifloyd 9a16431
Clarify order of Getting nFPM rules
cognifloyd b008080
Merge branch 'main' into cognifloyd/nfpm
cognifloyd 376cbcd
Merge branch 'main' into cognifloyd/nfpm
cognifloyd f0d9929
Merge branch 'main' into cognifloyd/nfpm
cognifloyd 71bb26a
register nfpm backend
cognifloyd 95405b2
nFPM: improve nFPM field docs
cognifloyd 076ef71
add test_nfpm_content_file_validate
cognifloyd 9ff9f7d
add test_generate_nfpm_config
cognifloyd 56cdd6c
flake8
cognifloyd 1b0fe6e
BUILD
cognifloyd 54f38c7
fix/fmt
cognifloyd b4147e7
flake8
cognifloyd aa63155
isort
cognifloyd 8b8122e
fix issues identified in nfpm field_sets_tests
cognifloyd de873cc
fix nfpm target_types_test
cognifloyd 07610b3
add more nfpm target_types_test cases
cognifloyd af366fe
mypy
cognifloyd 57a8649
refactor to make logic more testable
cognifloyd a480e71
nfpm: test sandbox dep categorization
cognifloyd d1f7428
flake8
cognifloyd f7769c6
run nfpm/util_rules tests
cognifloyd 63c192e
fix imports
cognifloyd e09df99
fix nfpm target registration
cognifloyd b9a9004
try to fix rule graph
cognifloyd 279d63b
nfpm: move target_types list for reuse in tests
cognifloyd d65451a
separate package rule per field set type
cognifloyd dca83e6
nfpm: stub integration test
cognifloyd 01cc68f
nfpm: register subsystem rules
cognifloyd b4bfedc
flake8
cognifloyd ad661c5
nfpm: register subsystem rules for integration test
cognifloyd 30e3e97
nfpm: register process rules
cognifloyd 5c30091
nfpm: fix rule registration
cognifloyd 21ad11b
nfpm: normalize Fields compute_value(raw_value) type hints
cognifloyd 4ca41a8
fmt
cognifloyd 2d34fd0
nfpm: add support for SOURCE_DATE_EPOCH and nfpm.yaml:mtime
cognifloyd 5c16ff5
nfpm: add suport for rpm verify scripts
cognifloyd 6bbfd66
nfpm: add TODOs about new IPK-type packaging format
cognifloyd f0daa81
nfpm: update to nfpm 2.37.1 (09 May 2024)
cognifloyd 2bee818
Merge branch 'main' into cognifloyd/nfpm
cognifloyd 53eeda2
pants migrate-call-by-name src/python/pants/backend/{experimental/,}n…
cognifloyd d63bb97
pants fix fmt src/python/pants/backend/nfpm/::
cognifloyd 3f9b638
fix mypy identified issues with the migration
cognifloyd 07ebd1e
Merge branch 'main' into cognifloyd/nfpm
cognifloyd f8afb71
nfpm: Add OctalInt representer to SafeDumper
cognifloyd 15910a8
nfpm: Add field_set.extension for use in tests
cognifloyd 3989b13
nfpm: Use full path for src/source
cognifloyd f8b1dd0
nfpm: Fix file mode parsing with "-" char
cognifloyd 4d1e0a1
nfpm: Fix default mtime to include Z (required by nFPM)
cognifloyd 13ca4fa
nfpm: Fix _SrcDstSequenceField validation
cognifloyd 61c3058
nfpm: Expand integration tests
cognifloyd b4d8fa2
nfpm: Add normalized_value property to scripts field
cognifloyd 29f95d9
nfpm: Add dependency inference for scripts field
cognifloyd 781c2e0
nfpm: fmt
cognifloyd dda934b
nfpm: add missing 'from future import __annotations__'
cognifloyd 91e1bf7
nfpm: add package scripts dep inference test
cognifloyd a148786
nfpm: fmt
cognifloyd c1fce24
nfpm: add filemode calculation tests
cognifloyd 1c59deb
nfpm: add test for populate_nfpm_content_sandbox rule
cognifloyd 2c36f24
nfpm: reorder test cases in test_populate_nfpm_content_sandbox
cognifloyd eb3991f
nfpm: add test codegen cases to test_populate_nfpm_content_sandbox
cognifloyd f962bac
nfpm: add package build cases to test_populate_nfpm_content_sandbox
cognifloyd ea9bbfd
nfpm: minor refactor
cognifloyd bd9d948
nfpm: use utf-8 explicitly
cognifloyd 1f5c137
nfpm: fmt
cognifloyd 63b89b2
nfpm: add test for generate_nfpm_yaml rule
cognifloyd 937e809
nfpm: add release notes and misc docstring updates
cognifloyd 03225f2
Merge branch 'main' into cognifloyd/nfpm
cognifloyd 4c1fbe4
nfpm: update to nFPM v2.38.0
cognifloyd bca1389
nfpm: migrate-call-by-name on newer code
cognifloyd 99f900b
nfpm: drop old TODOs
cognifloyd 32b6ab1
nfpm: add mtime field to nfpm_*_package targets
cognifloyd 5d0ce9c
nfpm: add [nfpm].default_mtime option
cognifloyd 99eee41
nfpm: drop apk, archlinux, rpm; keep only deb
cognifloyd d41a201
nfpm: drop deb packager to focus on core bits
cognifloyd 3d2a19c
nfpm: simplify OctalInt registration in yaml.SafeDumper
cognifloyd 425480c
nfpm: use type[...] instead of Type[...] in type hints
cognifloyd 242a47b
nfpm: use UPPER_SNAKE for constants
cognifloyd 74e90b2
nfpm: use frozenset for _FILEMODE_CHARS constant
cognifloyd 89215a8
Add StringStringTupleSequenceField
cognifloyd d97c1c4
Make more generic TupleSequenceField instead of StringStringTupleSequ…
cognifloyd 78c383a
Merge branch 'main' into cognifloyd/nfpm
cognifloyd 1f61628
Add TupleSequenceField
cognifloyd 9a7c390
Add TupleSequenceField test
cognifloyd 726c62a
nfpm: skip tests that can't run w/o nfpm_*_targets
cognifloyd 3a329fa
Merge branch 'cognifloyd/tuple-sequence-field' into cognifloyd/nfpm
cognifloyd eb958e0
nfpm: drop more deb-references from docstrings
cognifloyd 3e1a88d
nfpm: drop tests that cannot run w/o nfpm_*_package targets
cognifloyd 8ff5209
nfpm: refactor nfpm content dict calculation to use field sets
cognifloyd cbdb47c
nfpm: finish logic around nfpm content field sets
cognifloyd a6c4655
nfpm: fix usage of FieldSetsPerTarget
cognifloyd dd4b083
Merge branch 'main' into cognifloyd/nfpm
cognifloyd 22da064
nfpm: style uppercase constants
cognifloyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
python_sources() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
"""Create apk, archlinux, deb, and rpm system packages. | ||
|
||
See https://nfpm.goreleaser.com/ for details on nFPM, including these descriptions of it: | ||
- nFPM is "effing simple package management" | ||
- "nFPM is Not FPM--a zero dependencies, simple deb, rpm, apk, and arch linux packager written in Go." | ||
""" # TODO: include ipk in this docstring once support is added. | ||
|
||
from pants.backend.nfpm.dependency_inference import rules as nfpm_dependency_inference_rules | ||
from pants.backend.nfpm.rules import rules as nfpm_rules | ||
from pants.backend.nfpm.subsystem import rules as nfpm_subsystem_rules | ||
from pants.backend.nfpm.target_types import target_types as nfpm_target_types | ||
from pants.backend.nfpm.target_types_rules import rules as nfpm_target_type_rules | ||
|
||
|
||
def target_types(): | ||
return nfpm_target_types() | ||
|
||
|
||
def rules(): | ||
return [ | ||
*nfpm_subsystem_rules(), | ||
*nfpm_target_type_rules(), | ||
*nfpm_dependency_inference_rules(), | ||
*nfpm_rules(), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
python_sources() | ||
|
||
python_tests(name="tests") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TypedDict | ||
|
||
import yaml | ||
|
||
|
||
class OctalInt(int): | ||
# noinspection PyUnusedLocal | ||
@staticmethod | ||
def represent_octal(dumper: yaml.representer.BaseRepresenter, data: int) -> yaml.Node: | ||
# YAML 1.2 octal: 0o7777 (py: f"0o{data:o}" or f"{data:#o}" or oct(data)) | ||
# YAML 1.1 octal: 07777 (py: f"0{data:o}") | ||
# Both octal reprs are supported by `gopkg.in/yaml.v3` which parses YAML in nFPM. | ||
# See: https://github.com/go-yaml/yaml/tree/v3.0.1#compatibility | ||
# PyYAML only supports reading YAML 1.1, so we use that. | ||
return yaml.ScalarNode("tag:yaml.org,2002:int", f"0{data:o}") | ||
|
||
|
||
# This is an unfortunate import-time side effect: PyYAML does registration globally. | ||
yaml.SafeDumper.add_representer(OctalInt, OctalInt.represent_octal) | ||
|
||
|
||
class NfpmFileInfo(TypedDict, total=False): | ||
# nFPM allows these to be None or missing. | ||
# Each of the fields has a default, so in practice, these won't be None. | ||
owner: str | None | ||
group: str | None | ||
mode: OctalInt | None | ||
mtime: str | None | ||
|
||
|
||
class NfpmContent(TypedDict, total=False): | ||
src: str | ||
dst: str | ||
type: str | ||
packager: str | ||
file_info: NfpmFileInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
|
||
from pants.backend.nfpm.fields.scripts import NfpmPackageScriptsField | ||
from pants.base.glob_match_error_behavior import GlobMatchErrorBehavior | ||
from pants.base.specs import FileLiteralSpec, RawSpecs | ||
from pants.engine.internals.specs_rules import resolve_addresses_from_raw_specs | ||
from pants.engine.rules import collect_rules, rule | ||
from pants.engine.target import FieldSet, InferDependenciesRequest, InferredDependencies | ||
from pants.engine.unions import UnionRule | ||
from pants.util.logging import LogLevel | ||
|
||
|
||
@dataclass(frozen=True) | ||
class NfpmPackageScriptsInferenceFieldSet(FieldSet): | ||
required_fields = (NfpmPackageScriptsField,) | ||
|
||
scripts: NfpmPackageScriptsField | ||
|
||
|
||
class InferNfpmPackageScriptsDependencies(InferDependenciesRequest): | ||
infer_from = NfpmPackageScriptsInferenceFieldSet | ||
|
||
|
||
@rule( | ||
desc=f"Infer dependencies based on nfpm `{NfpmPackageScriptsField.alias}` field.", | ||
level=LogLevel.DEBUG, | ||
) | ||
async def infer_nfpm_package_scripts_dependencies( | ||
request: InferNfpmPackageScriptsDependencies, | ||
) -> InferredDependencies: | ||
scripts: NfpmPackageScriptsField = request.field_set.scripts | ||
scripts_paths = tuple(scripts.normalized_value.values()) | ||
if not scripts_paths: | ||
return InferredDependencies(()) | ||
|
||
resolved_scripts_addresses = await resolve_addresses_from_raw_specs( | ||
RawSpecs( | ||
file_literals=tuple(FileLiteralSpec(script_path) for script_path in scripts_paths), | ||
unmatched_glob_behavior=GlobMatchErrorBehavior.error, | ||
description_of_origin="nfpm package scripts field dependency inference", | ||
) | ||
) | ||
|
||
return InferredDependencies(resolved_scripts_addresses) | ||
|
||
|
||
def rules(): | ||
return [ | ||
*collect_rules(), | ||
UnionRule(InferDependenciesRequest, InferNfpmPackageScriptsDependencies), | ||
] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you plan on having an
example-nfpm
repository users could look at? No need to develop it now or even reference it if you have one, but might be good to keep in mind as a follow-on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't thought about that. I think a section in the documentation might be useful as well, but I don't know when I can tackle something like that.