Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_reqs_from_file(file):
file_path = realpath(file)
# parse_requirements() returns generator of pip.req.InstallRequirement
# objects
install_requirements = parse_requirements(file_path, session=PipSession)
# reqs is a list of requirement
# e.g. ['django==1.5.1', 'mezzanine==1.4.6']
return [str(ir.req) for ir in install_requirements]
import pip
import bzt
# thanks to pip there are two :incompatible ways to parse requirements.txt
if hasattr(pip, '__version__') and LooseVersion(str(pip.__version__)) >= LooseVersion('10.0.0'):
# new versions of pip require a session
from pip._internal import req, download
requirements = req.parse_requirements('requirements.txt', session=download.PipSession())
elif hasattr(pip, '__version__') and LooseVersion(str(pip.__version__)) >= LooseVersion('7.0'):
# new versions of pip require a session
requirements = pip.req.parse_requirements('requirements.txt', session=pip.download.PipSession())
else:
# old versions do not
requirements = pip.req.parse_requirements('requirements.txt')
requires = [str(item.req) for item in requirements]
setup(
name="bzt",
version=bzt.VERSION,
description='Taurus Tool for Continuous Testing',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
author='Andrey Pokhilko',
author_email='andrey@blazemeter.com',
url='http://gettaurus.org/',
download_url='http://gettaurus.org/docs/DeveloperGuide/#Python-Egg-Snapshots',
license='Apache 2.0',
install_requires=requires,
packages=['bzt', 'bzt.engine', 'bzt.six', 'bzt.jmx', 'bzt.modules',
from setuptools import setup
from pip.req import parse_requirements
parsed_reqs = parse_requirements('requirements.txt', session=False)
requirements = [str(x.req) for x in parsed_reqs]
setup (name='trials',
version='0.1',
description='Tiny Bayesian A/B testing library',
author='Bogdan Kulynych',
author_email='hello@bogdankulynych.me',
url='https://github.com/bogdan-kulynych/trials',
packages=['trials', 'trials.tests'],
license='MIT',
keywords='A/B testing, data analysis, statistics',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
def get_pip_requirements(fname=os.path.join(config_path.LIB_PATH,
'requirements.txt')):
"""
Gets the PIP requirements from a text file. If the files does not exists
or is not readable, it returns None
Arguments:
fname -- (optional) the requirement text file (Default:
"client/requirements.txt")
Returns:
A list of pip requirement objects or None
"""
logger = logging.getLogger(__name__)
if os.access(fname, os.R_OK):
reqs = list(pip.req.parse_requirements(fname))
logger.debug("Found %d PIP requirements in file '%s'", len(reqs),
fname)
return reqs
else:
logger.debug("PIP requirements file '%s' not found or not readable",
fname)
def verify_dependencies(root_dir):
"""Goes over the requirements file, parses it and checks if all requirements are satisfied
:param root_dir: Root directory for OWTF
:type root_dir: `str`
:return:
:rtype: None
"""
# Get all the installed libraries
# installed_libraries = {"tornado": "version"}
installed_libraries = dict((i.project_name, i.version) for i in pip.get_installed_distributions())
# Get all the libraries required by owtf
# owtf_libraries = ["tornado", "lxml"...]
owtf_reqs = pip.req.parse_requirements(os.path.join(root_dir, "install", "owtf.pip"), session=uuid.uuid1())
owtf_libraries = [req.req.name for req in owtf_reqs]
# Iterate over requirements and check if existed
missing_libraries = []
for library_name in owtf_libraries:
if library_name not in list(installed_libraries.keys()):
# Check if the module is installed via package manager
if not is_present(library_name):
missing_libraries.append(library_name)
# If there are missing libraries bail out :P
if len(missing_libraries) > 0:
print("The following python libraries seem missing : ")
print("\t%s\n" % (','.join(missing_libraries)))
print("Haven't you run the install script? ")
print("\t%s\n" % ("python2 install/install.py"))
for user in users:
packages.extend([x[1] for x in xmlrpc.user_packages(user)
if x[1] is not None])
requirements = None
if args.requirement_file:
class fakeopts:
default_vcs = ""
skip_requirements_regex = ""
# a list of requirements files to process
files = args.items
packages = []
requirements = {}
for filename in files:
for req in parse_requirements(filename, options=fakeopts):
requirements.setdefault(req.name, []).append(req.req)
packages.append(req.name)
# Should we run in verbose mode
verbose = args.verbose
session = requests.session()
session.verify = False
for package in packages:
print("")
print("Download candidates for %s" % package)
print("========================" + ("=" * len(package)))
# Grab the page from PyPI
url = "https://pypi.python.org/simple/%s/" % package
def do(txt_file):
click.secho('-> generating: generated.json', fg='cyan')
results = {}
session = PipSession()
finder = PackageFinder(
find_links=[],
index_urls=['https://pypi.python.org/simple/'],
allow_all_external=True,
session=session,
format_control=FormatControl(set([':all:']), set([])),
)
click.secho(' -> reading {}'.format(txt_file), fg='cyan')
reqs = parse_requirements(txt_file, finder, session=session)
click.secho(' -> proccessing every specification in {}'.format(txt_file), fg='cyan')
for req in reqs:
spec_name = str(req.__dict__['req']).replace('==', '-')
if spec_name not in results:
click.secho(' -> {} getting info'.format(spec_name), fg='cyan')
link = finder.find_requirement(req, False)
results.update({
spec_name: {
"name": req.name,
"spec_name": spec_name,
"hash_name": link.hash_name,
"hash": link.hash,
"url": link.url_without_fragment
}})
Args:
*args: Command-line options and arguments passed to pip.
Returns:
A set of requirements, index URLs, nested constraint files,
and nested requirements files.
The nested constraint and requirements files are sets of
:class:`RequirementFile` instances.
"""
self.nested_files = self.parse_nested_files()
pip_options, session = build_pip_session(*args)
repository = PyPiRepository(pip_options, session)
requirements = pip.req.parse_requirements(
str(self.filename),
finder=repository.finder,
session=repository.session,
options=pip_options)
requirements = ordered_set.OrderedSet(sorted(
(HashableInstallRequirement.from_ireq(ireq)
for ireq in requirements),
key=lambda ireq: str(ireq)))
index_urls = ordered_set.OrderedSet(repository.finder.index_urls)
nested_cfiles, nested_rfiles = self.parse_nested_files()
nested_requirements = set(itertools.chain(
*(requirements_file.requirements
for requirements_file in nested_rfiles)))
requirements -= nested_requirements
return requirements, index_urls, nested_cfiles, nested_rfiles
)
)
for req in options.editables:
requirement_set.add_requirement(
InstallRequirement.from_editable(
req,
default_vcs=options.default_vcs,
isolated=options.isolated_mode,
wheel_cache=wheel_cache
)
)
found_req_in_file = False
for filename in options.requirements:
for req in parse_requirements(
filename,
finder=finder, options=options, session=session,
wheel_cache=wheel_cache):
found_req_in_file = True
requirement_set.add_requirement(req)
if not (args or options.editables or found_req_in_file):
opts = {'name': name}
if options.find_links:
msg = ('You must give at least one requirement to '
'%(name)s (maybe you meant "pip %(name)s '
'%(links)s"?)' %
dict(opts, links=' '.join(options.find_links)))
else:
msg = ('You must give at least one requirement '
'to %(name)s (see "pip help %(name)s")' % opts)