Merge pull request #249464 from ngi-nix/kikit

kikit and kicad package set
This commit is contained in:
Valentin Gagarin
2023-11-16 17:20:37 +01:00
committed by GitHub
17 changed files with 539 additions and 1 deletions
+15
View File
@@ -8295,6 +8295,15 @@
githubId = 18501;
name = "Julien Langlois";
};
jfly = {
name = "Jeremy Fleischman";
email = "jeremyfleischman@gmail.com";
github = "jfly";
githubId = 277474;
keys = [{
fingerprint = "F1F1 3395 8E8E 9CC4 D9FC 9647 1931 9CD8 416A 642B";
}];
};
jfrankenau = {
email = "johannes@frankenau.net";
github = "jfrankenau";
@@ -11209,6 +11218,12 @@
githubId = 11810057;
name = "Matt Snider";
};
matusf = {
email = "matus.ferech@gmail.com";
github = "matusf";
githubId = 18228995;
name = "Matúš Ferech";
};
maurer = {
email = "matthew.r.maurer+nix@gmail.com";
github = "maurer";
@@ -0,0 +1,5 @@
{ kicad }:
{
kikit = kicad.callPackage ./kikit.nix { addonName = "kikit"; };
kikit-library = kicad.callPackage ./kikit.nix { addonName = "kikit-library"; };
}
@@ -0,0 +1,52 @@
# For building the multiple addons that are in the kikit repo.
{ stdenv
, bc
, kikit
, zip
, python3
, addonName
, addonPath
}:
let
# This python is only used when building the package, it's not the python
# environment that will ultimately run the code packaged here. The python env defined
# in KiCad will import the python code packaged here when KiCad starts up.
python = python3.withPackages (ps: with ps; [ click ]);
kikit-module = python3.pkgs.toPythonModule (kikit.override { inherit python3; });
# The following different addons can be built from the same source.
targetSpecs = {
"kikit" = {
makeTarget = "pcm-kikit";
resultZip = "pcm-kikit.zip";
description = "KiCad plugin and a CLI tool to automate several tasks in a standard KiCad workflow";
};
"kikit-library" = {
makeTarget = "pcm-lib";
resultZip = "pcm-kikit-lib.zip";
description = "KiKit uses these symbols and footprints to annotate your boards (e.g., to place a tab in a panel).";
};
};
targetSpec = targetSpecs.${addonName};
in
stdenv.mkDerivation {
name = "kicadaddon-${addonName}";
inherit (kikit-module) src version;
nativeBuildInputs = [ python bc zip ];
propagatedBuildInputs = [ kikit-module ];
buildPhase = ''
patchShebangs scripts/setJson.py
make ${targetSpec.makeTarget}
'';
installPhase = ''
mkdir $out
mv build/${targetSpec.resultZip} $out/${addonPath}
'';
meta = kikit-module.meta // {
description = targetSpec.description;
};
}
@@ -69,6 +69,8 @@ stdenv.mkDerivation rec {
patches = [
# upstream issue 12941 (attempted to upstream, but appreciably unacceptable)
./writable.patch
# https://gitlab.com/kicad/code/kicad/-/issues/15687
./runtime_stock_data_path.patch
];
# tagged releases don't have "unknown"
@@ -1,4 +1,6 @@
{ lib, stdenv
, runCommand
, newScope
, fetchFromGitLab
, gnome
, dconf
@@ -11,6 +13,8 @@
, callPackages
, librsvg
, cups
, unzip
, jq
, pname ? "kicad"
, stable ? true
@@ -18,6 +22,7 @@
, libngspice
, withScripting ? true
, python3
, addons ? [ ]
, debug ? false
, sanitizeAddress ? false
, sanitizeThreads ? false
@@ -27,6 +32,14 @@
, symlinkJoin
}:
# `addons`: https://dev-docs.kicad.org/en/addons/
#
# ```nix
# kicad = pkgs.kicad.override {
# addons = with pkgs.kicadAddons; [ kikit kikit-library ];
# };
# ```
# The `srcs` parameter can be used to override the kicad source code
# and all libraries, which are otherwise inaccessible
# to overlays since most of the kicad build expression has been
@@ -106,6 +119,32 @@ let
wxGTK = wxGTK32;
python = python3;
wxPython = python.pkgs.wxPython_4_2;
addonPath = "addon.zip";
addonsDrvs = map (pkg: pkg.override { inherit addonPath python3; }) addons;
addonsJoined =
runCommand "addonsJoined"
{
inherit addonsDrvs;
nativeBuildInputs = [ unzip jq ];
} ''
mkdir $out
for pkg in $addonsDrvs; do
unzip $pkg/addon.zip -d unpacked
folder_name=$(jq .identifier unpacked/metadata.json --raw-output | tr . _)
for d in unpacked/*; do
if [ -d "$d" ]; then
dest=$out/share/kicad/scripting/$(basename $d)/$folder_name
mkdir -p $(dirname $dest)
mv $d $dest
fi
done
rm -r unpacked
done
'';
inherit (lib) concatStringsSep flatten optionalString optionals;
in
@@ -113,6 +152,7 @@ stdenv.mkDerivation rec {
# Common libraries, referenced during runtime, via the wrapper.
passthru.libraries = callPackages ./libraries.nix { inherit libSrc; };
passthru.callPackage = newScope { inherit addonPath python3; };
base = callPackage ./base.nix {
inherit stable baseName;
inherit kicadSrc kicadVersion;
@@ -131,7 +171,7 @@ stdenv.mkDerivation rec {
dontFixup = true;
pythonPath = optionals (withScripting)
[ wxPython python.pkgs.six python.pkgs.requests ];
[ wxPython python.pkgs.six python.pkgs.requests ] ++ addonsDrvs;
nativeBuildInputs = [ makeWrapper ]
++ optionals (withScripting)
@@ -164,6 +204,17 @@ stdenv.mkDerivation rec {
"--set-default KICAD7_SYMBOL_DIR ${symbols}/share/kicad/symbols"
"--set-default KICAD7_TEMPLATE_DIR ${template_dir}"
]
++ optionals (addons != [ ]) (
let stockDataPath = symlinkJoin {
name = "kicad_stock_data_path";
paths = [
"${base}/share/kicad"
"${addonsJoined}/share/kicad"
];
};
in
[ "--set-default NIX_KICAD7_STOCK_DATA_PATH ${stockDataPath}" ]
)
++ optionals (with3d)
[
"--set-default KICAD7_3DMODEL_DIR ${packages3d}/share/kicad/3dmodels"
@@ -0,0 +1,15 @@
diff --git a/common/paths.cpp b/common/paths.cpp
index a74cdd9..790cc58 100644
--- a/common/paths.cpp
+++ b/common/paths.cpp
@@ -151,6 +151,10 @@ wxString PATHS::GetStockDataPath( bool aRespectRunFromBuildDir )
{
wxString path;
+ if( wxGetEnv( wxT( "NIX_KICAD7_STOCK_DATA_PATH" ), &path ) ) {
+ return path;
+ }
+
if( aRespectRunFromBuildDir && wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
{
// Allow debugging from build dir by placing relevant files/folders in the build root
+87
View File
@@ -0,0 +1,87 @@
{ bc
, zip
, lib
, fetchFromGitHub
, bats
, buildPythonApplication
, pythonOlder
, callPackage
, kicad
, numpy
, click
, markdown2
, pytestCheckHook
, commentjson
, wxPython_4_2
, pcbnew-transition
, pybars3
, versioneer
}:
let
solidpython = callPackage ./solidpython { };
# https://github.com/yaqwsx/KiKit/issues/574
# copy-pasted from nixpkgs#8d8e62e74f511160a599471549a98bc9e4f4818d
shapely = callPackage ./shapely { };
in
buildPythonApplication rec {
pname = "kikit";
version = "1.3.0";
format = "setuptools";
disabled = pythonOlder "3.7";
src = fetchFromGitHub {
owner = "yaqwsx";
repo = "KiKit";
rev = "v${version}";
hash = "sha256-kDTPk/R3eZtm4DjoUV4tSQzjGQ9k8MKQedX4oUXYzeo=";
};
propagatedBuildInputs = [
kicad
numpy
click
markdown2
commentjson
# https://github.com/yaqwsx/KiKit/issues/575
wxPython_4_2
pcbnew-transition
pybars3
shapely
# https://github.com/yaqwsx/KiKit/issues/576
solidpython
];
nativeBuildInputs = [
versioneer
bc
zip
];
nativeCheckInputs = [
pytestCheckHook
bats
];
pythonImportsCheck = [
"kikit"
];
preCheck = ''
export PATH=$PATH:$out/bin
make test-system
# pytest needs to run in a subdir. See https://github.com/yaqwsx/KiKit/blob/v1.3.0/Makefile#L43
cd test/units
'';
meta = with lib; {
description = "Automation for KiCAD boards";
homepage = "https://github.com/yaqwsx/KiKit/";
changelog = "https://github.com/yaqwsx/KiKit/releases/tag/v${version}";
maintainers = with maintainers; [ jfly matusf ];
license = licenses.mit;
};
}
+2
View File
@@ -0,0 +1,2 @@
{ python3 }:
(python3.pkgs.callPackage ./default.nix { })
+71
View File
@@ -0,0 +1,71 @@
{ lib
, stdenv
, buildPythonPackage
, fetchPypi
, substituteAll
, pythonOlder
, geos
, pytestCheckHook
, cython
, numpy
}:
buildPythonPackage rec {
pname = "Shapely";
version = "1.8.4";
disabled = pythonOlder "3.6";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-oZXlHKr6IYKR8suqP+9p/TNTyT7EtlsqRyLEz0DDGYw=";
};
nativeBuildInputs = [
geos # for geos-config
cython
];
propagatedBuildInputs = [
numpy
];
checkInputs = [
pytestCheckHook
];
# Environment variable used in shapely/_buildcfg.py
GEOS_LIBRARY_PATH = "${geos}/lib/libgeos_c${stdenv.hostPlatform.extensions.sharedLibrary}";
patches = [
# Patch to search form GOES .so/.dylib files in a Nix-aware way
(substituteAll {
src = ./library-paths.patch;
libgeos_c = GEOS_LIBRARY_PATH;
libc = lib.optionalString (!stdenv.isDarwin) "${stdenv.cc.libc}/lib/libc${stdenv.hostPlatform.extensions.sharedLibrary}.6";
})
];
preCheck = ''
rm -r shapely # prevent import of local shapely
'';
disabledTests = lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
# FIXME(lf-): these logging tests are broken, which is definitely our
# fault. I've tried figuring out the cause and failed.
#
# It is apparently some sandbox or no-sandbox related thing on macOS only
# though.
"test_error_handler_exception"
"test_error_handler"
"test_info_handler"
];
pythonImportsCheck = [ "shapely" ];
meta = with lib; {
description = "Geometric objects, predicates, and operations";
homepage = "https://pypi.python.org/pypi/Shapely/";
license = with licenses; [ bsd3 ];
maintainers = with maintainers; [ knedlsepp ];
};
}
@@ -0,0 +1,31 @@
diff --git a/shapely/geos.py b/shapely/geos.py
index 88c5f53..1ccd6e4 100644
--- a/shapely/geos.py
+++ b/shapely/geos.py
@@ -96,6 +96,7 @@ if sys.platform.startswith('linux'):
alt_paths = [
'libgeos_c.so.1',
'libgeos_c.so',
+ '@libgeos_c@',
]
_lgeos = load_dll('geos_c', fallbacks=alt_paths)
@@ -160,6 +161,7 @@ elif sys.platform == 'darwin':
"/usr/local/lib/libgeos_c.dylib",
# homebrew Apple Silicon
"/opt/homebrew/lib/libgeos_c.dylib",
+ "@libgeos_c@",
]
_lgeos = load_dll('geos_c', fallbacks=alt_paths)
diff --git a/tests/test_dlls.py b/tests/test_dlls.py
index c71da8e..c36262c 100644
--- a/tests/test_dlls.py
+++ b/tests/test_dlls.py
@@ -18,4 +18,5 @@ class LoadingTestCase(unittest.TestCase):
'/opt/homebrew/lib/libgeos_c.dylib', # homebrew (macOS)
os.path.join(sys.prefix, "lib", "libgeos_c.so"), # anaconda (Linux)
'libgeos_c.so.1',
- 'libgeos_c.so'])
+ 'libgeos_c.so',
+ '@libgeos_c@'])
@@ -0,0 +1,66 @@
# SolidPython is an unmaintained library with old dependencies.
{ buildPythonPackage
, callPackage
, fetchFromGitHub
, fetchFromGitLab
, fetchpatch
, lib
, pythonRelaxDepsHook
, poetry-core
, prettytable
, pypng
, ply
, setuptools
, euclid3
}:
buildPythonPackage rec {
pname = "solidpython";
version = "1.1.3";
format = "pyproject";
src = fetchFromGitHub {
owner = "SolidCode";
repo = "SolidPython";
rev = "d962740d600c5dfd69458c4559fc416b9beab575";
hash = "sha256-3fJta2a5c8hV9FPwKn5pj01aBtsCGSRCz3vvxR/5n0Q=";
};
nativeBuildInputs = [
poetry-core
pythonRelaxDepsHook
];
propagatedBuildInputs = [
ply
setuptools
euclid3
prettytable
];
pythonRelaxDeps = [
# SolidPython has PrettyTable pinned to a hyper-specific version due to
# some ancient bug with Poetry. They aren't interested in unpinning because
# SolidPython v1 seems to be deprecated in favor of v2:
# https://github.com/SolidCode/SolidPython/issues/207
"PrettyTable"
];
pythonRemoveDeps = [
# The pypng dependency is only used in an example script.
"pypng"
];
pythonImportsCheck = [
"solid"
];
meta = with lib; {
description = "Python interface to the OpenSCAD declarative geometry language";
homepage = "https://github.com/SolidCode/SolidPython";
changelog = "https://github.com/SolidCode/SolidPython/releases/tag/v${version}";
maintainers = with maintainers; [ jfly ];
license = licenses.lgpl21Plus;
};
}
@@ -0,0 +1,25 @@
{ buildPythonPackage
, lib
, fetchPypi
}:
buildPythonPackage rec {
pname = "euclid3";
version = "0.01";
format = "setuptools";
src = fetchPypi {
inherit pname version;
hash = "sha256-JbgnpXrb/Zo/qGJeQ6vD6Qf2HeYiND5+U4SC75tG/Qs=";
};
pythonImportsCheck = [
"euclid3"
];
meta = with lib; {
description = "2D and 3D vector, matrix, quaternion and geometry module.";
homepage = "http://code.google.com/p/pyeuclid/";
license = licenses.lgpl21Plus;
maintainers = with maintainers; [ jfly matusf ];
};
}
@@ -0,0 +1,39 @@
{ pythonOlder
, buildPythonPackage
, fetchPypi
, lib
, kicad
, versioneer
}:
buildPythonPackage rec {
pname = "pcbnewTransition";
version = "0.3.4";
format = "setuptools";
disabled = pythonOlder "3.7";
src = fetchPypi {
inherit pname version;
hash = "sha256-3CJUG1kd63Lg0r9HpJRIvttHS5s2EuZRoxeXrqsJ/kQ=";
};
propagatedBuildInputs = [
kicad
];
nativeBuildInputs = [
versioneer
];
pythonImportsCheck = [
"pcbnewTransition"
];
meta = with lib; {
description = "Library that allows you to support both, KiCad 5, 6 and 7 in your plugins";
homepage = "https://github.com/yaqwsx/pcbnewTransition";
changelog = "https://github.com/yaqwsx/pcbnewTransition/releases/tag/v${version}";
license = licenses.mit;
maintainers = with maintainers; [ jfly matusf ];
};
}
@@ -0,0 +1,38 @@
{ python3
, fetchPypi
, lib
, pymeta3
, buildPythonPackage
}:
buildPythonPackage rec {
pname = "pybars3";
version = "0.9.7";
format = "setuptools";
src = fetchPypi {
inherit pname version;
hash = "sha256-ashH6QXlO5xbk2rxEskQR14nv3Z/efRSjBb5rx7A4lI=";
};
propagatedBuildInputs = [
pymeta3
];
checkPhase = ''
runHook preCheck
${python3.interpreter} tests.py
runHook postCheck
'';
pythonImportsCheck = [
"pybars"
];
meta = with lib; {
description = "Handlebars.js template support for Python 3 and 2";
homepage = "https://github.com/wbond/pybars3";
changelog = "https://github.com/wbond/pybars3/releases/tag/${version}";
license = licenses.lgpl3Only;
maintainers = with maintainers; [ jfly matusf ];
};
}
@@ -0,0 +1,29 @@
{ buildPythonPackage
, fetchPypi
, lib
}:
buildPythonPackage rec {
pname = "pymeta3";
version = "0.5.1";
format = "setuptools";
src = fetchPypi {
inherit version;
pname = "PyMeta3";
hash = "sha256-GL2jJtmpu/WHv8DuC8loZJZNeLBnKIvPVdTZhoHQW8s=";
};
doCheck = false; # Tests do not support Python3
pythonImportsCheck = [
"pymeta"
];
meta = with lib; {
description = "Pattern-matching language based on OMeta for Python 3 and 2";
homepage = "https://github.com/wbond/pymeta3";
changelog = "https://github.com/wbond/pymeta3/releases/tag/${version}";
license = licenses.mit;
maintainers = with maintainers; [ jfly matusf ];
};
}
+2
View File
@@ -39794,6 +39794,8 @@ with pkgs;
with3d = false;
};
kicadAddons = recurseIntoAttrs (callPackage ../applications/science/electronics/kicad/addons {});
librepcb = libsForQt5.callPackage ../applications/science/electronics/librepcb { };
ngspice = libngspice.override {
+8
View File
@@ -3657,6 +3657,8 @@ self: super: with self; {
et-xmlfile = callPackage ../development/python-modules/et-xmlfile { };
euclid3 = callPackage ../development/python-modules/euclid3 { };
eufylife-ble-client = callPackage ../development/python-modules/eufylife-ble-client { };
evaluate = callPackage ../development/python-modules/evaluate { };
@@ -8843,6 +8845,8 @@ self: super: with self; {
inherit (pkgs) libpcap; # Avoid confusion with python package of the same name
};
pcbnew-transition = callPackage ../development/python-modules/pcbnew-transition { };
pcodedmp = callPackage ../development/python-modules/pcodedmp { };
pcpp = callPackage ../development/python-modules/pcpp { };
@@ -9009,6 +9013,10 @@ self: super: with self; {
psrpcore = callPackage ../development/python-modules/psrpcore { };
pybars3 = callPackage ../development/python-modules/pybars3 { };
pymeta3 = callPackage ../development/python-modules/pymeta3 { };
pypemicro = callPackage ../development/python-modules/pypemicro { };
pyprecice = callPackage ../development/python-modules/pyprecice { };