-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from sarugaku/add-package
WIP: add/remove
- Loading branch information
Showing
17 changed files
with
970 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,63 @@ | ||
# -*- coding=utf-8 -*- | ||
|
||
from .cli import main | ||
"""Debug-purpose command entry point. | ||
Recommended cases to test: | ||
* "oslo.utils==1.4.0" | ||
* "requests" "urllib3<1.21.1" | ||
* "pylint==1.9" "pylint-quotes==0.1.9" | ||
* "aiogremlin" "pyyaml" | ||
* Pipfile from pypa/pipenv#1974 (need to modify a bit) | ||
* Pipfile from pypa/pipenv#2529-410209718 | ||
""" | ||
|
||
from __future__ import absolute_import, print_function, unicode_literals | ||
|
||
import argparse | ||
import os | ||
|
||
from .lockers import BasicLocker | ||
from .projects import Project | ||
from .reporters import print_title | ||
|
||
from .cli.lock import lock | ||
|
||
|
||
def parse_arguments(argv): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"project_root", | ||
type=os.path.abspath, | ||
) | ||
parser.add_argument( | ||
"-o", "--output", | ||
choices=["write", "print", "none"], | ||
default="print", | ||
help="How to output the lockfile", | ||
) | ||
return parser.parse_args(argv) | ||
|
||
|
||
def parsed_main(options): | ||
project = Project(options.project_root) | ||
locker = BasicLocker(project) | ||
success = lock(locker) | ||
if not success: | ||
return | ||
|
||
if options.output == "write": | ||
project._l.write() | ||
print("Lock file written to", project._l.location) | ||
if options.output == "print": | ||
print_title(" LOCK FILE ") | ||
print(project._l.dumps()) | ||
|
||
|
||
def main(argv=None): | ||
options = parse_arguments(argv) | ||
parsed_main(options) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding=utf-8 -*- | ||
|
||
from __future__ import absolute_import, unicode_literals | ||
|
||
import sys | ||
|
||
|
||
class Command(object): | ||
"""A CLI command. | ||
""" | ||
def __init__(self, parse_arguments, parsed_main): | ||
self.parse_arguments = parse_arguments | ||
self.parsed_main = parsed_main | ||
|
||
def __call__(self, argv=None): | ||
options = self.parse_arguments(argv) | ||
result = self.parsed_main(options) | ||
if result is not None: | ||
sys.exit(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# -*- coding=utf-8 -*- | ||
|
||
from __future__ import absolute_import, unicode_literals | ||
|
||
import argparse | ||
import itertools | ||
import os | ||
import sys | ||
|
||
|
||
def parse_arguments(argv): | ||
parser = argparse.ArgumentParser("passa-add") | ||
parser.add_argument( | ||
"requirement_lines", metavar="requirement", | ||
nargs="*", | ||
) | ||
parser.add_argument( | ||
"-e", "--editable", | ||
metavar="requirement", dest="editable_lines", | ||
action="append", default=[], | ||
) | ||
parser.add_argument( | ||
"--dev", | ||
action="store_true", | ||
) | ||
parser.add_argument( | ||
"--project", dest="project_root", | ||
default=os.getcwd(), | ||
type=os.path.abspath, | ||
) | ||
options = parser.parse_args(argv) | ||
if not options.editable_lines and not options.requirement_lines: | ||
parser.error("Must supply either a requirement or --editable") | ||
return options | ||
|
||
|
||
def parsed_main(options): | ||
from passa.lockers import PinReuseLocker | ||
from passa.projects import Project | ||
from .lock import lock | ||
|
||
lines = list(itertools.chain( | ||
options.requirement_lines, | ||
("-e {}".format(e) for e in options.editable_lines), | ||
)) | ||
|
||
project = Project(options.project_root) | ||
for line in lines: | ||
try: | ||
project.add_line_to_pipfile(line, develop=options.dev) | ||
except (TypeError, ValueError) as e: | ||
print("Cannot add {line!r} to Pipfile: {error}".format( | ||
line=line, error=str(e), | ||
), file=sys.stderr) | ||
return 2 | ||
|
||
locker = PinReuseLocker(project) | ||
success = lock(locker) | ||
if not success: | ||
return 1 | ||
|
||
project._p.write() | ||
project._l.write() | ||
print("Written to project at", project.root) | ||
|
||
|
||
if __name__ == "__main__": | ||
from ._base import Command | ||
command = Command(parse_arguments, parsed_main) | ||
command() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- coding=utf-8 -*- | ||
|
||
from __future__ import absolute_import, print_function, unicode_literals | ||
|
||
import argparse | ||
import os | ||
|
||
|
||
def lock(locker): | ||
from passa.reporters import print_requirement | ||
from resolvelib import NoVersionsAvailable, ResolutionImpossible | ||
|
||
success = False | ||
try: | ||
locker.lock() | ||
except NoVersionsAvailable as e: | ||
print("\nCANNOT RESOLVE. NO CANDIDATES FOUND FOR:") | ||
print("{:>40}".format(e.requirement.as_line(include_hashes=False))) | ||
if e.parent: | ||
line = e.parent.as_line(include_hashes=False) | ||
print("{:>41}".format("(from {})".format(line))) | ||
else: | ||
print("{:>41}".format("(user)")) | ||
except ResolutionImpossible as e: | ||
print("\nCANNOT RESOLVE.\nOFFENDING REQUIREMENTS:") | ||
for r in e.requirements: | ||
print_requirement(r) | ||
else: | ||
success = True | ||
return success | ||
|
||
|
||
def parse_arguments(argv): | ||
parser = argparse.ArgumentParser("passa-lock") | ||
parser.add_argument( | ||
"--project", dest="project_root", | ||
default=os.getcwd(), | ||
type=os.path.abspath, | ||
) | ||
options = parser.parse_args(argv) | ||
return options | ||
|
||
|
||
def parsed_main(options): | ||
from passa.lockers import BasicLocker | ||
from passa.projects import Project | ||
|
||
project = Project(options.project_root) | ||
locker = BasicLocker(project) | ||
success = lock(locker) | ||
if not success: | ||
return | ||
|
||
project._l.write() | ||
print("Written to project at", project.root) | ||
|
||
|
||
if __name__ == "__main__": | ||
from ._base import Command | ||
command = Command(parse_arguments, parsed_main) | ||
command() |
Oops, something went wrong.