Skip to content

Commit

Permalink
added and documented remove command
Browse files Browse the repository at this point in the history
  • Loading branch information
darvid committed Dec 22, 2016
1 parent 792e5a8 commit a0da087
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
13 changes: 13 additions & 0 deletions docs/source/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,16 @@ reqwire init
* ``reqwire init --extra-index-url INDEX_URL``

Adds ``extra-index-url`` options to requirement source files.

reqwire remove
~~~~~~~~~~~~~~

* ``reqwire remove [specifier]...``

Removes the provided package name(s) from the main requirement source
file.

* ``reqwire remove -t TAG [specifier]...``

Removes the provided package name(s) from one or more tagged
requirement source files.
5 changes: 3 additions & 2 deletions docs/source/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Release Notes
:backlinks: none


0.1a4
-----
0.1 (12/22/16)
--------------

* Corrected package setup to include `sh <https://github.com/amoffat/sh>`_
as an installation dependency.
Expand All @@ -15,6 +15,7 @@ Release Notes
and environment variables.
* File headers now include modelines for Vim and Sublime Text (via
`STEmacsModelines <https://github.com/kvs/STEmacsModelines>`_).
* Added `reqwire remove` command.

0.1a3 (12/11/16)
----------------
Expand Down
2 changes: 1 addition & 1 deletion requirements/src/docs.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- mode: requirementstxt -*-
# vim: set ft=requirements
# Generated by reqwire on Sun Dec 11 18:33:24 2016
# Generated by reqwire on Thu Dec 22 14:51:30 2016
--index-url https://pypi.python.org/simple
Sphinx==1.5
sphinx-md-theme==0.1a2
Expand Down
59 changes: 57 additions & 2 deletions src/reqwire/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import atomicwrites
import click
import piptools.exceptions
import piptools.utils
import sh

import reqwire
Expand Down Expand Up @@ -167,7 +168,7 @@ def main_build(ctx, # type: click.Context
pip_compile_options, # type: Iterable[str]
):
# type: (...) -> None
"""Builds requirements with pip-compile."""
"""Build requirements with pip-compile."""
if not options['directory'].exists():
console.error('run `{} init\' first', ctx.find_root().info_name)
ctx.abort()
Expand Down Expand Up @@ -219,7 +220,7 @@ def main_init(ctx, # type: click.Context
# type: (...) -> None
"""Initialize reqwire in the current directory."""
if not force and options['directory'].exists():
console.error('requirements directory already exists', fg='red')
console.error('requirements directory already exists')
ctx.abort()
src_dir = reqwire.scaffold.init_source_dir(
options['directory'], exist_ok=force)
Expand All @@ -239,3 +240,57 @@ def main_init(ctx, # type: click.Context
index_url=index_url,
extra_index_urls=extra_index_url)
console.info('created {}', click.format_filename(filename))


@main.command('remove')
@click.option('-t', '--tag',
help=('Tagged requirements files to create. '
'Defaults to docs, main, qa, and test.'),
multiple=True)
@click.argument('specifiers', nargs=-1)
@click.pass_obj
@click.pass_context
def main_remove(ctx,
options,
tag,
specifiers,
):
# type: (...) -> None
"""Remove packages from requirement source files."""
if not options['directory'].exists():
console.error('run `{} init\' first', ctx.find_root().info_name)
ctx.abort()

if not tag:
tag = ('main',)

for tag_name in tag:
filename = reqwire.scaffold.build_filename(
working_directory=options['directory'],
tag_name=tag_name,
extension=options['extension'])
if not filename.exists():
console.warn('"{}" does not exist',
click.format_filename(str(filename)))
continue
req_file = reqwire.helpers.requirements.RequirementFile(
str(filename))
for specifier in specifiers:
hireq = (reqwire.helpers.requirements.HashableInstallRequirement
.from_line(specifier))
for requirement in req_file.requirements:
src_req_name = piptools.utils.name_from_req(requirement)
target_req_name = piptools.utils.name_from_req(hireq)
if src_req_name == target_req_name:
req_file.requirements.remove(requirement)
console.info('removed "{}" from {}',
src_req_name, tag_name)

reqwire.helpers.requirements.write_requirements(
filename=str(filename),
requirements=req_file.requirements,
header=reqwire.scaffold.build_source_header(
index_url=req_file.index_url,
extra_index_urls=req_file.extra_index_urls,
nested_cfiles=req_file.nested_cfiles,
nested_rfiles=req_file.nested_rfiles))
2 changes: 2 additions & 0 deletions src/reqwire/helpers/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def parse_nested_files(self):
defaults.index_url = None
with io.open(str(self.filename), 'r') as f:
for line in f:
if line.startswith('#'):
continue
args_str, options_str = pip.req.req_file.break_args_options(
line)
opts, _ = parser.parse_args(shlex.split(options_str), defaults)
Expand Down

0 comments on commit a0da087

Please sign in to comment.