Skip to content
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 ignore_git_ignore flag to build options #1253

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ pub struct BuildContext {
pub editable: bool,
/// Cargo build options
pub cargo_options: CargoOptions,
/// Ignore `.gitignore` files when including files for the Python part of a mixed project
pub ignore_git_ignore: bool,
}

/// The wheel file location and its Python version tag (e.g. `py3`).
Expand Down Expand Up @@ -474,6 +476,7 @@ impl BuildContext {
None,
&self.target,
self.editable,
self.ignore_git_ignore,
)
.context("Failed to add the files to the wheel")?;

Expand Down Expand Up @@ -545,6 +548,7 @@ impl BuildContext {
Some(python_interpreter),
&self.target,
self.editable,
self.ignore_git_ignore,
)
.context("Failed to add the files to the wheel")?;

Expand Down Expand Up @@ -663,6 +667,7 @@ impl BuildContext {
&artifact.path,
&self.interpreter[0].executable,
self.editable,
self.ignore_git_ignore,
)?;

self.add_pth(&mut writer)?;
Expand Down Expand Up @@ -763,7 +768,7 @@ impl BuildContext {
bail!("Sorry, adding python code to a wasm binary is currently not supported")
}
if !self.editable {
write_python_part(&mut writer, python_module)
write_python_part(&mut writer, python_module, self.ignore_git_ignore)
.context("Failed to add the python module to the package")?;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ pub struct BuildOptions {
#[arg(long = "skip-auditwheel")]
pub skip_auditwheel: bool,

/// Ignore `.gitignore` files when including files for the Python part of a mixed project
#[arg(long = "ignore-git-ignore")]
pub ignore_git_ignore: bool,

/// For manylinux targets, use zig to ensure compliance for the chosen manylinux version
///
/// Default to manylinux2014/manylinux_2_17 if you do not specify an `--compatibility`
Expand Down Expand Up @@ -597,6 +601,8 @@ impl BuildOptions {
let strip = pyproject.map(|x| x.strip()).unwrap_or_default() || strip;
let skip_auditwheel =
pyproject.map(|x| x.skip_auditwheel()).unwrap_or_default() || self.skip_auditwheel;
let ignore_git_ignore =
pyproject.map(|x| x.ignore_git_ignore()).unwrap_or_default() || self.ignore_git_ignore;
let platform_tags = if self.platform_tag.is_empty() {
let compatibility = pyproject
.and_then(|x| {
Expand Down Expand Up @@ -721,6 +727,7 @@ impl BuildOptions {
universal2,
editable,
cargo_options,
ignore_git_ignore,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions src/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub fn develop(
bindings,
out: Some(wheel_dir.path().to_path_buf()),
skip_auditwheel: false,
ignore_git_ignore: false,
zig: false,
universal2: false,
cargo: CargoOptions {
Expand Down
13 changes: 10 additions & 3 deletions src/module_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ pub fn write_bindings_module(
python_interpreter: Option<&PythonInterpreter>,
target: &Target,
editable: bool,
ignore_git_ignore: bool,
) -> Result<()> {
let ext_name = &project_layout.extension_name;
let so_filename = match python_interpreter {
Expand Down Expand Up @@ -664,7 +665,7 @@ pub fn write_bindings_module(
target.display()
))?;
} else {
write_python_part(writer, python_module)
write_python_part(writer, python_module, ignore_git_ignore)
.context("Failed to add the python module to the package")?;

let relative = project_layout
Expand Down Expand Up @@ -714,14 +715,15 @@ pub fn write_cffi_module(
artifact: &Path,
python: &Path,
editable: bool,
ignore_git_ignore: bool,
) -> Result<()> {
let cffi_declarations = generate_cffi_declarations(crate_dir, target_dir, python)?;

let module;

if let Some(python_module) = &project_layout.python_module {
if !editable {
write_python_part(writer, python_module)
write_python_part(writer, python_module, ignore_git_ignore)
.context("Failed to add the python module to the package")?;
}

Expand Down Expand Up @@ -848,8 +850,13 @@ if __name__ == '__main__':
pub fn write_python_part(
writer: &mut impl ModuleWriter,
python_module: impl AsRef<Path>,
ignore_git_ignore: bool,
) -> Result<()> {
for absolute in WalkBuilder::new(&python_module).hidden(false).build() {
for absolute in WalkBuilder::new(&python_module)
.git_ignore(!ignore_git_ignore)
.hidden(false)
.build()
{
let absolute = absolute?.into_path();
let relative = absolute
.strip_prefix(python_module.as_ref().parent().unwrap())
Expand Down
9 changes: 9 additions & 0 deletions src/pyproject_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct ToolMaturin {
skip_auditwheel: bool,
#[serde(default)]
strip: bool,
#[serde(default)]
ignore_git_ignore: bool,
/// The directory with python module, contains `<module_name>/__init__.py`
python_source: Option<PathBuf>,
/// Path to the wheel directory, defaults to `<module_name>.data`
Expand Down Expand Up @@ -142,6 +144,13 @@ impl PyProjectToml {
self.maturin()?.manifest_path.as_deref()
}

/// Returns the value of `[tool.maturin.ignore_git_ignore]` in pyproject.toml
pub fn ignore_git_ignore(&self) -> bool {
self.maturin()
.map(|maturin| maturin.ignore_git_ignore)
.unwrap_or_default()
}

/// Having a pyproject.toml without a version constraint is a bad idea
/// because at some point we'll have to do breaking changes and then source
/// distributions would break
Expand Down
3 changes: 3 additions & 0 deletions tests/cmd/build.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Options:
--skip-auditwheel
Don't check for manylinux compliance

--ignore-git-ignore
Ignore `.gitignore` files when including files for the Python part of a mixed project

--zig
For manylinux targets, use zig to ensure compliance for the chosen manylinux version

Expand Down
3 changes: 3 additions & 0 deletions tests/cmd/publish.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ Options:
--skip-auditwheel
Don't check for manylinux compliance

--ignore-git-ignore
Ignore `.gitignore` files when including files for the Python part of a mixed project

--zig
For manylinux targets, use zig to ensure compliance for the chosen manylinux version

Expand Down