Skip to content

Commit

Permalink
Add support for custom distinfo files (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
zooba authored Sep 24, 2024
1 parent 0b79b7b commit 4e3ebad
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,34 @@ PACKAGE = Package("my_package", P1)
PACKAGE.members.append(P2)
```

## Anonymous packages

To install files directly into the target location (often ``site-packages``),
use a top-level package with empty name. Other packages may be nested within
this package as normal.

```python
PACKAGE = Package(
"",
File("module.pth"),
Package("module", ...),
)
```

## Custom dist-info files

To install files into the generated `.dist-info` directory, specify the
``IncludeInDistinfo=True`` option. This will move the file in the built wheel,
while reading it from its usual location. It will be included in the sdist at
its source location.

```python
PACKAGE = Package(
"module",
File("entry_points.txt", IncludeInDistinfo=True),
)
```

## Wildcard handling

Files can be added recursively using wildcard operators. These are
Expand Down
4 changes: 4 additions & 0 deletions pymsbuild/_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def __init__(self, output_dir=None):
self.ext_suffix = None
self.platform = None
self.build_number = None
self.sdist_name = None
self.wheel_name = None
self.distinfo_name = None
self.python_cflags = None
self.python_ldflags = None
self.python_includes = None
Expand Down Expand Up @@ -309,6 +312,7 @@ def build(self, **properties):
properties.setdefault("OutDir", self.build_dir)
properties.setdefault("IntDir", self.temp_dir)
properties.setdefault("LayoutDir", self.layout_dir)
properties.setdefault("DistinfoDir", (self.metadata_dir / self.distinfo_name))
properties.setdefault("DefaultExtSuffix", self.ext_suffix)
properties.setdefault("PythonConfig", self.python_config)
properties.setdefault("PythonIncludes", self.python_includes)
Expand Down
30 changes: 26 additions & 4 deletions pymsbuild/targets/common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,44 @@
<Target Name="_GetSdistFilesFromProjects" DependsOnTargets="_GetSdistFilesFromEachProject">
</Target>

<Target Name="GetPackageFiles" DependsOnTargets="$(GetPackageFilesTargets)" Returns="@(PyMSBuild_PackageFiles)">
<Target Name="_GetDistinfoFiles" Returns="@(PyMSBuild_PackageFiles)" Condition="$(DistinfoDir) != ''">
<ItemGroup>
<_WithMetadata Remove="@(_WithMetadata)" />

<AllSourceFiles Include="@(Content);@(None)" />

<AllSourceFiles Remove="@(_ExcludeFile)" />
<_WithMetadata Include="@(AllSourceFiles)" Condition="%(AllSourceFiles.IncludeInWheel) == 'true'">
<_WithMetadata Include="@(AllSourceFiles)" Condition="%(AllSourceFiles.IncludeInDistinfo) == 'true'">
<Name Condition="%(AllSourceFiles.Name) == ''">%(Filename)%(Extension)</Name>
</_WithMetadata>
<_WithMetadata>
<TargetDir Condition="%(_WithMetadata.TargetDir) == ''">$([msbuild]::EnsureTrailingSlash($([System.IO.Path]::GetDirectoryName(`%(_WithMetadata.Name)`))))</TargetDir>
<TargetName Condition="%(_WithMetadata.TargetName) == ''">$([System.IO.Path]::GetFileNameWithoutExtension(`%(_WithMetadata.Name)`))</TargetName>
<TargetExt Condition="%(_WithMetadata.TargetExt) == ''">$([System.IO.Path]::GetExtension(%(_WithMetadata.Name)))</TargetExt>
</_WithMetadata>
<PyMSBuild_PackageFiles Include="@(_WithMetadata)" Condition="'%(IncludeInWheel)' == true" />
<_WithMetadata>
<Destination>$([msbuild]::EnsureTrailingSlash($([msbuild]::EnsureTrailingSlash($(DistinfoDir)))%(TargetDir)))%(TargetName)%(TargetExt)</Destination>
</_WithMetadata>
<PyMSBuild_PackageFiles Include="@(_WithMetadata)" Condition="'%(_WithMetadata.IncludeInDistinfo)' == true" />
</ItemGroup>
</Target>

<Target Name="GetPackageFiles" DependsOnTargets="$(GetPackageFilesTargets);_GetDistinfoFiles" Returns="@(PyMSBuild_PackageFiles)">
<ItemGroup>
<_WithMetadata Remove="@(_WithMetadata)" />

<AllSourceFiles Include="@(Content);@(None)" />

<AllSourceFiles Remove="@(_ExcludeFile)" />
<_WithMetadata Include="@(AllSourceFiles)" Condition="%(AllSourceFiles.IncludeInWheel) == 'true' and %(AllSourceFiles.IncludeInDistinfo) != 'true'">
<Name Condition="%(AllSourceFiles.Name) == ''">%(Filename)%(Extension)</Name>
</_WithMetadata>
<_WithMetadata>
<TargetDir Condition="%(_WithMetadata.TargetDir) == ''">$([msbuild]::EnsureTrailingSlash($([System.IO.Path]::GetDirectoryName(`%(_WithMetadata.Name)`))))</TargetDir>
<TargetName Condition="%(_WithMetadata.TargetName) == ''">$([System.IO.Path]::GetFileNameWithoutExtension(`%(_WithMetadata.Name)`))</TargetName>
<TargetExt Condition="%(_WithMetadata.TargetExt) == ''">$([System.IO.Path]::GetExtension(%(_WithMetadata.Name)))</TargetExt>
</_WithMetadata>
<PyMSBuild_PackageFiles Include="@(_WithMetadata)" Condition="'%(_WithMetadata.IncludeInWheel)' == true" />
</ItemGroup>
</Target>

Expand Down Expand Up @@ -101,7 +123,7 @@
<TargetName Condition="%(_WithMetadata.TargetName) == ''">$([System.IO.Path]::GetFileNameWithoutExtension(`%(_WithMetadata.Name)`))</TargetName>
<TargetExt Condition="%(_WithMetadata.TargetExt) == ''">$([System.IO.Path]::GetExtension(%(_WithMetadata.Name)))</TargetExt>
</_WithMetadata>
<PyMSBuild_LayoutFiles Include="@(_WithMetadata)" Condition="'%(IncludeInLayout)' == true" />
<PyMSBuild_LayoutFiles Include="@(_WithMetadata)" Condition="'%(_WithMetadata.IncludeInLayout)' == true" />
</ItemGroup>
</Target>

Expand Down
6 changes: 3 additions & 3 deletions pymsbuild/targets/package.targets
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<ItemGroup>
<_DistFiles Remove="@(_DistFiles)" />
<_DistFiles Include="@(PyMSBuild_PackageFiles)">
<Destination>$([msbuild]::EnsureTrailingSlash($([msbuild]::EnsureTrailingSlash($(LayoutDir)))%(TargetDir)))%(TargetName)%(TargetExt)</Destination>
<Destination Condition="%(PyMSBuild_PackageFiles.Destination) == ''">$([msbuild]::EnsureTrailingSlash($([msbuild]::EnsureTrailingSlash($(LayoutDir)))%(TargetDir)))%(TargetName)%(TargetExt)</Destination>
</_DistFiles>
</ItemGroup>
</Target>
Expand All @@ -96,7 +96,7 @@
<ItemGroup>
<_DistFiles Remove="@(_DistFiles)" />
<_DistFiles Include="@(PyMSBuild_SDistFiles)">
<Destination>$([msbuild]::EnsureTrailingSlash($(LayoutDir)))%(RelativeSource)</Destination>
<Destination Condition="%(PyMSBuild_SDistFiles.Destination) == ''">$([msbuild]::EnsureTrailingSlash($(LayoutDir)))%(RelativeSource)</Destination>
</_DistFiles>
</ItemGroup>
</Target>
Expand All @@ -105,7 +105,7 @@
<ItemGroup>
<_DistFiles Remove="@(_DistFiles)" />
<_DistFiles Include="@(PyMSBuild_LayoutFiles)" Condition="%(IncludeInLayout) == 'true'">
<Destination>$([msbuild]::EnsureTrailingSlash($([msbuild]::EnsureTrailingSlash($(_SourceLayoutDir)))%(TargetDir)))%(TargetName)%(TargetExt)</Destination>
<Destination Condition="%(PyMSBuild_LayoutFiles.Destination) == ''">$([msbuild]::EnsureTrailingSlash($([msbuild]::EnsureTrailingSlash($(_SourceLayoutDir)))%(TargetDir)))%(TargetName)%(TargetExt)</Destination>
</_DistFiles>
<!-- Remove anything that is being copied directly from the source tree -->
<_Removing Include="@(_DistFiles)" Condition="%(FullPath) == %(Destination)" />
Expand Down

0 comments on commit 4e3ebad

Please sign in to comment.