Skip to content

Commit

Permalink
[#690] Vendor randomly nose extension. Remove nose dependency. More r…
Browse files Browse the repository at this point in the history
…uff fixes. (#702)

* Vendor. node randomly

* Manual update for ruff checks.

* Convert to ruff todos.

* Add ruff for print.

* Add own ruff checks.

* Enable return ruff check.
  • Loading branch information
adiroiban authored Oct 28, 2024
1 parent ff42db8 commit 5e5a522
Show file tree
Hide file tree
Showing 27 changed files with 389 additions and 247 deletions.
Empty file removed example/__init__.py
Empty file.
58 changes: 0 additions & 58 deletions example/unix-daemon.py

This file was deleted.

52 changes: 42 additions & 10 deletions pavement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2010-2016 Adi Roiban.
# See LICENSE for details.
# ruff: noqa: T201
"""
Build script for chevah-compat.
"""
Expand Down Expand Up @@ -62,8 +63,8 @@
SETUP['test']['elevated'] = 'elevated'
SETUP['test']['nose_options'] = [
'--with-randomly',
# FIXME:690:
# Add support for extenstions.
# TODO: Add support for extenstions.
# 690
# '--with-timer',
# '--with-run-reporter',
# '--with-memory-usage',
Expand Down Expand Up @@ -214,19 +215,20 @@ def test_ci2(args):
"""
# When running in CI mode, we want to get more reports.
SETUP['test']['nose_options'] += [
# FIXME:690:
# Add support for extensions.
# TODO: Add support for extensions.
# 690
# '--with-run-reporter',
# '--with-timer',
'-v',
]

# Show some info about the current environment.
from chevah_compat.testing.testcase import ChevahTestCase
from coverage.cmdline import main as coverage_main
from OpenSSL import SSL
from OpenSSL import __version__ as pyopenssl_version

from chevah_compat.testing.testcase import ChevahTestCase

print(
f'{ChevahTestCase.os_family} / '
f'os_name:{ChevahTestCase.os_name} / '
Expand Down Expand Up @@ -268,9 +270,7 @@ def test_ci2(args):
else:
args = [args]

exit_code = call_task('test_python', args=args)

return exit_code
return call_task('test_python', args=args)


@task
Expand Down Expand Up @@ -310,16 +310,48 @@ def fix(args):
"""
ruff_bin = os.path.join(pave.path.build, 'bin', 'ruff')
check_result = subprocess.run(
[ruff_bin, 'check', '--fix', '--unsafe-fixes', '--no-cache'],
[ruff_bin, 'check', '--fix', '--unsafe-fixes', '--no-cache'] + args,
stdout=sys.stdout,
stderr=sys.stderr,
)

format_result = subprocess.run(
[ruff_bin, 'format', '--no-cache'],
[ruff_bin, 'format', '--no-cache'] + args,
stdout=sys.stdout,
stderr=sys.stderr,
)

if check_result.returncode != 0 or format_result != 0:
sys.exit(1)


@task
def migrate_fixme():
"""
Migrate the FIX_ME markers to the ruff TO_DO markers.
"""
for root, dirs, files in os.walk('.'):
for name in files:
if not name.endswith('.py'):
continue

have_fixes = False
file_path = os.path.join(root, name)
with open(file_path) as stream:
lines = stream.readlines()
for line_no, line in enumerate(lines):
if '# FIXME:' not in line:
continue

have_fixes = True
padding = line.split('# ')[0]
comment = lines[line_no + 1].split('# ', 1)[-1].strip()
issue = line.split('FIXME:')[1].replace(':', '')
lines[line_no] = f'{padding}# TODO: {comment}\n'
lines[line_no + 1] = f'{padding}# {issue}\n'

if not have_fixes:
continue

with open(file_path, 'w') as stream:
stream.write(''.join(lines))
19 changes: 13 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,21 @@ target-version = "py311"
# ARG flake8-unused-arguments
# B flake8-bugbear
# C90 mccabe
# CPY flake8-copyright
# CPY flake8-copyright - needs preview features
# D pydocstyle
# DTZ flake8-datetimez
# DTZ flake8-datetimez - need to fix datetime usage
# G flake8-logging-format
# INT flake8-gettext
# N pep8-naming
# N pep8-naming - poor support for interfaces
# PL Pylint
# PT flake8-pytest-style
# PTH flake8-use-pathlib
# Q flake8-quotes
# RET flake8-return
# S flake8-bandit
# SIM flake8-simplify
# SLF flake8-self
# T20 flake8-print
# SLF flake8-self - check private member access
# TCH flake8-type-checking
# TD flake8-todos
select = [
"A",
"AIR",
Expand All @@ -81,10 +79,14 @@ select = [
"PERF",
"PGH",
"PIE",
"RET",
"RUF",
"PYI",
"RSE",
"SLOT",
"T10",
"T20",
"TD",
"TID",
"TRY",
"YTT",
Expand All @@ -94,7 +96,12 @@ ignore = [
"BLE001",
"COM812",
"ISC001",
# TODO: Update code to disable ruff rules.
# https://github.com/chevah/compat/issues/701
"RUF005", # List concatenation
"RUF012", # Class mutable attributes
"TRY003",
"TD002", # We don't use authors tag for todos.
]

external = [
Expand Down
8 changes: 8 additions & 0 deletions release-notes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Release notes for chevah.compat
===============================


1.2.0 - 2024-10-26
--------------------

* Include nose_randomly extension. The extension is no longer maintained upstream.
It also removes the dependency on node.


1.1.2 - 2024-10-04
--------------------

Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = chevah-compat
version = 1.1.2
version = 1.2.0
maintainer = Adi Roiban
maintainer_email = [email protected]
license = BSD
Expand Down Expand Up @@ -28,7 +28,7 @@ package_dir = =src
; These are the deps required to develop.
; Try to pin them as much as possible.
dev =
ruff ~= 0.5
ruff ~= 0.7

bunch

Expand All @@ -37,7 +37,6 @@ dev =
service-identity==24.1.0

pynose == 1.5.3
nose-randomly == 1.2.5

coverage ~= 7.5
diff_cover == 6.4.4
Expand All @@ -61,6 +60,7 @@ nose.plugins.0.10 =
memory-usage = chevah_compat.testing.nose_memory_usage:MemoryUsage
test-time = chevah_compat.testing.nose_test_timer:TestTimer
run-reporter = chevah_compat.testing.nose_run_reporter:RunReporter
randomly = chevah_compat.testing.nose_randomly:RandomlyPlugin


[bdist_wheel]
Expand Down
9 changes: 5 additions & 4 deletions src/chevah_compat/administration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: T201
# Copyright (c) 2012 Adi Roiban.
# See LICENSE for details.
"""
Expand Down Expand Up @@ -492,8 +493,7 @@ def _setUserPassword_unix(self, user):
"""
if self.fs.exists(self.shadow_segments):
return self._setUserPassword_shadow(user, self.shadow_segments)
else:
return self._setUserPassword_passwd(user, self.passwd_segments)
return self._setUserPassword_passwd(user, self.passwd_segments)

def _setUserPassword_shadow(self, user, segments):
"""
Expand Down Expand Up @@ -995,8 +995,9 @@ def deleteHomeFolder(self, user):
home_base = os.path.dirname(os.getenv('USERPROFILE'))
profile_folder_path = os.path.join(home_base, user.name)

# FIXME:927:
# We need to look for a way to delete home folders with unicode
# TODO: We need to look for a way to delete home folders with unicode
# 927

# names.
command = f'rmdir /S /Q "{profile_folder_path}"'
result = subprocess.call(command, shell=True)
Expand Down
19 changes: 9 additions & 10 deletions src/chevah_compat/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ def _get_os_name():
family = sys.platform
if family.startswith('linux'):
return 'linux'
elif family.startswith('win'):
if family.startswith('win'):
return 'windows'
elif family.startswith('aix'):
if family.startswith('aix'):
return 'aix'
elif family.startswith('darwin'):
if family.startswith('darwin'):
return 'osx'
elif family.startswith('sunos'):
if family.startswith('sunos'):
return 'solaris'
elif family.startswith('hp-ux11'):
if family.startswith('hp-ux11'):
return 'hpux'
elif family.startswith('openbsd'):
if family.startswith('openbsd'):
return 'openbsd'
elif family.startswith('freebsd'):
if family.startswith('freebsd'):
return 'freebsd'
else:
raise AssertionError(f'OS "{family}" not supported.')
raise AssertionError(f'OS "{family}" not supported.')


def _get_cpu_type():
Expand All @@ -43,7 +42,7 @@ def _get_cpu_type():
if not base:
base = platform.machine()

if base == 'aarch64': # noqa: cover
if base == 'aarch64': # pragma: no cover
return 'arm64'

if base == 'x86_64':
Expand Down
6 changes: 2 additions & 4 deletions src/chevah_compat/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def __init__(self, message=''):
self.message = message

def __repr__(self):
result = f'CompatException {self.message}'
return result
return f'CompatException {self.message}'


class ChangeUserException(CompatException):
Expand All @@ -40,8 +39,7 @@ def __init__(self, event_id, message):
self.message = message

def __repr__(self):
result = f'CompatError {str(self.event_id)} - {self.message}'
return result
return f'CompatError {self.event_id!s} - {self.message}'

def __str__(self):
return self.__repr__()
12 changes: 4 additions & 8 deletions src/chevah_compat/nt_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def create_home_folder(self):
and 'SeRestorePrivilege' in privileges
):
return True
else:
return False
return False

@property
def get_home_folder(self):
Expand Down Expand Up @@ -291,8 +290,7 @@ def _isPrivilegeStateEnabled(self, state):
"""
if state in ['enabled', 'enabled-by-default']:
return True
else:
return False
return False

def _isPrivilegeStateAvailable(self, state):
"""
Expand All @@ -301,8 +299,7 @@ def _isPrivilegeStateAvailable(self, state):
"""
if state in ['present', 'enabled', 'enabled-by-default']:
return True
else:
return False
return False

def _hasPrivilege(self, privilege_name):
"""
Expand All @@ -323,5 +320,4 @@ def symbolic_link(self):
"""
if self._hasPrivilege(win32security.SE_CREATE_SYMBOLIC_LINK_NAME):
return True
else:
return False
return False
Loading

0 comments on commit 5e5a522

Please sign in to comment.