Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of Updates #35

Merged
merged 10 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:

- uses: actions/checkout@v1

- name: Set up Python 3.7
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: "3.11"

- name: Prepare project for development
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, pypy3]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest]

steps:

- uses: actions/checkout@v1

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
1 change: 1 addition & 0 deletions lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
set -e
set -x
poetry run black --check .
poetry run isort --check .
poetry run flake8 .
poetry run mypy
4 changes: 0 additions & 4 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,5 @@ ignore_missing_imports = false
pretty = true


[mypy-path]
ignore_missing_imports = true

[mypy-pytest]
ignore_missing_imports = true

777 changes: 308 additions & 469 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pycp/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
import typing

from pycp.transfer import TransferManager, TransferError, TransferOptions
from pycp.transfer import TransferError, TransferManager, TransferOptions


def is_pymv() -> bool:
Expand Down Expand Up @@ -136,13 +136,13 @@ def main() -> None:
try:
errors = transfer_manager.do_transfer()
except TransferError as err:
sys.exit(err)
sys.exit(str(err))
except KeyboardInterrupt:
sys.exit("Interrputed by user")

if errors:
print("Error occurred when transferring the following files:")
for (file_name, error) in errors.items():
for file_name, error in errors.items():
print(file_name, error)


Expand Down
23 changes: 11 additions & 12 deletions pycp/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import sys
import time
import typing

import attr
from dataclasses import dataclass


class Progress:
Expand Down Expand Up @@ -47,14 +46,14 @@ def human_readable(size: int) -> str:
bytes

"""
if size < 1024 ** 2:
if size < 1024**2:
hreadable = float(size) / 1024.0
return "%.0fK" % hreadable
elif size < (1024 ** 3):
hreadable = float(size) / (1024 ** 2)
elif size < (1024**3):
hreadable = float(size) / (1024**2)
return "%.1fM" % round(hreadable, 1)
else:
hreadable = float(size) / (1024.0 ** 3)
hreadable = float(size) / (1024.0**3)
return "%.2fG" % round(hreadable, 2)


Expand Down Expand Up @@ -106,7 +105,7 @@ def shorten_string(input_string: str, length: int) -> str:


def describe_transfer(src: str, dest: str) -> typing.Tuple[str, str, str, str]:
""" Returns pfx, src_mid, dest_mid, sfx, the 4 components
"""Returns pfx, src_mid, dest_mid, sfx, the 4 components
required to build the "foo/{bar => baz}/qux" string

"""
Expand Down Expand Up @@ -160,7 +159,7 @@ def describe_transfer(src: str, dest: str) -> typing.Tuple[str, str, str, str]:
class Component(metaclass=abc.ABCMeta):
@abc.abstractmethod
def render(self, props: Props) -> SizedString:
""" Should return a tuple with a length and a string """
"""Should return a tuple with a length and a string"""


class AnsiEscapeSequence(Component):
Expand Down Expand Up @@ -356,17 +355,17 @@ def get_text(self, props: Props) -> str:
return shorten_path(filename, 40)


@attr.s
@dataclass
class FixedTuple:
index: int = attr.ib()
component: Component = attr.ib()
index: int
component: Component


class Line:
def __init__(self, components: typing.List[Component]) -> None:
self.components = components
fixed = list()
for (i, component) in enumerate(components):
for i, component in enumerate(components):
if isinstance(component, FixedWidthComponent):
fixed.append(FixedTuple(i, component))
assert len(fixed) == 1, "Expecting exactly one fixed width component"
Expand Down
22 changes: 7 additions & 15 deletions pycp/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import time
import typing

from pycp.progress import OneFileIndicator, GlobalIndicator, Progress, ProgressIndicator
from pycp.progress import GlobalIndicator, OneFileIndicator, Progress, ProgressIndicator

BUFFER_SIZE = 100 * 1024


class TransferError(Exception):
"""Custom exception: wraps IOError

"""
"""Custom exception: wraps IOError"""

def __init__(self, message: str) -> None:
Exception.__init__(self)
Expand Down Expand Up @@ -115,18 +113,14 @@ def parse(self, sources: typing.List[str], destination: str) -> None:
self._parse_dir(directory, destination)

def _parse_file(self, source: str, destination: str) -> None:
"""Parse a new source file

"""
"""Parse a new source file"""
if os.path.isdir(destination):
basename = os.path.basename(os.path.normpath(source))
destination = os.path.join(destination, basename)
self.add(source, destination)

def _parse_dir(self, source: str, destination: str) -> None:
"""Parse a new source directory

"""
"""Parse a new source directory"""
if os.path.isdir(destination):
basename = os.path.basename(os.path.normpath(source))
destination = os.path.join(destination, basename)
Expand All @@ -138,7 +132,7 @@ def _parse_dir(self, source: str, destination: str) -> None:
self.to_remove.append(source)

def add(self, src: str, dest: str) -> None:
"""Add a new tuple to the transfer list. """
"""Add a new tuple to the transfer list."""
file_size = os.path.getsize(src)
if not os.path.islink(src):
self.size += file_size
Expand All @@ -149,9 +143,7 @@ def add(self, src: str, dest: str) -> None:


class FileTransferManager:
"""This class handles transferring one file to an other

"""
"""This class handles transferring one file to an other"""

def __init__(self, src: str, dest: str, options: TransferOptions) -> None:
self.src = src
Expand Down Expand Up @@ -333,7 +325,7 @@ def on_file_transfer(transferred: int) -> None:
self.progress_indicator.on_progress(progress)
self.last_progress_update = now

for (src, dest, file_size) in self.transfer_info.to_transfer:
for src, dest, file_size in self.transfer_info.to_transfer:
file_start = time.time()
progress.index += 1
progress.src = src
Expand Down
27 changes: 14 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[tool.isort]
profile = "black"

[tool.poetry]
name = "pycp"
version = "8.0.8"
Expand All @@ -14,23 +17,21 @@ classifiers=[
]

[tool.poetry.dependencies]
python = "^3.6"
attrs = "^19.3.0"
python = "^3.8.1"

[tool.poetry.dev-dependencies]
black = { version = "^19.10b0", markers = "implementation_name != 'pypy'" }
path = "^13.2.0"
flake8 = "^3.7.9"
pytest = "^5.4.1"
pytest-mock = "^3.1.0"
pytest-cov = "^2.8.1"
mypy = { version = "^0.770", markers = "implementation_name != 'pypy'" }
[tool.poetry.group.dev.dependencies]
black = "^23"
isort = "^5.13.2"
flake8 = "^6.1"
pytest = "^7.4"
pytest-mock = "^3.12"
pytest-cov = "^4.1"
mypy = "^1.7"

[tool.poetry.scripts]
pycp = "pycp.main:main"
pymv = "pycp.main:main"


[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
6 changes: 4 additions & 2 deletions test/test_progress.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import typing

from conftest import mock_term_size

import pycp.progress
from pycp.progress import (
GlobalIndicator,
OneFileIndicator,
shorten_path,
shorten_string,
OneFileIndicator,
GlobalIndicator,
)


Expand Down
7 changes: 3 additions & 4 deletions test/test_pycp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import time
import typing


from pycp.main import main as pycp_main
import pytest
from conftest import mock_term_size, strip_ansi_colors

import pytest
from pycp.main import main as pycp_main


def test_zero() -> None:
Expand Down Expand Up @@ -233,7 +232,7 @@ def test_copy_readonly(test_dir: str) -> None:


def test_preserve(test_dir: str) -> None:
""" Check that mtimes are preserved"""
"""Check that mtimes are preserved"""
a_file = os.path.join(test_dir, "a_file")
long_ago = time.time() - 10000
os.utime(a_file, (long_ago, long_ago))
Expand Down
5 changes: 2 additions & 3 deletions test/test_pymv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
import os

import sys

from pycp.main import main as pycp_main

Expand All @@ -17,7 +16,7 @@ def test_mv_file_file(test_dir: str) -> None:


def test_mv_dir_dir_1(test_dir: str) -> None:
""""mv a_dir -> b_dir should work when b_dir does not exist"""
""" "mv a_dir -> b_dir should work when b_dir does not exist"""
a_dir = os.path.join(test_dir, "a_dir")
b_dir = os.path.join(test_dir, "b_dir")
sys.argv = ["pymv", a_dir, b_dir]
Expand Down
4 changes: 2 additions & 2 deletions test/test_transfer_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
```
"""

from pycp.progress import TransferText

from conftest import strip_ansi_colors

from pycp.progress import TransferText


def assert_pprint(src: str, dest: str, actual: str) -> None:
transfer_text = TransferText()
Expand Down
Loading