PK!, pipfile_requirements.py""" pipfile_requirements.py ~~~~~~~~~~~~~~~~~~~~~~~ :author: frostming :license: MIT """ import os import sys import json import argparse import warnings from vistir.compat import Path from requirementslib import Lockfile, Pipfile if sys.version_info[:2] == (2, 7): class FileNotFoundError(OSError): pass def parse_args(): parser = argparse.ArgumentParser() parser.add_argument( "-p", "--project", default=".", type=Path, help="Specify another project root" ) parser.add_argument( "--hashes", default=False, action="store_true", help="whether to include the hashes", ) parser.add_argument( "-d", "--dev", default=False, action="store_true", help="whether to choose the dev-dependencies section", ) parser.add_argument( "file", nargs="?", default=None, help="The file path to covert, support both Pipfile and Pipfile.lock. " "If it isn't given, will try Pipfile.lock first then Pipfile.", ) return parser.parse_args() def _convert_pipfile(pipfile, dev=False): pfile = Pipfile.load(pipfile) requirements = pfile.dev_requirements if dev else pfile.requirements return [req.as_line() for req in requirements] def _convert_pipfile_lock(pipfile, hashes=False, dev=False): lockfile = Lockfile.load(pipfile) return lockfile.as_requirements(hashes, dev=dev) def convert_pipfile_or_lock(project, pipfile=None, hashes=False, dev=False): """Convert given Pipfile/Pipfile.lock to requirements.txt content. :param project: the project path, default to `pwd`. :param pipfile: the path of Pipfile or Pipfile.lock. If it isn't given, will try Pipfile.lock first then Pipfile. :param hashes: whether to include hashes :param dev: whether to choose the dev-dependencies section. :returns: the content of requirements.txt """ if pipfile is None: if project.joinpath("Pipfile.lock").exists(): pipfile = "Pipfile.lock" elif project.joinpath("Pipfile").exists(): pipfile = "Pipfile" if pipfile and not Path(pipfile).is_absolute(): full_path = project.joinpath(pipfile).as_posix() else: full_path = pipfile if pipfile is None or not os.path.exists(full_path): raise FileNotFoundError("No Pipfile* is found.") try: with open(full_path) as f: json.load(f) except Exception: if hashes: warnings.warn( "Pipfile is given, the hashes flag won't take effect.", UserWarning ) return _convert_pipfile(full_path, dev) else: return _convert_pipfile_lock(full_path, hashes, dev) def main(): args = parse_args() lines = convert_pipfile_or_lock(args.project, args.file, args.hashes, args.dev) for line in lines: print(line) if __name__ == "__main__": main() PK!H 349;pipfile_requirements-0.1.0.post0.dist-info/entry_points.txtN+I/N.,()*,HI5*J-̢Լb<..PK!G@@2pipfile_requirements-0.1.0.post0.dist-info/LICENSEMIT License Copyright (c) 2019 Frost Ming Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HWY0pipfile_requirements-0.1.0.post0.dist-info/WHEEL A н#Z;/"b&F]xzwC;dhfCSTֻ0*Ri.4œh6-]{H, JPK!Hʮ& 3pipfile_requirements-0.1.0.post0.dist-info/METADATAVmOFbNT*bµHQJS!ecO=lvwU͇x~}f32^FuJWc;,q F*0w,Xy'qNRf pt:uAZϰƅNnq7##3 {ox8̔ErTU6|1S`lr%VXD–M^ڎ3mEXJUTr]efy6 MRaGR}޷~1{qTHR!<pp饯ǰ &OW_NKNLά,~pJ$j65ִ]X⧵-~^bA1k.=(~*rw H'mɛz=5J*MkB$ }Fu7S`A_x/XʩJ,R[ܒ+e}- Jēz ܣ7(0+·` rC*_E$z/E9F,ʯ+42?^ 2HՁX@P,&k:7B .lPK!Ha541pipfile_requirements-0.1.0.post0.dist-info/RECORDMwC@}~(Xtc4TJCB tH~}ۅ]79ZHY5V|8 U1g=vz૽Sf%>!0 43' "z[y0 te;{J{G&؛MQ4G?ңo5"g▇ؖ Tm8]o!^֠bMtL@}A*J[ɚu8̉BkcwP7L,##U5X /ru';OR0iix%sduWZ< vb6 #ńX怺R /09nPK!, pipfile_requirements.pyPK!H 349; pipfile_requirements-0.1.0.post0.dist-info/entry_points.txtPK!G@@2 pipfile_requirements-0.1.0.post0.dist-info/LICENSEPK!HWY0pipfile_requirements-0.1.0.post0.dist-info/WHEELPK!Hʮ& 3pipfile_requirements-0.1.0.post0.dist-info/METADATAPK!Ha541pipfile_requirements-0.1.0.post0.dist-info/RECORDPK,2