diff --git a/flake.lock b/flake.lock index 99401e6..d9904ca 100644 --- a/flake.lock +++ b/flake.lock @@ -18,45 +18,6 @@ "type": "github" } }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nix-github-actions": { - "inputs": { - "nixpkgs": [ - "poetry2nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1703863825, - "narHash": "sha256-rXwqjtwiGKJheXB43ybM8NwWB8rO2dSRrEqes0S7F5Y=", - "owner": "nix-community", - "repo": "nix-github-actions", - "rev": "5163432afc817cf8bd1f031418d1869e4c9d5547", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nix-github-actions", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1726062873, @@ -85,27 +46,23 @@ "url": "https://github.com/NixOS/nixpkgs/archive/356624c12086a18f2ea2825fed34523d60ccc4e3.tar.gz" } }, - "poetry2nix": { + "pyproject-nix": { "inputs": { - "flake-utils": "flake-utils", - "nix-github-actions": "nix-github-actions", "nixpkgs": [ "nixpkgs" - ], - "systems": "systems_2", - "treefmt-nix": "treefmt-nix" + ] }, "locked": { - "lastModified": 1726275961, - "narHash": "sha256-QMdPMN+I9pwuE7/9d5Dane0VwGxtoTVNWIp3TMSIrgI=", - "owner": "nix-community", - "repo": "poetry2nix", - "rev": "9a04664289506c27ddbf098d98ce520155af574c", + "lastModified": 1734658408, + "narHash": "sha256-HdHkeJ506zKDOrCvsMoZllrOs1sol6bYbv1DifDtas0=", + "owner": "pyproject-nix", + "repo": "pyproject.nix", + "rev": "139a84af40ed51c87f27708fcbe196bd6f189efd", "type": "github" }, "original": { - "owner": "nix-community", - "repo": "poetry2nix", + "owner": "pyproject-nix", + "repo": "pyproject.nix", "type": "github" } }, @@ -113,57 +70,7 @@ "inputs": { "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", - "poetry2nix": "poetry2nix" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "systems_2": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "id": "systems", - "type": "indirect" - } - }, - "treefmt-nix": { - "inputs": { - "nixpkgs": [ - "poetry2nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1719749022, - "narHash": "sha256-ddPKHcqaKCIFSFc/cvxS14goUhCOAwsM1PbMr0ZtHMg=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "8df5ff62195d4e67e2264df0b7f5e8c9995fd0bd", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "treefmt-nix", - "type": "github" + "pyproject-nix": "pyproject-nix" } } }, diff --git a/flake.nix b/flake.nix index e186b75..dc610cf 100644 --- a/flake.nix +++ b/flake.nix @@ -4,94 +4,62 @@ inputs = { flake-parts.url = "github:hercules-ci/flake-parts"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - poetry2nix = { - url = "github:nix-community/poetry2nix"; + pyproject-nix = { + url = "github:pyproject-nix/pyproject.nix"; inputs.nixpkgs.follows = "nixpkgs"; }; }; - outputs = inputs@{ nixpkgs, flake-parts, ... }: - let - readMetadata = { lib }: ( + outputs = + inputs@{ flake-parts, pyproject-nix, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + + perSystem = + { config, pkgs, ... }: let - pyproject = builtins.fromTOML ( - builtins.readFile ./pyproject.toml - ); + project = pyproject-nix.lib.project.loadPyproject { + projectRoot = ./.; + }; + python = pkgs.python3.override { + packageOverrides = import ./nix/mkPackageOverrides.nix { inherit pkgs; }; + }; + packageAttrs = project.renderers.buildPythonPackage { inherit python; }; in - (with pyproject.tool.poetry; { - inherit description; - homepage = documentation; - license = lib.meta.getLicenseFromSpdxId license; - }) - ); - in - flake-parts.lib.mkFlake { inherit inputs; } rec { - flake = rec { - lib.mkPackageRequirements = - { overrides, requirements }: - overrides.extend (final: prev: - builtins.mapAttrs (package: reqs: - (builtins.getAttr package prev).overridePythonAttrs (old: { - buildInputs = (old.buildInputs or [ ]) ++ (builtins.map (pkg: prev.${pkg}) reqs); - }) - ) requirements - ); - lib.mkTgpy = - { system ? null - , pkgs ? import nixpkgs { inherit system; } - , poetry2nix ? inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; } - }: poetry2nix.mkPoetryApplication { - projectDir = ./.; - preferWheels = false; - meta = readMetadata { lib = pkgs.lib; }; - overrides = lib.mkPackageRequirements { - overrides = poetry2nix.defaultPoetryOverrides.extend (self: super: { - cryptg-anyos = super.cryptg-anyos.override { - preferWheel = true; + { + packages = { + tgpy = python.pkgs.buildPythonPackage ( + packageAttrs + // { + meta = with pkgs.lib; { + description = "Run Python code right in your Telegram messages"; + homepage = "https://tgpy.tmat.me/"; + license = licenses.mit; + mainProgram = "tgpy"; + platforms = platforms.all; + pythonImportsCheck = [ "tgpy" ]; }; - nh3 = import ./nix/nh3overrides.nix { inherit self super pkgs; }; - }); - requirements = { - telethon-v1-24 = [ "setuptools" ]; - pipreqs = [ "setuptools" ]; - python-semantic-release = [ "setuptools" ]; - }; - }; + } + ); + default = config.packages.tgpy; }; - }; - systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; - perSystem = { self', pkgs, ... }: { - packages = { - tgpy = flake.lib.mkTgpy { - inherit pkgs; - }; - default = self'.packages.tgpy; - }; - - devShells.default = - let - poetry2nix = inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }; - in - (poetry2nix.mkPoetryEnv { - projectDir = ./.; - preferWheels = true; - groups = [ "dev" ]; - }).overrideAttrs (old: { - nativeBuildInputs = with pkgs; [ - poetry - python3Packages.python-lsp-server - ] ++ (with pkgs.python3Packages; [ - mkdocs - mkdocs-material - mkdocs-redirects - mkdocs-git-revision-date-localized-plugin - cairosvg - pillow - ]); - }); + devShells.default = + let + pythonEnv = python.withPackages (project.renderers.withPackages { inherit python; }); + in + pkgs.mkShell { + packages = [ + pythonEnv + ]; + }; - formatter = pkgs.nixpkgs-fmt; - }; + formatter = pkgs.nixfmt-rfc-style; + }; }; } diff --git a/nix/mkPackageOverrides.nix b/nix/mkPackageOverrides.nix new file mode 100644 index 0000000..0c74b05 --- /dev/null +++ b/nix/mkPackageOverrides.nix @@ -0,0 +1,24 @@ +{ pkgs }: +self: super: { + telethon-v1-24 = super.telethon.overridePythonAttrs (old: rec { + version = "1.24.18"; + src = pkgs.fetchPypi { + pname = "Telethon-v1.24"; + inherit version; + hash = "sha256-rVgunqMHpOLjRhIZ7RfugTrrv136YtTlqa9CvWOyElY="; + }; + doCheck = false; + }); + cryptg-anyos = super.cryptg.overridePythonAttrs (old: rec { + version = "0.4.1"; + src = super.fetchPypi { + pname = "cryptg-anyos"; + inherit version; + hash = "sha256-pXY0CfdZRDjgID78STTDrvm1wUj4z1AooUBtrSG09Qo="; + }; + cargoDeps = pkgs.rustPlatform.fetchCargoTarball { + inherit src; + hash = "sha256-AqSVFOB9Lfvk9h3GtoYlEOXBEt7YZYLhCDNKM9upQ2U="; + }; + }); +} diff --git a/nix/nh3overrides.nix b/nix/nh3overrides.nix deleted file mode 100644 index 734e1c2..0000000 --- a/nix/nh3overrides.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ super, pkgs, ... }: -super.nh3.overridePythonAttrs (old: { - cargoDeps = pkgs.rustPlatform.fetchCargoTarball { - inherit (old) src; - name = "${old.pname}-${old.version}"; - sha256 = "sha256-fetAE3cj9hh4SoPE72Bqco5ytUMiDqbazeS2MHdUibM="; - }; - buildInputs = old.buildInputs or [ ] ++ (pkgs.lib.optionals super.stdenv.isDarwin [ - pkgs.libiconv - ]); - nativeBuildInputs = old.nativeBuildInputs or [ ] ++ (with pkgs.rustPlatform; [ - cargoSetupHook - maturinBuildHook - pkgs.cargo - pkgs.rustc - ]); -}) diff --git a/pyproject.toml b/pyproject.toml index c91db34..ca372ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,24 +1,49 @@ -[tool.poetry] +[project] name = "tgpy" version = "0.16.0" description = "Run Python code right in your Telegram messages" -authors = ["tmat ", "vanutp ", "ntonee "] -license = "MIT" -documentation = "https://tgpy.tmat.me/" -repository = "https://github.com/tm-a-t/TGPy/" readme = "README.md" +requires-python = ">=3.10" +license = { file = "LICENSE" } classifiers = [ - "Operating System :: OS Independent" + "Operating System :: OS Independent", + "Programming Language :: Python", + "Development Status :: 4 - Beta", +] +authors = [ + { name = "tmat", email = "a@tmat.me" }, + { name = "vanutp", email = "hello@vanutp.dev" }, + { name = "ntonee", email = "a12286@yandex.com" }, +] +dependencies = [ + "PyYAML~=6.0", + "aiorun~=2023.7.2", + "rich~=13.7.1", + "appdirs~=1.4.4", + "telethon-v1-24~=1.24.16", + "python-socks[asyncio]~=2.4.3", + "cryptg-anyos~=0.4.1", ] -[tool.poetry.scripts] -tgpy = 'tgpy.main:main' +[project.optional-dependencies] +dev = ["python-semantic-release~=7.31.2", "black~=22.6.0", "isort~=5.10.1"] +guide = [ + "mkdocs-material~=9.5.18", + "mkdocs-git-revision-date-localized-plugin~=1.2.4", + "mkdocs-redirects~=1.2.1", + "pillow~=10.3.0", + "cairosvg~=2.7.1", +] + +[project.urls] +documentation = "https://tgpy.tmat.me/" +repository = "https://github.com/tm-a-t/TGPy/" + +[project.scripts] +tgpy = "tgpy.main:main" [tool.semantic_release] -version_variable = [ - "tgpy/version.py:__version__", - "pyproject.toml:version" -] +version_variable = ["tgpy/version.py:__version__", "pyproject.toml:version"] branch = "master" upload_to_repository = true upload_to_release = true @@ -34,28 +59,6 @@ include = '/tgpy/.*\.pyi?$' profile = "black" src_paths = ["tgpy"] -[tool.poetry.dependencies] -python = "^3.10" -PyYAML = "^6.0" -aiorun = "^2023.7.2" -rich = "^12.5.1" -appdirs = "^1.4.4" -telethon-v1-24 = "^1.24.16" -python-socks = {extras = ["asyncio"], version = "^2.4.3"} -cryptg-anyos = "^0.4.1" - -[tool.poetry.group.dev.dependencies] -python-semantic-release = "^7.31.2" -black = "^22.6.0" -isort = "^5.10.1" - -[tool.poetry.group.guide.dependencies] -mkdocs-material = "^9.5.18" -mkdocs-git-revision-date-localized-plugin = "^1.2.4" -mkdocs-redirects = "^1.2.1" -pillow = "^10.3.0" -cairosvg = "^2.7.1" - [build-system] -requires = ["poetry-core>=1.0.0"] -build-backend = "poetry.core.masonry.api" +requires = ["flit-core>=3.4,<4"] +build-backend = "flit_core.buildapi" diff --git a/result b/result new file mode 120000 index 0000000..b12c716 --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/gxinxxdrmbl46d6qsm2q9fda7zpwvif9-python3.12-tgpy-0.16.0 \ No newline at end of file