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

Commit 12dbf14

Browse files
committed
Enforce flake8 complience
We include flake8 in checkPhase now
1 parent 1229e50 commit 12dbf14

File tree

12 files changed

+105
-66
lines changed

12 files changed

+105
-66
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/result*
66
/examples/generated*
77
/deploy_rsa
8+
*~

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ before_install:
2828
- export SSL_CERT_FILE=$PWD/result-cacert/etc/ssl/certs/ca-bundle.crt
2929
- 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
3030
- echo 'binary-caches = https://cache.nixos.org/ https://travis.garbas.si/pypi2nix/' | sudo tee -a /etc/nix/nix.conf > /dev/null
31-
- if [ "$TRAVIS_PULL_REQUEST" != "true" -a "$TRAVIS_BRANCH" = "master" ]; then
31+
- if [ "$TRAVIS_PULL_REQUEST" = "false" -a "$TRAVIS_BRANCH" = "master" ]; then
3232
openssl aes-256-cbc -K $encrypted_0cfcc1944c73_key -iv $encrypted_0cfcc1944c73_iv -in deploy_rsa.enc -out deploy_rsa -d;
3333
eval "$(ssh-agent -s)";
3434
chmod 600 $TRAVIS_BUILD_DIR/deploy_rsa;
3535
ssh-add $TRAVIS_BUILD_DIR/deploy_rsa;
3636
fi
3737
script:
3838
- cd examples && make $EXAMPLE && cd ..
39-
- if [ "$TRAVIS_PULL_REQUEST" != "true" -a "$TRAVIS_BRANCH" = "master" ]; then
39+
- if [ "$TRAVIS_PULL_REQUEST" = "false" -a "$TRAVIS_BRANCH" = "master" ]; then
4040
mkdir nars/;
4141
nix-push --dest "$PWD/nars/" --force ./examples/$EXAMPLE;
4242
fi
4343
after_success:
44-
- if [ "$TRAVIS_PULL_REQUEST" != "true" -a "$TRAVIS_BRANCH" = "master" ]; then
44+
- if [ "$TRAVIS_PULL_REQUEST" = "false" -a "$TRAVIS_BRANCH" = "master" ]; then
4545
rsync -avh --ignore-existing $TRAVIS_BUILD_DIR/nars/ [email protected]:/var/travis/pypi2nix/;
4646
fi
4747

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
flakes:
2+
nix-shell '<nixpkgs>' -p python3Packages.flake8 --command \
3+
'flake8 src/ --ignore E501'
4+
5+
.PHONY: flakes

default.nix

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{ stdenv, fetchurl, python, zip, makeWrapper, nix, nix-prefetch-scripts
1+
{ stdenv, fetchurl, zip, makeWrapper, nix, nix-prefetch-scripts
2+
, pythonPackages
23
, src ? { outPath = ./.; name = "pypi2nix"; }
34
}:
45

@@ -23,7 +24,11 @@ in stdenv.mkDerivation rec {
2324
click
2425
requests
2526
];
26-
buildInputs = [ python zip makeWrapper nix.out nix-prefetch-scripts ];
27+
buildInputs = [
28+
pythonPackages.python pythonPackages.flake8
29+
zip makeWrapper nix.out nix-prefetch-scripts
30+
];
31+
doCheck = true;
2732
sourceRoot = ".";
2833

2934
postUnpack = ''
@@ -50,7 +55,7 @@ in stdenv.mkDerivation rec {
5055
commonPhase = ''
5156
mkdir -p $out/bin
5257
53-
echo "#!${python.interpreter}" > $out/bin/pypi2nix
58+
echo "#!${pythonPackages.python.interpreter}" > $out/bin/pypi2nix
5459
echo "import pypi2nix.cli" >> $out/bin/pypi2nix
5560
echo "pypi2nix.cli.main()" >> $out/bin/pypi2nix
5661
@@ -59,6 +64,10 @@ in stdenv.mkDerivation rec {
5964
export PYTHONPATH=$out/pkgs:$PYTHONPATH
6065
'';
6166

67+
checkPhase = ''
68+
flake8 ${src}/src
69+
'';
70+
6271
installPhase = commonPhase + ''
6372
wrapProgram $out/bin/pypi2nix --prefix PYTHONPATH : "$PYTHONPATH"
6473
'';

release.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ let
1010
if builtins.elem system supportedSystems
1111
then import ./default.nix {
1212
inherit (pkgs) stdenv fetchurl zip makeWrapper nix nix-prefetch-scripts;
13-
python = pkgs.python35;
1413
src = pypi2nix;
14+
pythonPackages = pkgs.python3Packages;
1515
}
1616
else abort "Unsupported system type: ${system}";
1717

shell.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
let
77
pkgs = import nixpkgs {};
8-
python = (builtins.getAttr "python${pythonVersion}Packages" pkgs).python;
8+
pythonPackages = builtins.getAttr "python${pythonVersion}Packages" pkgs;
99
in import ./default.nix {
10-
inherit src python;
10+
inherit src pythonPackages;
1111
inherit (pkgs) stdenv fetchurl zip makeWrapper nix nix-prefetch-scripts;
1212
}

src/pypi2nix/cli.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,13 @@ def handle_requirements_file(project_dir, requirements_file):
195195
with open(new_requirements_file, "w+") as f2:
196196
for requirements_line in f1.readlines():
197197
if requirements_line.startswith("-e git+") or \
198-
requirements_line.startswith("-e hg+"):
198+
requirements_line.startswith("-e hg+"):
199199
pass
200200
elif requirements_line.startswith("-e"):
201201
requirements_line = requirements_line.strip()[3:]
202202
try:
203-
tmp_path, egg = requirements_line.strip().split('#')
203+
tmp_path, egg = requirements_line.strip() \
204+
.split('#')
204205
tmp_name = egg.split('egg=')[1]
205206
_tmp = tmp_path.split('[')
206207
if len(_tmp) > 1:
@@ -229,7 +230,7 @@ def handle_requirements_file(project_dir, requirements_file):
229230
elif requirements_line.startswith("-r ./"):
230231
requirements_file2 = os.path.abspath(os.path.join(
231232
os.path.dirname(requirements_file),
232-
requirements_line.strip()[3:]
233+
requirements_line.strip()[3:]
233234
))
234235
new_requirements_file2 = handle_requirements_file(
235236
project_dir, requirements_file2)
@@ -251,7 +252,8 @@ def handle_requirements_file(project_dir, requirements_file):
251252
click.echo('')
252253

253254
if buildout:
254-
click.echo('Stage0: Generating requirements.txt from buildout configuration ...')
255+
click.echo('Stage0: Generating requirements.txt from buildout '
256+
'configuration ...')
255257
buildout_requirements = pypi2nix.stage0.main(
256258
verbose=verbose,
257259
buildout_file=buildout,
@@ -319,7 +321,6 @@ def handle_requirements_file(project_dir, requirements_file):
319321
current_dir=current_dir,
320322
)
321323

322-
323324
click.echo('')
324325
click.echo('Nix expressions generated successfully.')
325326
click.echo('')

src/pypi2nix/stage0.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,7 @@ def main(verbose,
4040
raise click.ClickException(
4141
u'While trying to run the command something went wrong.')
4242

43-
44-
return buildout_file and os.path.join(project_dir, 'buildout_requirements.txt') or None
43+
return buildout_file and \
44+
os.path.join(project_dir,
45+
'buildout_requirements.txt') \
46+
or None

src/pypi2nix/stage1.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def main(verbose,
7171

7272
returncode, output = pypi2nix.utils.cmd(command, verbose != 0)
7373
if returncode != 0 or \
74-
output.endswith('ERROR: Failed to build one or more wheels'):
74+
output.endswith('ERROR: Failed to build one or more wheels'):
7575
if verbose == 0:
7676
click.echo(output)
7777

@@ -80,9 +80,10 @@ def main(verbose,
8080
# trying to recognize the problem and provide more meanigful error
8181
# message
8282
no_matching_dist = "No matching distribution found for "
83-
no_pg_config = "Error: pg_config executable not found."
8483
if no_matching_dist in output:
85-
dist_name = output[output.find(no_matching_dist) + len(no_matching_dist):]
84+
dist_name = output[
85+
output.find(no_matching_dist) + len(no_matching_dist):
86+
]
8687
dist_name = dist_name[:dist_name.find(' (from')]
8788
message = (
8889
"Most likely `%s` package does not have source (zip/tar.bz) "
@@ -94,7 +95,8 @@ def main(verbose,
9495
if click.confirm('Do you want to report above issue (a browser '
9596
'will open with prefilled details of issue)?'):
9697
title = "Error when running pypi2nix command"
97-
body = "# Description\n\n<detailed description of error here>\n\n"
98+
body = "# Description\n\n<detailed description of error "
99+
"here>\n\n"
98100
body += "# Traceback \n\n```bash\n"
99101
body += "% pypi2nix --version\n"
100102
with open(os.path.join(HERE, 'VERSION')) as f:

src/pypi2nix/stage2.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Parse metadata from .dist-info directories in a wheelhouse."""
2+
# flake8: noqa: E501
23

34
import click
45
import hashlib
@@ -56,7 +57,6 @@ def extract_deps(metadata):
5657

5758
return list(set(deps))
5859

59-
6060
all_classifiers = {
6161
'License :: Aladdin Free Public License (AFPL)': None,
6262
'License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication': None,
@@ -226,7 +226,7 @@ def find_release(wheel_cache_dir, wheel, wheel_data):
226226
if not _releases:
227227
for _version, _releases_tmp in wheel_data['releases'].items():
228228
if pkg_resources.parse_version(wheel['version']) == \
229-
pkg_resources.parse_version(_version):
229+
pkg_resources.parse_version(_version):
230230
_release_version = _version
231231
_releases = _releases_tmp
232232
break
@@ -294,9 +294,8 @@ def process_wheel(wheel_cache_dir, wheel, sources, verbose, index=INDEX_URL,
294294
release['hash_type'] = 'sha256'
295295

296296
repo_type = sources[wheel['name']]['type']
297-
if repo_type is None and \
298-
(release['url'].startswith('http://') or \
299-
release['url'].startswith('https://')):
297+
if repo_type is None and (release['url'].startswith('http://') or
298+
release['url'].startswith('https://')):
300299

301300
release['fetch_type'] = 'fetchurl'
302301

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

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

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

430-
elif line.startswith('http://') or line.startswith('https://') or \
431-
line.startswith('git+') or line.startswith('hg+'):
427+
elif (line.startswith('http://') or
428+
line.startswith('https://') or
429+
line.startswith('git+') or
430+
line.startswith('hg+')):
432431
try:
433432
url, egg = line.split('#')
434433
name = egg.split('egg=')[1]

src/pypi2nix/stage3.py

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
inherit (pkgs) makeWrapper;
1919
inherit (pkgs.stdenv.lib) fix' extends inNixShell;
2020
21-
pythonPackages = import "${toString pkgs.path}/pkgs/top-level/python-packages.nix" {
21+
pythonPackages =
22+
import "${toString pkgs.path}/pkgs/top-level/python-packages.nix" {
2223
inherit pkgs;
2324
inherit (pkgs) stdenv;
2425
python = pkgs.%(python_version)s;
@@ -35,8 +36,10 @@
3536
buildInputs = [ makeWrapper ] ++ (builtins.attrValues pkgs);
3637
buildCommand = ''
3738
mkdir -p $out/bin
38-
ln -s ${pythonPackages.python.interpreter} $out/bin/${pythonPackages.python.executable}
39-
for dep in ${builtins.concatStringsSep " " (builtins.attrValues pkgs)}; do
39+
ln -s ${pythonPackages.python.interpreter} \
40+
$out/bin/${pythonPackages.python.executable}
41+
for dep in ${builtins.concatStringsSep " " \
42+
(builtins.attrValues pkgs)}; do
4043
if [ -d "$dep/bin" ]; then
4144
for prog in "$dep/bin/"*; do
4245
if [ -f $prog ]; then
@@ -67,7 +70,8 @@
6770
6871
python = withPackages {};
6972
70-
generated = import %(generated_file)s { inherit pkgs python commonBuildInputs commonDoCheck; };
73+
generated = import %(generated_file)s
74+
{ inherit pkgs python commonBuildInputs commonDoCheck; };
7175
overrides = import %(overrides_file)s { inherit pkgs python; };
7276
7377
in python.withPackages (fix' (extends overrides generated))
@@ -122,10 +126,18 @@ def main(packages_metadata,
122126
'''Create Nix expressions.
123127
'''
124128

125-
default_file = os.path.join(current_dir, '{}.nix'.format(requirements_name))
126-
generated_file = os.path.join(current_dir, '{}_generated.nix'.format(requirements_name))
127-
overrides_file = os.path.join(current_dir, '{}_override.nix'.format(requirements_name))
128-
frozen_file = os.path.join(current_dir, '{}_frozen.txt'.format(requirements_name))
129+
default_file = os.path.join(
130+
current_dir, '{}.nix'.format(requirements_name)
131+
)
132+
generated_file = os.path.join(
133+
current_dir, '{}_generated.nix'.format(requirements_name)
134+
)
135+
overrides_file = os.path.join(
136+
current_dir, '{}_override.nix'.format(requirements_name)
137+
)
138+
frozen_file = os.path.join(
139+
current_dir, '{}_frozen.txt'.format(requirements_name)
140+
)
129141

130142
version_file = os.path.join(os.path.dirname(__file__), 'VERSION')
131143
with open(version_file) as f:
@@ -137,36 +149,41 @@ def main(packages_metadata,
137149
for item in sorted(packages_metadata, key=lambda x: x['name']):
138150
propagatedBuildInputs = '[ ]'
139151
if item.get('deps'):
140-
deps = [x for x in item['deps'] if x.lower() in metadata_by_name.keys()]
152+
deps = [x for x in item['deps']
153+
if x.lower() in metadata_by_name.keys()]
141154
if deps:
142155
propagatedBuildInputs = "[\n%s\n ]" % (
143156
'\n'.join(sorted(
144-
[' self."%s"' % (metadata_by_name[x.lower()]['name'])
145-
for x in deps if x not in [item['name']]
146-
])))
157+
[' self."%s"' %
158+
(metadata_by_name[x.lower()]['name'])
159+
for x in deps if x not in [item['name']]]
160+
)))
147161
fetch_type = item.get('fetch_type', None)
148162
if fetch_type == 'path':
149-
fetch_expression = './' + os.path.relpath(item['url'], current_dir)
163+
fetch_expression = './' + os.path.relpath(item['url'], current_dir)
150164
elif fetch_type == 'fetchgit':
151-
fetch_expression = 'pkgs.fetchgit { url = "%(url)s"; %(hash_type)s = "%(hash_value)s"; rev = "%(rev)s"; }' % dict(
152-
url=item['url'],
153-
hash_type=item['hash_type'],
154-
hash_value=item['hash_value'],
155-
rev=item['rev']
156-
)
165+
fetch_expression = 'pkgs.fetchgit { url = "%(url)s"; '\
166+
'%(hash_type)s = "%(hash_value)s"; rev = "%(rev)s"; }' % dict(
167+
url=item['url'],
168+
hash_type=item['hash_type'],
169+
hash_value=item['hash_value'],
170+
rev=item['rev']
171+
)
157172
elif fetch_type == 'fetchhg':
158-
fetch_expression = 'pkgs.fetchhg { url = "%(url)s"; %(hash_type)s = "%(hash_value)s"; rev = "%(rev)s"; }' % dict(
159-
url=item['url'],
160-
hash_type=item['hash_type'],
161-
hash_value=item['hash_value'],
162-
rev=item['rev']
163-
)
173+
fetch_expression = 'pkgs.fetchhg { url = "%(url)s"; '\
174+
'%(hash_type)s = "%(hash_value)s"; rev = "%(rev)s"; }' % dict(
175+
url=item['url'],
176+
hash_type=item['hash_type'],
177+
hash_value=item['hash_value'],
178+
rev=item['rev']
179+
)
164180
else:
165-
fetch_expression='pkgs.fetchurl { url = "%(url)s"; %(hash_type)s = "%(hash_value)s"; }' % dict(
166-
url=item['url'],
167-
hash_type=item['hash_type'],
168-
hash_value=item['hash_value'],
169-
)
181+
fetch_expression = 'pkgs.fetchurl { url = "%(url)s"; '\
182+
'%(hash_type)s = "%(hash_value)s"; }' % dict(
183+
url=item['url'],
184+
hash_type=item['hash_type'],
185+
hash_value=item['hash_value'],
186+
)
170187

171188
generated_packages_metadata.append(dict(
172189
name=item.get("name", ""),
@@ -188,9 +205,11 @@ def main(packages_metadata,
188205
version=version,
189206
command_arguments=' '.join(sys.argv[1:]),
190207
python_version=python_version,
191-
extra_build_inputs=extra_build_inputs
192-
and "with pkgs; [ %s ]" % (' '.join(extra_build_inputs))
193-
or "[]",
208+
extra_build_inputs=(
209+
extra_build_inputs and
210+
"with pkgs; [ %s ]" % (' '.join(extra_build_inputs)) or
211+
"[]"
212+
),
194213
generated_file='.' + generated_file[len(current_dir):],
195214
overrides_file='.' + overrides_file[len(current_dir):],
196215
enable_tests=str(enable_tests).lower(),

0 commit comments

Comments
 (0)