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

nix development support #19

Closed
wants to merge 2 commits 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
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# use https://github.com/nix-community/nix-direnv
use_flake ".#python311.dev_env"
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,10 @@ cython_debug/
# For testing
input/
output/

# nix build
result
.direnv

# vs code
.vscode
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ To install from GitHub:

pip install -e git+https://github.com/quantum5/win2xcur.git

To install from nix flakes:

nix profile install "github:quantum5/win2xcur#python311.bin"

## Usage: `win2xcur`

For example, if you want to convert [the sample cursor](sample/crosshair.cur)
Expand Down Expand Up @@ -52,3 +56,6 @@ are using unconventional distros (e.g. Alpine) and are getting errors related
to `wand`, please see the [Wand documentation on installation][wand-install].

[wand-install]: https://docs.wand-py.org/en/0.6.7/guide/install.html

Nix installation will not interfere with your local python, try this
option if you have dependencies or python version conflicts.
63 changes: 63 additions & 0 deletions build_pkg/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
makesLib,
nixpkgs,
python_version,
src,
}: let
deps = import ./deps {
inherit nixpkgs python_version;
};

# Define the package requirements
build_required_deps = python_pkgs: {
runtime_deps = with python_pkgs; [
numpy
wand
];
build_deps = with python_pkgs; [flit-core];
test_deps = with python_pkgs; [
mypy
pytest
pylint
];
};

# The pkg builder
bundle_builder = lib: pkgDeps:
makesLib.makePythonPyprojectPackage {
inherit (lib) buildEnv buildPythonPackage;
inherit pkgDeps src;
};

# Abstract builder to allow an alternative to override dependencies
build_bundle = builder:
# builder: Deps -> (PythonPkgs -> PkgDeps) -> (Deps -> PkgDeps -> Bundle) -> Bundle
# Deps: are the default project dependencies
# PythonPkgs -> PkgDeps: is the required dependencies builder
# Deps -> PkgDeps -> Bundle: is the bundle builder
builder deps build_required_deps bundle_builder;

# Concrete bundle that uses python pkgs from the default
# i.e. the python nixpkg from the flake
bundle = build_bundle (default: required_deps: builder: builder default.lib (required_deps default.python_pkgs));

# Develompent environment
dev_env = let
template = makesLib.makePythonVscodeSettings {
env = bundle.env.dev;
bins = [ ];
name = "win2xcur-env-dev-template";
};
hook = makesLib.makeScript {
name = "win2xcur-env-dev";
entrypoint = "${template}/template";
};
in nixpkgs.mkShell {
packages = [bundle.env.dev];
shellHook = "${hook}/bin/dev";
};

# Executable application derivation
bin = deps.lib.toPythonApplication bundle.pkg;
in
bundle // {inherit build_bundle dev_env bin;}
15 changes: 15 additions & 0 deletions build_pkg/deps/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
nixpkgs,
python_version,
}: let
# Define required nixpkgs python builders
lib = {
buildEnv = nixpkgs."${python_version}".buildEnv.override;
inherit (nixpkgs."${python_version}".pkgs) buildPythonPackage toPythonApplication;
inherit (nixpkgs.python3Packages) fetchPypi;
};
# Define the nixpkgs python packages overrides
python_pkgs = nixpkgs."${python_version}Packages";
in {
inherit lib python_pkgs;
}
13 changes: 13 additions & 0 deletions build_pkg/filter.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let
metadata = (builtins.fromTOML (builtins.readFile ../pyproject.toml)).project;
in
path_filter: src:
path_filter {
root = src;
include = [
"mypy.ini"
"pyproject.toml"
(path_filter.inDirectory metadata.name)
(path_filter.inDirectory "tests")
];
}
76 changes: 76 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
description = "win2xcur is a tool to convert Windows .cur and .ani cursors to Xcursor format.";
inputs = {
makes.url = "github:fluidattacks/makes";
nixpkgs.url = "github:nixos/nixpkgs";
nix_filter.url = "github:numtide/nix-filter";
};
outputs = {
self,
nixpkgs,
nix_filter,
makes,
}: let
path_filter = nix_filter.outputs.lib;
src = import ./build_pkg/filter.nix path_filter self;
out = system: python_version: let
makesLib = makes.lib."${system}";
pkgs = nixpkgs.legacyPackages."${system}";
in
import ./build_pkg {
inherit src python_version makesLib;
nixpkgs = pkgs;
};
supported = ["python39" "python310" "python311"];
python_outs = system:
(builtins.listToAttrs (map (name: {
inherit name;
value = out system name;
})
supported))
// {build_with_python = out system; nixpkgs = nixpkgs.legacyPackages."${system}";};
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
forAllSystems = nixpkgs.lib.genAttrs systems;
in {
packages = forAllSystems python_outs;
defaultPackage = self.packages;
};
}
35 changes: 35 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[project]
name = "win2xcur"
authors = [
{name = "quantum", email = "[email protected]"},
]
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Win32 (MS Windows)",
"Environment :: X11 Applications",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Desktop Environment",
]
requires-python = ">=3.9"
dependencies = [
"numpy >=1.2.12, <2.0.0",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mere guess, I do not know which are the ranges of versions that the library requires.

"Wand >=0.6.13, <1.0.0",
]
description = "win2xcur is a tool to convert Windows .cur and .ani cursors to Xcursor format."
dynamic = ["version"]

[project.scripts]
win2xcur = 'win2xcur.main.win2xcur:main'
x2wincur = 'win2xcur.main.x2wincur:main'

[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

44 changes: 0 additions & 44 deletions setup.py

This file was deleted.

Empty file added tests/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions tests/test_placeholder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_placeholder() -> None:
assert 1 == 1
1 change: 1 addition & 0 deletions win2xcur/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.2.0"