fix(package): Ignore setup.cfg attr: and file: (#3054)
The setup.cfg version key allows "attr:" and "file:" directives to load the actual value from elsewhere [1]. Treat these as if no version was found, since the text of the directive isn't the version number we're after. [1]: https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html#specifying-values
This commit is contained in:
parent
5d0a38aca3
commit
bbb8d3c357
|
@ -84,7 +84,11 @@ fn get_setup_cfg_version(context: &Context, config: &PackageConfig) -> Option<St
|
|||
let ini = Ini::load_from_str(&file_contents).ok()?;
|
||||
let raw_version = ini.get_from(Some("metadata"), "version")?;
|
||||
|
||||
format_version(raw_version, config.version_format)
|
||||
if raw_version.starts_with("attr:") || raw_version.starts_with("file:") {
|
||||
None
|
||||
} else {
|
||||
format_version(raw_version, config.version_format)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_gradle_version(context: &Context, config: &PackageConfig) -> Option<String> {
|
||||
|
@ -613,6 +617,34 @@ license = "MIT"
|
|||
project_dir.close()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_setup_cfg_version_attr() -> io::Result<()> {
|
||||
let config_name = "setup.cfg";
|
||||
let config_content = String::from(
|
||||
"[metadata]
|
||||
version = attr: mymod.__version__",
|
||||
);
|
||||
|
||||
let project_dir = create_project_dir()?;
|
||||
fill_config(&project_dir, config_name, Some(&config_content))?;
|
||||
expect_output(&project_dir, None, None);
|
||||
project_dir.close()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_setup_cfg_version_file() -> io::Result<()> {
|
||||
let config_name = "setup.cfg";
|
||||
let config_content = String::from(
|
||||
"[metadata]
|
||||
version = file: version.txt",
|
||||
);
|
||||
|
||||
let project_dir = create_project_dir()?;
|
||||
fill_config(&project_dir, config_name, Some(&config_content))?;
|
||||
expect_output(&project_dir, None, None);
|
||||
project_dir.close()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_gradle_version_single_quote() -> io::Result<()> {
|
||||
let config_name = "build.gradle";
|
||||
|
|
Loading…
Reference in New Issue