Skip to content

Commit

Permalink
Allow CC-BY, CC-BY-SA, or CC0 licenses
Browse files Browse the repository at this point in the history
Closes #1511
  • Loading branch information
reknih committed Jan 7, 2025
1 parent 8208183 commit e98885f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ Required for submissions to this repository:
address, homepage, or GitHub handle in angle brackets. The latter must start
with an `@` character, and URLs must start with `http://` or `https://`.
- `license`: The package's license. Must contain a valid SPDX-2 expression
describing one or multiple [OSI-approved][OSI] licenses.
describing one or multiple licenses that are either [OSI-approved][OSI]
licenses or a version of CC-BY, CC-BY-SA, or CC0. We recommend you do not
license your package using a Creative Commons license unless it is a
derivative work of a CC-BY-SA-licensed work or if it is not primarily code,
but content or data. In most other cases, [a free/open license specific to
software is better suited for Typst packages](https://creativecommons.org/faq/#can-i-apply-a-creative-commons-license-to-software).
- `description`: A short description of the package. Double-check this for
grammar and spelling mistakes as it will appear in the [package list][list].

Expand Down
26 changes: 20 additions & 6 deletions bundler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ toml = { version = "0.8", default-features = false, features = ["parse"] }
unicode-ident = "1.0.12"
unscanny = "0.1.0"
walkdir = "2"
regex = "1.11.1"
once_cell = "1.20.2"
22 changes: 19 additions & 3 deletions bundler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use anyhow::{bail, Context};
use image::codecs::webp::{WebPEncoder, WebPQuality};
use image::imageops::FilterType;
use semver::Version;
use spdx::LicenseId;
use typst_syntax::package::{PackageInfo, PackageManifest, TemplateInfo, UnknownFields};
use unicode_ident::{is_xid_continue, is_xid_start};

Expand All @@ -25,6 +26,13 @@ use self::timestamp::determine_timestamps;
const DIST: &str = "dist";
const THUMBS_DIR: &str = "thumbnails";

macro_rules! regex {
($re:literal $(,)?) => {{
static RE: once_cell::sync::OnceCell<regex::Regex> = once_cell::sync::OnceCell::new();
RE.get_or_init(|| regex::Regex::new($re).unwrap())
}};
}

fn main() -> anyhow::Result<()> {
println!("Starting bundling.");

Expand Down Expand Up @@ -106,7 +114,7 @@ fn main() -> anyhow::Result<()> {
determine_timestamps(&paths, &mut index)?;

// Sort the index.
index.sort_by_key(|info| (info.package.name.clone(), info.package.version.clone()));
index.sort_by_key(|info| (info.package.name.clone(), info.package.version));

println!("Writing index.");
fs::write(
Expand Down Expand Up @@ -247,8 +255,11 @@ fn parse_manifest(path: &Path, namespace: &str) -> anyhow::Result<PackageManifes
.id()
.context("license must not contain a referencer")?;

if !id.is_osi_approved() {
bail!("license is not OSI approved: {}", id.full_name);
if !id.is_osi_approved() && !is_allowed_cc(id) {
bail!(
"license is neither OSI approved nor allowed CC license: {}",
id.full_name
);
}
}

Expand Down Expand Up @@ -454,3 +465,8 @@ fn is_id_start(c: char) -> bool {
fn is_id_continue(c: char) -> bool {
is_xid_continue(c) || c == '_' || c == '-'
}

// Check that a license is any version of CC-BY, CC-BY-SA, or CC0.
fn is_allowed_cc(license: LicenseId) -> bool {
regex!(r"^CC(-(BY(-SA)?)|0)-[0-9]\.[0-9](-[A-Z]+)?$").is_match(license.name)
}

0 comments on commit e98885f

Please sign in to comment.