Skip to content

Commit

Permalink
Merge 19bd8ab into 2a299cc
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-barzilay committed May 9, 2021
2 parents 2a299cc + 19bd8ab commit ea0ac7e
Show file tree
Hide file tree
Showing 5 changed files with 1,486 additions and 213 deletions.
14 changes: 7 additions & 7 deletions .travis.yml
Expand Up @@ -4,17 +4,17 @@ language: python

matrix:
include:
- python: 3.9
env: TOX_ENV=py39
- python: 3.8
env: TOX_ENV=py38
- python: 3.7
env: TOX_ENV=py37
- python: 3.6
env: TOX_ENV=py36
- python: 3.5
env: TOX_ENV=py35
- python: 3.4
env: TOX_ENV=py34
- python: 2.7
env: TOX_ENV=py27
- python: pypy3
env: TOX_ENV=pypy3
- python: 3.6
- python: 3.9
env: TOX_ENV=flake8

# Use tox to run tests on Travis-CI to keep one unified method of running tests in any environment
Expand Down
20 changes: 4 additions & 16 deletions pipreqs/pipreqs.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""pipreqs - Generate pip requirements.txt file based on imports
Usage:
Expand Down Expand Up @@ -37,13 +36,11 @@
<gt> | e.g. Flask>=1.1.2
<no-pin> | e.g. Flask
"""
from __future__ import print_function, absolute_import
from contextlib import contextmanager
import os
import sys
import re
import logging
import codecs
import ast
import traceback
from docopt import docopt
Expand All @@ -58,14 +55,6 @@
re.compile(r'^from ((?!\.+).*?) import (?:.*)$')
]

if sys.version_info[0] > 2:
open_func = open
py2 = False
else:
open_func = codecs.open
py2 = True
py2_exclude = ["concurrent", "concurrent.futures"]


@contextmanager
def _open(filename=None, mode='r'):
Expand Down Expand Up @@ -122,7 +111,7 @@ def get_all_imports(
candidates += [os.path.splitext(fn)[0] for fn in files]
for file_name in files:
file_name = os.path.join(root, file_name)
with open_func(file_name, "r", encoding=encoding) as f:
with open(file_name, "r", encoding=encoding) as f:
contents = f.read()
try:
tree = ast.parse(contents)
Expand Down Expand Up @@ -157,7 +146,6 @@ def get_all_imports(
with open(join("stdlib"), "r") as f:
data = {x.strip() for x in f}

data = {x for x in data if x not in py2_exclude} if py2 else data
return list(packages - data)


Expand Down Expand Up @@ -214,7 +202,7 @@ def get_locally_installed_packages(encoding=None):
for item in files:
if "top_level" in item:
item = os.path.join(root, item)
with open_func(item, "r", encoding=encoding) as f:
with open(item, "r", encoding=encoding) as f:
package = root.split(os.sep)[-1].split("-")
try:
package_import = f.read().strip().split("\n")
Expand Down Expand Up @@ -309,7 +297,7 @@ def parse_requirements(file_):
delim = ["<", ">", "=", "!", "~"]

try:
f = open_func(file_, "r")
f = open(file_, "r")
except OSError:
logging.error("Failed on file: {}".format(file_))
raise
Expand Down Expand Up @@ -381,7 +369,7 @@ def clean(file_, imports):
to_write = []

try:
f = open_func(file_, "r+")
f = open(file_, "r+")
except OSError:
logging.error("Failed on file: {}".format(file_))
raise
Expand Down

0 comments on commit ea0ac7e

Please sign in to comment.