mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
feat(project): add PEP 621 support for Python projects
BREAKING CHANGE: this replaces the `poetry` `.Type` value with `python`. Segment templates matching the `poetry` type will need to be updated to match the new `python` type.
This commit is contained in:
parent
bcebcb55a2
commit
9e470e5205
|
@ -33,9 +33,10 @@ type CargoTOML struct {
|
|||
Package ProjectData
|
||||
}
|
||||
|
||||
// Python Poetry package
|
||||
// Python package
|
||||
type PyProjectTOML struct {
|
||||
Tool PyProjectToolTOML
|
||||
Project ProjectData
|
||||
Tool PyProjectToolTOML
|
||||
}
|
||||
|
||||
type PyProjectToolTOML struct {
|
||||
|
@ -95,9 +96,9 @@ func (n *Project) Init(props properties.Properties, env platform.Environment) {
|
|||
Fetcher: n.getCargoPackage,
|
||||
},
|
||||
{
|
||||
Name: "poetry",
|
||||
Name: "python",
|
||||
Files: []string{"pyproject.toml"},
|
||||
Fetcher: n.getPoetryPackage,
|
||||
Fetcher: n.getPythonPackage,
|
||||
},
|
||||
{
|
||||
Name: "php",
|
||||
|
@ -165,7 +166,7 @@ func (n *Project) getCargoPackage(item ProjectItem) *ProjectData {
|
|||
}
|
||||
}
|
||||
|
||||
func (n *Project) getPoetryPackage(item ProjectItem) *ProjectData {
|
||||
func (n *Project) getPythonPackage(item ProjectItem) *ProjectData {
|
||||
content := n.env.FileContent(item.Files[0])
|
||||
|
||||
var data PyProjectTOML
|
||||
|
@ -175,9 +176,15 @@ func (n *Project) getPoetryPackage(item ProjectItem) *ProjectData {
|
|||
return nil
|
||||
}
|
||||
|
||||
if len(data.Tool.Poetry.Version) != 0 || len(data.Tool.Poetry.Name) != 0 {
|
||||
return &ProjectData{
|
||||
Version: data.Tool.Poetry.Version,
|
||||
Name: data.Tool.Poetry.Name,
|
||||
}
|
||||
}
|
||||
return &ProjectData{
|
||||
Version: data.Tool.Poetry.Version,
|
||||
Name: data.Tool.Poetry.Name,
|
||||
Version: data.Project.Version,
|
||||
Name: data.Project.Name,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -92,21 +92,37 @@ func TestPackage(t *testing.T) {
|
|||
PackageContents: "[package]\nname=\"test\"\nversion=\"3.2.1\"\n",
|
||||
},
|
||||
{
|
||||
Case: "1.0.0 poetry",
|
||||
Case: "1.0.0 python (poetry)",
|
||||
ExpectedEnabled: true,
|
||||
ExpectedString: "\uf487 1.0.0 test",
|
||||
Name: "poetry",
|
||||
Name: "python",
|
||||
File: "pyproject.toml",
|
||||
PackageContents: "[tool.poetry]\nname=\"test\"\nversion=\"1.0.0\"\n",
|
||||
},
|
||||
{
|
||||
Case: "3.2.1 poetry",
|
||||
Case: "3.2.1 python (poetry)",
|
||||
ExpectedEnabled: true,
|
||||
ExpectedString: "\uf487 3.2.1 test",
|
||||
Name: "poetry",
|
||||
Name: "python",
|
||||
File: "pyproject.toml",
|
||||
PackageContents: "[tool.poetry]\nname=\"test\"\nversion=\"3.2.1\"\n",
|
||||
},
|
||||
{
|
||||
Case: "1.0.0 python (pep621)",
|
||||
ExpectedEnabled: true,
|
||||
ExpectedString: "\uf487 1.0.0 test",
|
||||
Name: "python",
|
||||
File: "pyproject.toml",
|
||||
PackageContents: "[project]\nname=\"test\"\nversion=\"1.0.0\"\n",
|
||||
},
|
||||
{
|
||||
Case: "3.2.1 python (pep621)",
|
||||
ExpectedEnabled: true,
|
||||
ExpectedString: "\uf487 3.2.1 test",
|
||||
Name: "python",
|
||||
File: "pyproject.toml",
|
||||
PackageContents: "[project]\nname=\"test\"\nversion=\"3.2.1\"\n",
|
||||
},
|
||||
{
|
||||
Case: "No version present node.js",
|
||||
ExpectedEnabled: true,
|
||||
|
@ -124,13 +140,21 @@ func TestPackage(t *testing.T) {
|
|||
PackageContents: "[package]\nname=\"test\"\n",
|
||||
},
|
||||
{
|
||||
Case: "No version present poetry",
|
||||
Case: "No version present python (poetry)",
|
||||
ExpectedEnabled: true,
|
||||
ExpectedString: "test",
|
||||
Name: "poetry",
|
||||
Name: "python",
|
||||
File: "pyproject.toml",
|
||||
PackageContents: "[tool.poetry]\nname=\"test\"\n",
|
||||
},
|
||||
{
|
||||
Case: "No version present python (pep621)",
|
||||
ExpectedEnabled: true,
|
||||
ExpectedString: "test",
|
||||
Name: "python",
|
||||
File: "pyproject.toml",
|
||||
PackageContents: "[project]\nname=\"test\"\n",
|
||||
},
|
||||
{
|
||||
Case: "No name present node.js",
|
||||
ExpectedEnabled: true,
|
||||
|
@ -148,13 +172,21 @@ func TestPackage(t *testing.T) {
|
|||
PackageContents: "[package]\nversion=\"1.0.0\"\n",
|
||||
},
|
||||
{
|
||||
Case: "No name present poetry",
|
||||
Case: "No name present python (poetry)",
|
||||
ExpectedEnabled: true,
|
||||
ExpectedString: "\uf487 1.0.0",
|
||||
Name: "poetry",
|
||||
Name: "python",
|
||||
File: "pyproject.toml",
|
||||
PackageContents: "[tool.poetry]\nversion=\"1.0.0\"\n",
|
||||
},
|
||||
{
|
||||
Case: "No name present python (pep621)",
|
||||
ExpectedEnabled: true,
|
||||
ExpectedString: "\uf487 1.0.0",
|
||||
Name: "python",
|
||||
File: "pyproject.toml",
|
||||
PackageContents: "[project]\nversion=\"1.0.0\"\n",
|
||||
},
|
||||
{
|
||||
Case: "Empty project package node.js",
|
||||
ExpectedEnabled: true,
|
||||
|
@ -170,9 +202,9 @@ func TestPackage(t *testing.T) {
|
|||
PackageContents: "",
|
||||
},
|
||||
{
|
||||
Case: "Empty project package poetry",
|
||||
Case: "Empty project package python",
|
||||
ExpectedEnabled: true,
|
||||
Name: "poetry",
|
||||
Name: "python",
|
||||
File: "pyproject.toml",
|
||||
PackageContents: "",
|
||||
},
|
||||
|
|
|
@ -12,7 +12,7 @@ Supports:
|
|||
|
||||
- Node.js project (`package.json`)
|
||||
- Cargo project (`Cargo.toml`)
|
||||
- Poetry project (`pyproject.toml`)
|
||||
- Python project (`pyproject.toml`, supports metadata defined according to [PEP 621][pep621-standard] or [Poetry][poetry-standard])
|
||||
- PHP project (`composer.json`)
|
||||
- Any nuspec based project (`*.nuspec`, first file match info is displayed)
|
||||
- .NET project (`*.sln`, `*.slnf`, `*.csproj`, `*.vbproj` or `*.fsproj`, first file match info is displayed)
|
||||
|
@ -55,10 +55,12 @@ import Config from "@site/src/components/Config.js";
|
|||
|
||||
| Name | Type | Description |
|
||||
| ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `.Type` | `string` | The type of project:<ul><li>`node`</li><li>`cargo`</li><li>`poetry`</li><li>`php`</li><li>`nuspec`</li><li>`dotnet`</li><li>`julia`</li><li>`powershell`</li></ul> |
|
||||
| `.Type` | `string` | The type of project:<ul><li>`node`</li><li>`cargo`</li><li>`python`</li><li>`php`</li><li>`nuspec`</li><li>`dotnet`</li><li>`julia`</li><li>`powershell`</li></ul> |
|
||||
| `.Version` | `string` | The version of your project |
|
||||
| `.Target` | `string` | The target framwork/language version of your project |
|
||||
| `.Name` | `string` | The name of your project |
|
||||
| `.Error` | `string` | The error context when we can't fetch the project info |
|
||||
|
||||
[templates]: /docs/configuration/templates
|
||||
[pep621-standard]: https://peps.python.org/pep-0621/
|
||||
[poetry-standard]: https://python-poetry.org/docs/pyproject/
|
||||
|
|
Loading…
Reference in a new issue