Skip to content

Commit

Permalink
fix(build): change resolve_requires to be independent of pip
Browse files Browse the repository at this point in the history
Fixes: #451
  • Loading branch information
piraz committed Apr 22, 2024
1 parent 9e95493 commit 0013a0b
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions setup.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# Copyright 2015-2023 Flavio Garcia
# Copyright 2015-2024 Flavio Garcia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,35 +16,30 @@

import firenado
from setuptools import setup, find_packages
import sys
import os

try:
# for pip >= 10
from pip._internal.req import parse_requirements
except ImportError:
# for pip <= 9.0.3
print("error: Upgrade to a pip version newer than 10. Run \"pip install "
"--upgrade pip\".")
sys.exit(1)
with open("README.md", "r") as fh:
long_description = fh.read()


# Solution from http://bit.ly/29Yl8VN
def resolve_requires(requirements_file):
try:
requirements = parse_requirements("./%s" % requirements_file,
session=False)
return [str(ir.req) for ir in requirements]
except AttributeError:
# for pip >= 20.1.x
# Need to run again as the first run was ruined by the exception
requirements = parse_requirements("./%s" % requirements_file,
session=False)
# pr stands for parsed_requirement
return [str(pr.requirement) for pr in requirements]

requires = []
if os.path.isfile(f"./{requirements_file}"):
file_dir = os.path.dirname(f"./{requirements_file}")
with open(f"./{requirements_file}") as f:
for raw_line in f.readlines():
line = raw_line.strip().replace("\n", "")
if len(line) > 0:
if line.startswith("-r "):
partial_file = os.path.join(file_dir, line.replace(
"-r ", ""))
partial_requires = resolve_requires(partial_file)
requires = requires + partial_requires
continue
requires.append(line)
return requires

with open("README.md", "r") as fh:
long_description = fh.read()

setup(
name="Firenado",
Expand Down

0 comments on commit 0013a0b

Please sign in to comment.