Skip to content

Commit 7f8c864

Browse files
authored
Badges (#4)
* Minor adjustments * Refactor badges * Fix osi behavior * Reposition vhs script * Add debug log for whitelist build * Add files * Fix
1 parent d1fdf7a commit 7f8c864

File tree

8 files changed

+78
-30
lines changed

8 files changed

+78
-30
lines changed

rerender_vhs.sh .github/assets/demo/rerender_vhs.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
# Make sure you are in an environment with vhs installed
66

77
export PS1="> "
8-
vhs .github/assets/demo/demo-light.tape
9-
vhs .github/assets/demo/demo-dark.tape
8+
vhs demo-light.tape
9+
vhs demo-dark.tape

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2024, Paul Mueller
3+
Copyright 2023 QuantCo Inc., Paul Müller, Pavel Zwerschke
44

55
Redistribution and use in source and binary forms, with or without
66
modification, are permitted provided that the following conditions are met:

README.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66

77
<div align="center">
88

9-
![Cargo Build & Test](https://github.com/quantco/conda-deny/actions/workflows/ci.yml/badge.svg)
9+
[![License][license-badge]](LICENSE)
10+
[![CI Status][ci-badge]][ci]
1011
![Binary Build](https://github.com/quantco/conda-deny/actions/workflows/build.yml/badge.svg)
11-
<!-- ![Conda Package](https://github.com/quantco/conda-deny/actions/workflows/package.yml/badge.svg) -->
12-
[![codecov](https://codecov.io/gh/Quantco/conda-deny/graph/badge.svg?token=uixrZFJln7)](https://codecov.io/gh/Quantco/conda-deny)
12+
[![Conda Platform][conda-badge]][conda-url]
13+
[![codecov](https://codecov.io/gh/Quantco/conda-deny/graph/badge.svg)](https://codecov.io/gh/Quantco/conda-deny)
14+
15+
[license-badge]: https://img.shields.io/github/license/quantco/conda-deny?style=flat-square
16+
[ci-badge]: https://img.shields.io/github/actions/workflow/status/quantco/conda-deny/ci.yml?style=flat-square&branch=main
17+
[ci]: https://github.com/quantco/conda-deny/actions/
18+
[conda-badge]: https://img.shields.io/conda/vn/conda-forge/conda-deny?style=flat-square
19+
[conda-url]: https://prefix.dev/channels/conda-forge/packages/conda-deny
1320

1421
</div>
1522

@@ -47,7 +54,7 @@ The tool expects a configuration in the following format:
4754
#--------------------------------------------------------
4855
# General setup options:
4956
#--------------------------------------------------------
50-
license-whitelist = "https://raw.githubusercontent.com/PaulKMueller/conda-deny-test/refs/heads/main/conda-deny-license_whitelist.toml" # or ["license_whitelist.toml", "other_license_whitelist.toml"]
57+
license-whitelist = "https://raw.githubusercontent.com/QuantCo/conda-deny/main/tests/test_remote_base_configs/conda-deny-license_whitelist.toml" # or ["license_whitelist.toml", "other_license_whitelist.toml"]
5158
platform = "linux-64" # or ["linux-64", "osx-arm64"]
5259
environment = "default" # or ["default", "py39", "py310", "prod"]
5360
lockfile = "environment/pixi.lock" # or ["environment1/pixi.lock", "environment2/pixi.lock"]

src/conda_deny_config.rs

+14
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ impl CondaDenyConfig {
116116
None => vec![],
117117
}
118118
}
119+
120+
pub fn empty() -> Self {
121+
CondaDenyConfig {
122+
tool: Tool {
123+
conda_deny: CondaDeny {
124+
license_whitelist: None,
125+
platform_spec: None,
126+
environment_spec: None,
127+
lockfile_spec: None,
128+
},
129+
},
130+
path: "".to_string(),
131+
}
132+
}
119133
}
120134

121135
#[cfg(test)]

src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ pub fn check_license_infos(check_input: CheckInput) -> Result<CheckOutput> {
4545
let (conda_deny_config, cli_lockfiles, cli_platforms, cli_environment, conda_prefixes, osi) =
4646
check_input;
4747

48-
let license_whitelist = build_license_whitelist(conda_deny_config)
49-
.with_context(|| "Building the license whitelist failed.")?;
50-
5148
if conda_prefixes.is_empty() {
5249
let mut license_infos = LicenseInfos::get_license_infos_from_config(
5350
conda_deny_config,
@@ -64,6 +61,8 @@ pub fn check_license_infos(check_input: CheckInput) -> Result<CheckOutput> {
6461
debug!("Checking licenses for OSI compliance");
6562
Ok(license_infos.osi_check())
6663
} else {
64+
let license_whitelist = build_license_whitelist(conda_deny_config)
65+
.with_context(|| "Building the license whitelist failed.")?;
6766
debug!("Checking licenses against specified whitelist");
6867
Ok(license_infos.check(&license_whitelist))
6968
}
@@ -75,6 +74,8 @@ pub fn check_license_infos(check_input: CheckInput) -> Result<CheckOutput> {
7574
debug!("Checking for OSI licenses");
7675
Ok(conda_prefixes_license_infos.osi_check())
7776
} else {
77+
let license_whitelist = build_license_whitelist(conda_deny_config)
78+
.with_context(|| "Building the license whitelist failed.")?;
7879
debug!("Checking licenses against specified whitelist");
7980
Ok(conda_prefixes_license_infos.check(&license_whitelist))
8081
}

src/license_whitelist.rs

+3
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ pub fn build_license_whitelist(
248248

249249
if final_license_whitelist.safe_licenses.is_empty() {
250250
anyhow::bail!("Your license whitelist is empty.");
251+
} else {
252+
debug!("License whitelist built successfully.");
251253
}
252254
Ok(final_license_whitelist)
253255
}
@@ -277,6 +279,7 @@ mod tests {
277279
#[test]
278280
fn test_fetch_safe_licenses_success() {
279281
let reader = MockReader;
282+
// TODO: Change this to "https://raw.githubusercontent.com/QuantCo/conda-deny/main/tests/test_remote_base_configs/conda-deny-license_whitelist.toml"
280283
let result = fetch_safe_licenses("https://raw.githubusercontent.com/PaulKMueller/conda-deny-test/main/conda-deny-license_whitelist.toml", &reader)
281284
.unwrap();
282285

src/main.rs

+33-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use anyhow::{Context, Result};
22
use clap::Parser;
3+
use colored::Colorize;
34
use conda_deny::cli::{Cli, Commands};
45
use conda_deny::conda_deny_config::CondaDenyConfig;
56
use conda_deny::{check_license_infos, format_check_output, list};
6-
use log::{debug, info};
7+
use log::debug;
78

89
fn main() -> Result<()> {
910
let cli = Cli::parse();
@@ -12,28 +13,39 @@ fn main() -> Result<()> {
1213
.filter_level(cli.verbose.log_level_filter())
1314
.init();
1415

15-
let config = if let Some(config_path) = cli.config {
16-
CondaDenyConfig::from_path(config_path.as_str())
17-
.with_context(|| format!("Failed to parse config file {}", config_path))?
18-
} else {
19-
match CondaDenyConfig::from_path("pixi.toml")
20-
.with_context(|| "Failed to parse config file pixi.toml")
21-
{
22-
Ok(config) => {
23-
debug!("Successfully loaded config from pixi.toml");
24-
config
25-
}
26-
Err(e) => {
27-
debug!(
16+
let osi = match cli.command {
17+
Commands::Check { osi, .. } => osi,
18+
_ => false,
19+
};
20+
21+
let mut config = CondaDenyConfig::empty();
22+
23+
if !osi {
24+
config = if let Some(config_path) = cli.config {
25+
CondaDenyConfig::from_path(config_path.as_str())
26+
.with_context(|| format!("Failed to parse config file {}", config_path))?
27+
} else {
28+
match CondaDenyConfig::from_path("pixi.toml")
29+
.with_context(|| "Failed to parse config file pixi.toml")
30+
{
31+
Ok(config) => {
32+
debug!("Successfully loaded config from pixi.toml");
33+
config
34+
}
35+
Err(e) => {
36+
debug!(
2837
"Error parsing config file: pixi.toml: {}. Attempting to use pyproject.toml instead...",
2938
e
3039
);
31-
CondaDenyConfig::from_path("pyproject.toml")
32-
.context(e)
33-
.with_context(|| "Failed to parse config file pyproject.toml")?
40+
CondaDenyConfig::from_path("pyproject.toml")
41+
.context(e)
42+
.with_context(|| "Failed to parse config file pyproject.toml")?
43+
}
3444
}
35-
}
36-
};
45+
};
46+
} else {
47+
debug!("Skipping config file parsing for OSI compliance check. Your {} section will be ignored.", "[tool.conda-deny]".yellow());
48+
}
3749

3850
let conda_prefixes = cli.prefix.unwrap_or_default();
3951

@@ -56,9 +68,10 @@ fn main() -> Result<()> {
5668
let mut locks_to_check = cli_lockfiles.clone();
5769
locks_to_check.push("pixi.lock".to_string());
5870
debug!("Checking pixi lockfiles: {:?}", locks_to_check);
71+
debug!("Checking for OSI compliance: {}", osi);
5972

6073
if include_safe {
61-
info!("Including safe dependencies in output");
74+
debug!("Including safe dependencies in output");
6275
}
6376

6477
let check_input = (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[tool.conda-deny]
2+
safe-licenses = [
3+
"MIT",
4+
"Unlicense",
5+
"WTFPL",
6+
"Apache-2.0"
7+
]
8+
ignore-packages = [
9+
{package="_libgcc_mutex"},
10+
]

0 commit comments

Comments
 (0)