From 339aee3b149909430ebe7e3e27b8cf158addaef1 Mon Sep 17 00:00:00 2001 From: Rok Garbas Date: Tue, 28 Jun 2016 23:48:01 +0200 Subject: [PATCH] in generated files display which pypi2nix and exact command ... ... was used to generate nix expressions also all TODOs were moved into github issue tracker --- default.nix | 2 +- VERSION => src/pypi2nix/VERSION | 0 src/pypi2nix/cli.py | 2 -- src/pypi2nix/stage1.py | 1 - src/pypi2nix/stage3.py | 29 ++++++++++++++++++++++------- 5 files changed, 23 insertions(+), 11 deletions(-) rename VERSION => src/pypi2nix/VERSION (100%) diff --git a/default.nix b/default.nix index 39515c0..145a784 100644 --- a/default.nix +++ b/default.nix @@ -4,7 +4,7 @@ let deps = import ./src/pypi2nix/deps.nix { inherit fetchurl; }; - version = builtins.readFile ./VERSION; + version = builtins.readFile ./src/pypi2nix/VERSION; in stdenv.mkDerivation rec { name = "pypi2nix-${version}"; srcs = with deps; [ src pip click setuptools zcbuildout zcrecipeegg ]; # six attrs effect ]; diff --git a/VERSION b/src/pypi2nix/VERSION similarity index 100% rename from VERSION rename to src/pypi2nix/VERSION diff --git a/src/pypi2nix/cli.py b/src/pypi2nix/cli.py index 43752c3..3c6b902 100644 --- a/src/pypi2nix/cli.py +++ b/src/pypi2nix/cli.py @@ -99,12 +99,10 @@ def main(nix_path, if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) - # TODO: create requirements.txt from buildout.cfg if buildout: raise click.exceptions.ClickException( u'Not yet implemented!') - # TODO: create requirements.txt from SPECIFICATION elif specification: raise click.exceptions.ClickException( u'Not yet implemented!') diff --git a/src/pypi2nix/stage1.py b/src/pypi2nix/stage1.py index f65ce7d..6af8ec9 100644 --- a/src/pypi2nix/stage1.py +++ b/src/pypi2nix/stage1.py @@ -48,7 +48,6 @@ def main(requirements_file, returncode = pypi2nix.utils.cmd(command) if returncode != 0: raise click.ClickException( - # TODO: better error u'While trying to run the command something went wrong.') return glob.glob(os.path.join(wheelhouse_dir, '*.dist-info')) diff --git a/src/pypi2nix/stage3.py b/src/pypi2nix/stage3.py index 44ab346..469ab81 100644 --- a/src/pypi2nix/stage3.py +++ b/src/pypi2nix/stage3.py @@ -1,7 +1,13 @@ +import sys import os import click -DEFAULT_NIX = ''' + +DEFAULT_NIX = '''# generated using pypi2nix tool (version: %(version)s) +# +# COMMAND: +# pypi2nix %(command_arguments)s +# { pkgs ? import {} }: @@ -36,7 +42,12 @@ in python ''' -GENERATED_NIX = ''' +GENERATED_NIX = '''# generated using pypi2nix tool (version: %s) +# +# COMMAND: +# pypi2nix %s +# + { pkgs, python, commonBuildInputs ? [], commonDoCheck ? false }: self: { @@ -72,7 +83,6 @@ def find_license(item): - # TODO: get license also from classifiers license = item.get('license') if license == 'ZPL 2.1': license = "lib.zpt21" @@ -104,6 +114,10 @@ def main(packages_metadata, generated_file = os.path.join(project_folder, '{}_generated.nix'.format(requirements_name)) overrides_file = os.path.join(project_folder, '{}_override.nix'.format(requirements_name)) + version_file = os.path.join(os.path.dirname(__file__), 'VERSION') + with open(version_file) as f: + version = f.read() + metadata_by_name = {x['name'].lower(): x for x in packages_metadata} generated_packages_metadata = [] @@ -118,7 +132,6 @@ def main(packages_metadata, generated_packages_metadata.append(dict( name=item.get("name", ""), version=item.get("version", ""), - # TODO: handle other formats (eg. wheel/egg) url=item.get("url", ""), hash_type="md5", hash_value=item.get("md5", ""), @@ -128,13 +141,15 @@ def main(packages_metadata, description=item.get("description", ""), )) - generated = GENERATED_NIX % '\n\n'.join( - GENERATED_PACKAGE_NIX % x for x in generated_packages_metadata) + generated = GENERATED_NIX % ( + version, ' '.join(sys.argv[1:]), '\n\n'.join( + GENERATED_PACKAGE_NIX % x for x in generated_packages_metadata)) - # TODO: include known overrides overrides = OVERRIDES_NIX % "" default = DEFAULT_NIX % dict( + version=version, + command_arguments=' '.join(sys.argv[1:]), python_version=python_version, extra_build_inputs=extra_build_inputs and "with pkgs; [ %s ]" % (' '.join(extra_build_inputs))