Skip to content
This repository was archived by the owner on Oct 7, 2022. It is now read-only.

Apply flake8 to src #105

Merged
merged 1 commit into from
Feb 18, 2017
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/result*
/examples/generated*
/deploy_rsa
*~
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ before_install:
- export SSL_CERT_FILE=$PWD/result-cacert/etc/ssl/certs/ca-bundle.crt
- sudo mkdir -p /etc/ssl/certs/ && sudo rm -f /etc/ssl/certs/ca-certificates.crt && sudo ln -s $PWD/result-cacert/etc/ssl/certs/ca-bundle.crt /etc/ssl/certs/ca-certificates.crt
- echo 'binary-caches = https://cache.nixos.org/ https://travis.garbas.si/pypi2nix/' | sudo tee -a /etc/nix/nix.conf > /dev/null
- if [ "$TRAVIS_PULL_REQUEST" != "true" -a "$TRAVIS_BRANCH" = "master" ]; then
- if [ "$TRAVIS_PULL_REQUEST" = "false" -a "$TRAVIS_BRANCH" = "master" ]; then
openssl aes-256-cbc -K $encrypted_0cfcc1944c73_key -iv $encrypted_0cfcc1944c73_iv -in deploy_rsa.enc -out deploy_rsa -d;
eval "$(ssh-agent -s)";
chmod 600 $TRAVIS_BUILD_DIR/deploy_rsa;
ssh-add $TRAVIS_BUILD_DIR/deploy_rsa;
fi
script:
- cd examples && make $EXAMPLE && cd ..
- if [ "$TRAVIS_PULL_REQUEST" != "true" -a "$TRAVIS_BRANCH" = "master" ]; then
- if [ "$TRAVIS_PULL_REQUEST" = "false" -a "$TRAVIS_BRANCH" = "master" ]; then
mkdir nars/;
nix-push --dest "$PWD/nars/" --force ./examples/$EXAMPLE;
fi
after_success:
- if [ "$TRAVIS_PULL_REQUEST" != "true" -a "$TRAVIS_BRANCH" = "master" ]; then
- if [ "$TRAVIS_PULL_REQUEST" = "false" -a "$TRAVIS_BRANCH" = "master" ]; then
rsync -avh --ignore-existing $TRAVIS_BUILD_DIR/nars/ [email protected]:/var/travis/pypi2nix/;
fi

5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flakes:
nix-shell '<nixpkgs>' -p python3Packages.flake8 --command \
'flake8 src/ --ignore E501'

.PHONY: flakes
15 changes: 12 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ stdenv, fetchurl, python, zip, makeWrapper, nix, nix-prefetch-scripts
{ stdenv, fetchurl, zip, makeWrapper, nix, nix-prefetch-scripts
, pythonPackages
, src ? { outPath = ./.; name = "pypi2nix"; }
}:

Expand All @@ -23,7 +24,11 @@ in stdenv.mkDerivation rec {
click
requests
];
buildInputs = [ python zip makeWrapper nix.out nix-prefetch-scripts ];
buildInputs = [
pythonPackages.python pythonPackages.flake8
zip makeWrapper nix.out nix-prefetch-scripts
];
doCheck = true;
sourceRoot = ".";

postUnpack = ''
Expand All @@ -50,7 +55,7 @@ in stdenv.mkDerivation rec {
commonPhase = ''
mkdir -p $out/bin

echo "#!${python.interpreter}" > $out/bin/pypi2nix
echo "#!${pythonPackages.python.interpreter}" > $out/bin/pypi2nix
echo "import pypi2nix.cli" >> $out/bin/pypi2nix
echo "pypi2nix.cli.main()" >> $out/bin/pypi2nix

Expand All @@ -59,6 +64,10 @@ in stdenv.mkDerivation rec {
export PYTHONPATH=$out/pkgs:$PYTHONPATH
'';

checkPhase = ''
flake8 ${src}/src
'';

installPhase = commonPhase + ''
wrapProgram $out/bin/pypi2nix --prefix PYTHONPATH : "$PYTHONPATH"
'';
Expand Down
2 changes: 1 addition & 1 deletion release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ let
if builtins.elem system supportedSystems
then import ./default.nix {
inherit (pkgs) stdenv fetchurl zip makeWrapper nix nix-prefetch-scripts;
python = pkgs.python35;
src = pypi2nix;
pythonPackages = pkgs.python3Packages;
}
else abort "Unsupported system type: ${system}";

Expand Down
4 changes: 2 additions & 2 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

let
pkgs = import nixpkgs {};
python = (builtins.getAttr "python${pythonVersion}Packages" pkgs).python;
pythonPackages = builtins.getAttr "python${pythonVersion}Packages" pkgs;
in import ./default.nix {
inherit src python;
inherit src pythonPackages;
inherit (pkgs) stdenv fetchurl zip makeWrapper nix nix-prefetch-scripts;
}
11 changes: 6 additions & 5 deletions src/pypi2nix/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,13 @@ def handle_requirements_file(project_dir, requirements_file):
with open(new_requirements_file, "w+") as f2:
for requirements_line in f1.readlines():
if requirements_line.startswith("-e git+") or \
requirements_line.startswith("-e hg+"):
requirements_line.startswith("-e hg+"):
pass
elif requirements_line.startswith("-e"):
requirements_line = requirements_line.strip()[3:]
try:
tmp_path, egg = requirements_line.strip().split('#')
tmp_path, egg = requirements_line.strip() \
.split('#')
tmp_name = egg.split('egg=')[1]
_tmp = tmp_path.split('[')
if len(_tmp) > 1:
Expand Down Expand Up @@ -229,7 +230,7 @@ def handle_requirements_file(project_dir, requirements_file):
elif requirements_line.startswith("-r ./"):
requirements_file2 = os.path.abspath(os.path.join(
os.path.dirname(requirements_file),
requirements_line.strip()[3:]
requirements_line.strip()[3:]
))
new_requirements_file2 = handle_requirements_file(
project_dir, requirements_file2)
Expand All @@ -251,7 +252,8 @@ def handle_requirements_file(project_dir, requirements_file):
click.echo('')

if buildout:
click.echo('Stage0: Generating requirements.txt from buildout configuration ...')
click.echo('Stage0: Generating requirements.txt from buildout '
'configuration ...')
buildout_requirements = pypi2nix.stage0.main(
verbose=verbose,
buildout_file=buildout,
Expand Down Expand Up @@ -319,7 +321,6 @@ def handle_requirements_file(project_dir, requirements_file):
current_dir=current_dir,
)


click.echo('')
click.echo('Nix expressions generated successfully.')
click.echo('')
Expand Down
6 changes: 4 additions & 2 deletions src/pypi2nix/stage0.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ def main(verbose,
raise click.ClickException(
u'While trying to run the command something went wrong.')


return buildout_file and os.path.join(project_dir, 'buildout_requirements.txt') or None
return buildout_file and \
os.path.join(project_dir,
'buildout_requirements.txt') \
or None
10 changes: 6 additions & 4 deletions src/pypi2nix/stage1.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def main(verbose,

returncode, output = pypi2nix.utils.cmd(command, verbose != 0)
if returncode != 0 or \
output.endswith('ERROR: Failed to build one or more wheels'):
output.endswith('ERROR: Failed to build one or more wheels'):
if verbose == 0:
click.echo(output)

Expand All @@ -80,9 +80,10 @@ def main(verbose,
# trying to recognize the problem and provide more meanigful error
# message
no_matching_dist = "No matching distribution found for "
no_pg_config = "Error: pg_config executable not found."
if no_matching_dist in output:
dist_name = output[output.find(no_matching_dist) + len(no_matching_dist):]
dist_name = output[
output.find(no_matching_dist) + len(no_matching_dist):
]
dist_name = dist_name[:dist_name.find(' (from')]
message = (
"Most likely `%s` package does not have source (zip/tar.bz) "
Expand All @@ -94,7 +95,8 @@ def main(verbose,
if click.confirm('Do you want to report above issue (a browser '
'will open with prefilled details of issue)?'):
title = "Error when running pypi2nix command"
body = "# Description\n\n<detailed description of error here>\n\n"
body = "# Description\n\n<detailed description of error "
"here>\n\n"
body += "# Traceback \n\n```bash\n"
body += "% pypi2nix --version\n"
with open(os.path.join(HERE, 'VERSION')) as f:
Expand Down
17 changes: 8 additions & 9 deletions src/pypi2nix/stage2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Parse metadata from .dist-info directories in a wheelhouse."""
# flake8: noqa: E501

import click
import hashlib
Expand Down Expand Up @@ -56,7 +57,6 @@ def extract_deps(metadata):

return list(set(deps))


all_classifiers = {
'License :: Aladdin Free Public License (AFPL)': None,
'License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication': None,
Expand Down Expand Up @@ -226,7 +226,7 @@ def find_release(wheel_cache_dir, wheel, wheel_data):
if not _releases:
for _version, _releases_tmp in wheel_data['releases'].items():
if pkg_resources.parse_version(wheel['version']) == \
pkg_resources.parse_version(_version):
pkg_resources.parse_version(_version):
_release_version = _version
_releases = _releases_tmp
break
Expand Down Expand Up @@ -294,9 +294,8 @@ def process_wheel(wheel_cache_dir, wheel, sources, verbose, index=INDEX_URL,
release['hash_type'] = 'sha256'

repo_type = sources[wheel['name']]['type']
if repo_type is None and \
(release['url'].startswith('http://') or \
release['url'].startswith('https://')):
if repo_type is None and (release['url'].startswith('http://') or
release['url'].startswith('https://')):

release['fetch_type'] = 'fetchurl'

Expand Down Expand Up @@ -388,14 +387,12 @@ def process_wheel(wheel_cache_dir, wheel, sources, verbose, index=INDEX_URL,
else:
raise click.ClickException('Source type `{}` not implemented'.format(repo_type))


else:
url = "{}/{}/json".format(index, wheel['name'])
r = requests.get(url, timeout=None)
r.raise_for_status() # TODO: handle this nicer
wheel_data = r.json()


if not wheel_data.get('releases'):
raise click.ClickException(
"Unable to find releases for packge {name}".format(**wheel))
Expand Down Expand Up @@ -427,8 +424,10 @@ def main(verbose, wheels, requirements_files, wheel_cache_dir, index=INDEX_URL,
"Source for path `%s` does not exists." % line
)

elif line.startswith('http://') or line.startswith('https://') or \
line.startswith('git+') or line.startswith('hg+'):
elif (line.startswith('http://') or
line.startswith('https://') or
line.startswith('git+') or
line.startswith('hg+')):
try:
url, egg = line.split('#')
name = egg.split('egg=')[1]
Expand Down
85 changes: 52 additions & 33 deletions src/pypi2nix/stage3.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
inherit (pkgs) makeWrapper;
inherit (pkgs.stdenv.lib) fix' extends inNixShell;

pythonPackages = import "${toString pkgs.path}/pkgs/top-level/python-packages.nix" {
pythonPackages =
import "${toString pkgs.path}/pkgs/top-level/python-packages.nix" {
inherit pkgs;
inherit (pkgs) stdenv;
python = pkgs.%(python_version)s;
Expand All @@ -35,8 +36,10 @@
buildInputs = [ makeWrapper ] ++ (builtins.attrValues pkgs);
buildCommand = ''
mkdir -p $out/bin
ln -s ${pythonPackages.python.interpreter} $out/bin/${pythonPackages.python.executable}
for dep in ${builtins.concatStringsSep " " (builtins.attrValues pkgs)}; do
ln -s ${pythonPackages.python.interpreter} \
$out/bin/${pythonPackages.python.executable}
for dep in ${builtins.concatStringsSep " " \
(builtins.attrValues pkgs)}; do
if [ -d "$dep/bin" ]; then
for prog in "$dep/bin/"*; do
if [ -f $prog ]; then
Expand Down Expand Up @@ -67,7 +70,8 @@

python = withPackages {};

generated = import %(generated_file)s { inherit pkgs python commonBuildInputs commonDoCheck; };
generated = import %(generated_file)s
{ inherit pkgs python commonBuildInputs commonDoCheck; };
overrides = import %(overrides_file)s { inherit pkgs python; };

in python.withPackages (fix' (extends overrides generated))
Expand Down Expand Up @@ -122,10 +126,18 @@ def main(packages_metadata,
'''Create Nix expressions.
'''

default_file = os.path.join(current_dir, '{}.nix'.format(requirements_name))
generated_file = os.path.join(current_dir, '{}_generated.nix'.format(requirements_name))
overrides_file = os.path.join(current_dir, '{}_override.nix'.format(requirements_name))
frozen_file = os.path.join(current_dir, '{}_frozen.txt'.format(requirements_name))
default_file = os.path.join(
current_dir, '{}.nix'.format(requirements_name)
)
generated_file = os.path.join(
current_dir, '{}_generated.nix'.format(requirements_name)
)
overrides_file = os.path.join(
current_dir, '{}_override.nix'.format(requirements_name)
)
frozen_file = os.path.join(
current_dir, '{}_frozen.txt'.format(requirements_name)
)

version_file = os.path.join(os.path.dirname(__file__), 'VERSION')
with open(version_file) as f:
Expand All @@ -137,36 +149,41 @@ def main(packages_metadata,
for item in sorted(packages_metadata, key=lambda x: x['name']):
propagatedBuildInputs = '[ ]'
if item.get('deps'):
deps = [x for x in item['deps'] if x.lower() in metadata_by_name.keys()]
deps = [x for x in item['deps']
if x.lower() in metadata_by_name.keys()]
if deps:
propagatedBuildInputs = "[\n%s\n ]" % (
'\n'.join(sorted(
[' self."%s"' % (metadata_by_name[x.lower()]['name'])
for x in deps if x not in [item['name']]
])))
[' self."%s"' %
(metadata_by_name[x.lower()]['name'])
for x in deps if x not in [item['name']]]
)))
fetch_type = item.get('fetch_type', None)
if fetch_type == 'path':
fetch_expression = './' + os.path.relpath(item['url'], current_dir)
fetch_expression = './' + os.path.relpath(item['url'], current_dir)
elif fetch_type == 'fetchgit':
fetch_expression = 'pkgs.fetchgit { url = "%(url)s"; %(hash_type)s = "%(hash_value)s"; rev = "%(rev)s"; }' % dict(
url=item['url'],
hash_type=item['hash_type'],
hash_value=item['hash_value'],
rev=item['rev']
)
fetch_expression = 'pkgs.fetchgit { url = "%(url)s"; '\
'%(hash_type)s = "%(hash_value)s"; rev = "%(rev)s"; }' % dict(
url=item['url'],
hash_type=item['hash_type'],
hash_value=item['hash_value'],
rev=item['rev']
)
elif fetch_type == 'fetchhg':
fetch_expression = 'pkgs.fetchhg { url = "%(url)s"; %(hash_type)s = "%(hash_value)s"; rev = "%(rev)s"; }' % dict(
url=item['url'],
hash_type=item['hash_type'],
hash_value=item['hash_value'],
rev=item['rev']
)
fetch_expression = 'pkgs.fetchhg { url = "%(url)s"; '\
'%(hash_type)s = "%(hash_value)s"; rev = "%(rev)s"; }' % dict(
url=item['url'],
hash_type=item['hash_type'],
hash_value=item['hash_value'],
rev=item['rev']
)
else:
fetch_expression='pkgs.fetchurl { url = "%(url)s"; %(hash_type)s = "%(hash_value)s"; }' % dict(
url=item['url'],
hash_type=item['hash_type'],
hash_value=item['hash_value'],
)
fetch_expression = 'pkgs.fetchurl { url = "%(url)s"; '\
'%(hash_type)s = "%(hash_value)s"; }' % dict(
url=item['url'],
hash_type=item['hash_type'],
hash_value=item['hash_value'],
)

generated_packages_metadata.append(dict(
name=item.get("name", ""),
Expand All @@ -188,9 +205,11 @@ def main(packages_metadata,
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))
or "[]",
extra_build_inputs=(
extra_build_inputs and
"with pkgs; [ %s ]" % (' '.join(extra_build_inputs)) or
"[]"
),
generated_file='.' + generated_file[len(current_dir):],
overrides_file='.' + overrides_file[len(current_dir):],
enable_tests=str(enable_tests).lower(),
Expand Down
Loading