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

Use pyproject.toml by default and fix config merger #35

Merged
merged 3 commits into from
Nov 8, 2024
Merged
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
20 changes: 15 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Python now generates a `run` command and cli entry point for clients and services.

### Changed
- Python now uses `pyproject` instead of `setuptools` by default. Template for targetSetup
has been updated accordingly. It also conforms to `ruff`s checks and formatting by default.

### Fixed
- Python's config merger now handles mypy overrides targeting multiple packages.

## [5.0.0] - 2024-10-15

## Added
### Added
- `input` parameter to `mkPlatform` for C. This controls what target
gets used for dependent components.

## Removed
### Removed
- `targetName` no longer gets sent to the `mk*` functions for C.

## [4.1.5] - 2024-09-13

## Fixed
### Fixed
- Overriding the factory of a C platform caused the 'override' function
to disappear from the resulting set.
- `output` now works as expected on C platforms. Previously, setting
Expand All @@ -26,14 +36,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [4.1.4] - 2024-06-03

## Fixed
### Fixed
- Python check runner not finding config when not in root of component.
- Fix some outside tools not getting check configs because TMP is not
always set.

## [4.1.3] - 2024-03-22

## Fixed
### Fixed
- Flake8 not getting configuration.

## [4.1.2] - 2024-03-22
Expand Down
4 changes: 2 additions & 2 deletions python/component-template/@mainPackage@/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" @desc@ """
"""@desc@"""


def main() -> None:
""" main function of @mainPackage@ """
"""Main function of @mainPackage@."""
raise NotImplementedError
18 changes: 18 additions & 0 deletions python/component-template/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[build-system]
requires = ["setuptools"]

[project]
name = "@pname@"
version = "@version@"
description = "@desc@"
authors = [{name = "@author@", email = "@email@"}]

[setuptools.packages.find]
exclude = ["tests*"]

[urls]
Homepage = "@url@"

[project.scripts]
@entryPoint@

13 changes: 0 additions & 13 deletions python/component-template/setup.py

This file was deleted.

5 changes: 3 additions & 2 deletions python/component-template/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" Tests for @mainPackage@ in @pname@ """
"""Tests for @mainPackage@ in @pname@."""
import @[email protected]


def test_main() -> None:
""" Tests for the main function """
"""Tests for the main function."""
@[email protected]()
12 changes: 6 additions & 6 deletions python/hooks/config-merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ def mypy_overrides(config_file, key) -> dict:

root = {}
for override in overrides:
module_name = f'mypy-{override.pop("module")}'
root.update(
{
module_name: override,
}
)
modules = override.pop("module")
if not isinstance(modules, list):
modules = [modules]
for module in modules:
module_name = f'mypy-{module}'
root.setdefault(module_name, {}).update(override)
to_remove = config_file
for remove_key in keys[:-1]:
to_remove = to_remove.get(remove_key)
Expand Down
3 changes: 3 additions & 0 deletions python/main.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

if __name__ == "__main__":
main()
20 changes: 17 additions & 3 deletions python/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,26 @@ let
inherit version;
pname = name;
mainPackage = lib.toLower (builtins.replaceStrings [ "-" " " ] [ "_" "_" ] name);
entryPoint = if setuptoolsLibrary then "{}" else "{\\\"console_scripts\\\": [\\\"${name}=${mainPackage}.main:main\\\"]}";
entryPoint = if setuptoolsLibrary then "" else "${name}=\\\"${mainPackage}.main:main\\\"";
} // args.targetSetup.variables or { };
variableQueries = {
desc = "✍️ Write a short description for your component:";
author = "🤓 Enter author name:";
email = "📧 Enter author email:";
url = "🏄 Enter author website url:";
} // args.targetSetup.variableQueries or { };
initCommands = "black .";
initCommands = ''
${if ! setuptoolsLibrary then "cat ${./main.py.in} >>$mainPackage/main.py" else ""}
ruff format .
ruff check --fix --unsafe-fixes .
'';
});

pythonPackageArgs = attrs // {
inherit version preBuild doStandardTests pythonVersion propagatedBuildInputs;
src = if lib.isStorePath src then src else filteredSrc;
pname = name;
format = attrs.format or "pyproject";

# Don't install dependencies with pip, let nix handle that
preInstall = ''
Expand Down Expand Up @@ -170,7 +175,16 @@ let
Show the config Nedryland has generated for a linter, one of:
black, coverage, flake8, isort, mypy, pylint, pytest'';
};
} // attrs.shellCommands or { });
} // (
lib.optionalAttrs
(! setuptoolsLibrary)
{
run = {
script = ''python -m ${name}.main "$@"'';
description = "Run the main module.";
};
})
// attrs.shellCommands or { });
};
in
pythonPkgs.buildPythonPackage pythonPackageArgs
Loading