Skip to content

Commit

Permalink
Implement base functionality (#11)
Browse files Browse the repository at this point in the history
* Add poetry.show_outdated

* Print outdated packages

* Allow filtering packages

* Add git.current_branch

* Add git.is_worktree_clean

* Add git.branch_exists

* Add git.switch

* Add poetry.update

* Generalize git.{is_worktree_clean => is_clean}

* Add git.resolve_branch

* Add git.remove_branch

* Add git.add

* Add git.commit

* Add git.push

* Add git.push with merge request

* Add github.pull_request_exists

* Add github.create_pull_request

* Use str not Path in git.is_clean

* Use str not Path in git.add

* Remove unused import for pathlib.Path

* Implement default behaviour

* Add console.show_package

* Eliminate redundant upstream_branch_exists

* Fix inverted check if package was modified

* Eliminate redundant package_modified

* Fix iteration over None in git.is_clean

* Fix usage of str.format in console.show_package

* Fix usage of git.add

* Add options --push and --no-push

* Add options --merge-request and --no-merge-request

* Add options --pull-request and --no-pull-request

* Add options --install and --no-install

* Fix broken idempotency

* Add option --dry-run

* Remove redundant pass

* Add options --commit and --no-commit

* Add option --remote

* Avoid redundant switch

* Do not assume master in git.switch(create=True)

* Add option --upstream

* Minor cleanup

* Use `poetry-up/` prefix for branches

* Fix `gh pr create` usage

* Ignore S404 (subprocess module)

* Ignore S603 (subprocess call)

* Ignore S607 (Starting a process with a partial executable path)

* Fix BLK100 (Black would make changes)

* Ignore C901 (too complex: 11)

* Fix D101 (Missing docstring in public class)

* Fix D103 (Missing docstring in public function)

* Fix BLK100 (Black would make changes)

* Ignore C901 (too complex: 11) on Python < 3.8

* Fix return type annotation for git.switch

* Drop Python 3.6

subprocess.run has no capture_output and text keyword arguments

* Add pytest-datadir 1.3.1

* Add option --cwd

* Add data files

* Add repository fixture

* Perform test run on a fixture repository

* Add pytest-datadir to Nox session

* Use --cov-config as workaround for pytest-cov with subprocesses

$ nox -rs tests-3.8

tests/test_console.py .                                                                                                                                                    [100%]
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "<path>/.nox/tests-3-8/lib/python3.8/site-packages/_pytest/main.py", line 191, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "<path>/.nox/tests-3-8/lib/python3.8/site-packages/_pytest/main.py", line 247, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "<path>/.nox/tests-3-8/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "<path>/.nox/tests-3-8/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "<path>/.nox/tests-3-8/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File "<path>/.nox/tests-3-8/lib/python3.8/site-packages/pluggy/callers.py", line 203, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "<path>/.nox/tests-3-8/lib/python3.8/site-packages/pytest_cov/plugin.py", line 254, in pytest_runtestloop
INTERNALERROR>     self.cov_controller.finish()
INTERNALERROR>   File "<path>/.nox/tests-3-8/lib/python3.8/site-packages/pytest_cov/engine.py", line 197, in finish
INTERNALERROR>     self.cov.stop()
INTERNALERROR>   File "<path>/.nox/tests-3-8/lib/python3.8/site-packages/coverage/control.py", line 680, in combine
INTERNALERROR>     combine_parallel_data(self._data, aliases=aliases, data_paths=data_paths, strict=strict)
INTERNALERROR>   File "<path>/.nox/tests-3-8/lib/python3.8/site-packages/coverage/data.py", line 117, in combine_parallel_data
INTERNALERROR>     data.update(new_data, aliases=aliases)
INTERNALERROR>   File "<path>/.nox/tests-3-8/lib/python3.8/site-packages/coverage/sqldata.py", line 563, in update
INTERNALERROR>     raise CoverageException("Can't combine line data with arc data")
INTERNALERROR> coverage.misc.CoverageException: Can't combine line data with arc data

$ ls -la

 52K Apr  9 21:48 .coverage
164K Apr  9 21:48 .coverage.<hostname>.25010.488442
 52K Apr  9 21:48 .coverage.<hostname>.25010.767724
 52K Apr  9 21:48 .coverage.<hostname>.25014.058534
 52K Apr  9 21:48 .coverage.<hostname>.25014.368716
 52K Apr  9 21:48 .coverage.<hostname>.25015.158100
 52K Apr  9 21:48 .coverage.<hostname>.25015.687276
 52K Apr  9 21:48 .coverage.<hostname>.25016.098986
 52K Apr  9 21:48 .coverage.<hostname>.25016.941181
 52K Apr  9 21:48 .coverage.<hostname>.25017.098210
 52K Apr  9 21:48 .coverage.<hostname>.25017.556523
164K Apr  9 21:48 .coverage.<hostname>.25021.631968
 52K Apr  9 21:48 .coverage.<hostname>.25021.863210
 52K Apr  9 21:48 .coverage.<hostname>.25023.568437
 52K Apr  9 21:48 .coverage.<hostname>.25023.600773
 52K Apr  9 21:48 .coverage.<hostname>.25024.405837
 52K Apr  9 21:48 .coverage.<hostname>.25024.452642
 52K Apr  9 21:48 .coverage.<hostname>.25025.535531
 52K Apr  9 21:48 .coverage.<hostname>.25025.671654
 52K Apr  9 21:48 .coverage.<hostname>.25026.557432
 52K Apr  9 21:48 .coverage.<hostname>.25026.670483

* Add remote to repository fixture

* Add tests for non-default options, excluding PRs and MRs

* Add test for --pull-request

* Stub poetry.show_outdated

* Modernize poetry.lock in test fixture

* Add poetry.lock.new to test fixture

* Stub poetry.update

* Stub git.push (for --merge-request)

* Add test for --merge-request

* Add test for dirty worktree

* Add working_directory context manager

* Add test for --dry-run

* Test that branch is created

* Add stub for poetry.update which does nothing

* Test that branch is removed on refused upgrades

* Move working_directory context manager to conftest.py

* Change working directory to repository fixture

* Simplify console test using current working directory

* Add test for git.switch without location

* Test git.push with merge request

* Add pretend 1.0.9

* Add pretend to Nox session

* Add tests for github module

* Use marshmallow 3.5.1 in all tests, for consistency

* Add tests for poetry module

* Add missing docstrings for console tests

* Ignore missing imports for _pytest.* types

* Ignore missing imports for pretend types

* Add missing docstrings to conftest.py

* Ignore S404 (subprocess module)

* Ignore S603 (subprocess call) and S607 (partial executable path)

* Fix I100 (import statement order)

* Fix BLK100 (Black would make changes)

* Fix ANN201 (Missing return type annotation for public function)

* Update documentation

* Set Git user.email and user.name for tests

* Fix YAML multiline syntax
  • Loading branch information
cjolowicz committed Apr 10, 2020
1 parent c00ba19 commit 5aec142
Show file tree
Hide file tree
Showing 24 changed files with 794 additions and 56 deletions.
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ max-complexity = 10
application-import-names = poetry_up,tests
import-order-style = google
docstring-convention = google
per-file-ignores = tests/*:S101
per-file-ignores =
tests/*:S101
3 changes: 3 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:
with:
python-version: "3.8"
architecture: x64
- run: |
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
- run: pip install nox==2019.11.9
- run: pip install poetry==1.0.5
- run: nox --sessions tests-3.8 coverage
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:
with:
python-version: "3.8"
architecture: x64
- run: |
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
- run: pip install nox==2019.11.9
- run: pip install poetry==1.0.5
- run: nox
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
python-version: "3.8"
architecture: x64
- run: pip install poetry==1.0.5
- run: >-
- run: |
poetry version patch &&
version=$(poetry version | awk '{print $2}') &&
poetry version $version.dev.$(date +%s)
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8"]
python-version: ["3.7", "3.8"]
name: Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: |
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
- run: pip install nox==2019.11.9
- run: pip install poetry==1.0.5
- run: nox
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Request features on the [Issue Tracker].

## How to set up your development environment

You need Python 3.6+ and the following tools:
You need Python 3.7+ and the following tools:

- [Poetry]
- [Nox]
Expand Down
88 changes: 82 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Poetry Up
==============================
poetry-up
=========

.. toctree::
:hidden:
Expand All @@ -11,13 +11,26 @@ Poetry Up
license
Changelog <https://github.com/cjolowicz/poetry-up/releases>

This package has a command-line interface.
Command-line tool for upgrading Python dependencies using Poetry.

By default, this tool determines outdated dependencies
using ``poetry show --outdated``,
and performs the following actions for every reported package:

1. Switch to a new branch ``poetry-up/<package>-<version>``.
2. Update the dependency with ``poetry update``.
3. Commit the changes to pyproject.toml and poetry.lock.
4. Push to origin (optional).
5. Open a pull request or merge request (optional).

If no packages are specified on the command-line,
all outdated dependencies are upgraded.


Installation
------------

To install Poetry Up,
To install poetry-up,
run this command in your terminal:

.. code-block:: console
Expand All @@ -28,11 +41,74 @@ run this command in your terminal:
Usage
-----

Poetry Up's usage looks like:
poetry-up's usage looks like:

.. code-block:: console
$ poetry-up [OPTIONS]
$ poetry-up [<options>] [<packages>]
.. option:: --install

Install dependency into virtual environment.
This is the default behavior.

.. option:: --no-install

Do not install dependency into virtual environment.

.. option:: --commit

Commit the changes to Git.
This is the default behavior.

.. option:: --no-commit

Do not commit the changes to Git.

.. option:: --push

Push the changes to the remote repository.

.. option:: --no-push

Do not push the changes to the remote repository.
This is the default behavior.

.. option:: --merge-request

Open a merge request.

.. option:: --no-merge-request

Do not open a merge request.
This is the default behavior.

.. option:: --pull-request

Open a pull request.

.. option:: --no-pull-request

Do not open a pull request.
This is the default behavior.

.. option:: --upstream <branch>, -u <branch>

Specify the upstream branch.
By default, branches are created off the master branch.

.. option:: --remote <remote>, -r <remote>

Specify the remote to push to.
By default, branches are pushed to origin.

.. option:: -C <directory>, --cwd <directory>

Change to this directory before performing any actions.

.. option:: -n, --dry-run

Just show what would be done.

.. option:: --version

Expand Down
23 changes: 22 additions & 1 deletion docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,28 @@ Reference


poetry_up.console
--------------------------
-----------------

.. automodule:: poetry_up.console
:members:


poetry_up.git
-------------

.. automodule:: poetry_up.git
:members:


poetry_up.github
----------------

.. automodule:: poetry_up.github
:members:


poetry_up.poetry
----------------

.. automodule:: poetry_up.poetry
:members:
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[mypy]

[mypy-nox.*,pytest]
[mypy-nox.*,pretend,pytest,_pytest.*]
ignore_missing_imports = True
10 changes: 6 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


package = "poetry_up"
python_versions = ["3.8", "3.7", "3.6"]
python_versions = ["3.8", "3.7"]
nox.options.sessions = "lint", "safety", "mypy", "pytype", "tests"
locations = "src", "tests", "noxfile.py", "docs/conf.py"

Expand Down Expand Up @@ -153,7 +153,7 @@ def mypy(session: Session) -> None:
session.run("mypy", *args)


@nox.session(python=["3.7", "3.6"])
@nox.session(python=["3.7"])
def pytype(session: Session) -> None:
"""Type-check using pytype."""
args = session.posargs or ["--disable=import-error", *locations]
Expand All @@ -164,9 +164,11 @@ def pytype(session: Session) -> None:
@nox.session(python=python_versions)
def tests(session: Session) -> None:
"""Run the test suite."""
args = session.posargs or ["--cov"]
args = session.posargs or ["--cov", "--cov-config=pyproject.toml"]
install_package(session)
install(session, "coverage[toml]", "pytest", "pytest-cov")
install(
session, "coverage[toml]", "pretend", "pytest", "pytest-cov", "pytest-datadir"
)
session.run("pytest", *args)


Expand Down
62 changes: 30 additions & 32 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ documentation = "https://poetry-up.readthedocs.io"
Changelog = "https://github.com/cjolowicz/poetry-up/releases"

[tool.poetry.dependencies]
python = "^3.6"
python = "^3.7"
click = "^7.0"
importlib-metadata = {version = "^1.5.0", python = "<3.8"}

Expand All @@ -40,6 +40,8 @@ sphinx-autodoc-typehints = "^1.10.3"
recommonmark = "^0.6.0"
pep8-naming = "^0.9.1"
flake8-rst-docstrings = "^0.0.13"
pytest-datadir = "^1.3.1"
pretend = "^1.0.9"

[tool.poetry.scripts]
poetry-up = "poetry_up.console:main"
Expand Down

0 comments on commit 5aec142

Please sign in to comment.