1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-02-04 02:26:16 +01:00

Merge pull request #1117 from dmach/setup.py-to-setup.cfg

Move python package metadata from setup.py to setup.cfg
This commit is contained in:
Daniel Mach 2022-08-24 14:28:32 +02:00 committed by GitHub
commit 8ca816755a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 179 additions and 132 deletions

View File

@ -1,4 +1,4 @@
name: 'rpmbuild test'
name: 'build and installation tests'
on:
push:
@ -19,7 +19,7 @@ on:
- 'doc/**'
jobs:
test:
rpmbuild:
name: 'rpmbuild test'
runs-on: 'ubuntu-latest'
strategy:
@ -84,3 +84,22 @@ jobs:
git fetch upstream --tags --force
./contrib/build_rpm.py --srpm --rpm
pip:
name: 'pip install test'
runs-on: 'ubuntu-latest'
strategy:
fail-fast: false
steps:
- name: 'Install packages'
run: |
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y --no-install-recommends install git python3-pip python3-rpm
- uses: actions/checkout@v3
- name: 'Install osc from pip'
run: |
pip3 install .

View File

@ -1,4 +1,4 @@
include NEWS
include README
include README.md
include AUTHORS
include COPYING

View File

@ -1,3 +1,19 @@
__all__ = ['babysitter', 'core', 'commandline', 'oscerr', 'build', 'fetch', 'meter', 'grabber']
__all__ = [
'babysitter',
'build',
'connection',
'commandline',
'core',
'fetch',
'grabber',
'meter',
'oscerr',
'oscssl',
]
from .util import git_version
__version__ = git_version.get_version('1.0.0~b1')
# vim: sw=4 et

View File

@ -4249,13 +4249,10 @@ Please submit there instead, or use --nodevelproject to force direct submission.
def _prdiff_output_diff(self, opts, rdiff):
if opts.diffstat:
print()
p = subprocess.Popen("diffstat",
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
close_fds=True)
p.stdin.write(rdiff)
p.stdin.close()
print("".join(decode_it(x) for x in p.stdout.readlines()))
with subprocess.Popen("diffstat", stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True) as p:
p.stdin.write(rdiff)
p.stdin.close()
print("".join(decode_it(x) for x in p.stdout.readlines()))
elif opts.unified:
print()
if isinstance(rdiff, str):

View File

@ -16,6 +16,7 @@ import urllib3.poolmanager
import urllib3.response
import urllib3.util
from . import __version__
from . import conf
from . import oscerr
from . import oscssl
@ -98,7 +99,7 @@ def get_proxy_manager(env):
proxy_headers = urllib3.make_headers(
proxy_basic_auth=proxy_purl.auth,
user_agent=f"osc/{core.__version__}",
user_agent=f"osc/{__version__}",
)
manager = urllib3.ProxyManager(proxy_url, proxy_headers=proxy_headers)
@ -123,6 +124,24 @@ HTTP_PROXY_MANAGER = get_proxy_manager("HTTP_PROXY")
HTTPS_PROXY_MANAGER = get_proxy_manager("HTTPS_PROXY")
def http_request_wrap_file(func):
"""
Turn file path into a file object and close it automatically
by using a context manager.
"""
def new_func(method, url, headers=None, data=None, file=None):
if file:
with open(file, "rb") as f:
return func(method, url, headers, data, file=f)
else:
return func(method, url, headers, data, file)
new_func.__name__ = func.__name__
new_func.__doc__ = func.__doc__
return new_func
@http_request_wrap_file
def http_request(method, url, headers=None, data=None, file=None):
"""
Send a HTTP request to a server.
@ -153,7 +172,7 @@ def http_request(method, url, headers=None, data=None, file=None):
headers = urllib3.response.HTTPHeaderDict(headers or {})
# identify osc
headers.update(urllib3.make_headers(user_agent=f"osc/{core.__version__}"))
headers.update(urllib3.make_headers(user_agent=f"osc/{__version__}"))
if data and file:
raise RuntimeError('Specify either `data` or `file`')
@ -162,8 +181,8 @@ def http_request(method, url, headers=None, data=None, file=None):
data = data.encode("utf-8")
content_length = len(data)
elif file:
content_length = os.path.getsize(file)
data = open(file, "rb")
content_length = os.fstat(file.fileno()).st_size
data = file
else:
content_length = 0

View File

@ -4,10 +4,6 @@
# either version 2, or version 3 (at your option).
from .util import git_version
__version__ = git_version.get_version('1.0.0~b1')
# __store_version__ is to be incremented when the format of the working copy
# "store" changes in an incompatible way. Please add any needed migration
# functionality to check_store_version().
@ -37,6 +33,7 @@ try:
except ImportError:
distro = None
from . import __version__
from . import conf
from . import oscerr
from .connection import http_request, http_GET, http_POST, http_PUT, http_DELETE
@ -2023,7 +2020,8 @@ class Package:
if not add:
tmpl = b'-%s'
ltmpl = b'@@ -1,%d +0,0 @@\n'
lines = [tmpl % i for i in open(fname, 'rb').readlines()]
with open(fname, 'rb') as f:
lines = [tmpl % i for i in f.readlines()]
if len(lines):
diff.append(ltmpl % len(lines))
if not lines[-1].endswith(b'\n'):
@ -3277,7 +3275,8 @@ def store_readlist(dir, name):
r = []
if os.path.exists(os.path.join(dir, store, name)):
r = [line.rstrip('\n') for line in open(os.path.join(dir, store, name))]
with open(os.path.join(dir, store, name)) as f:
r = [line.rstrip('\n') for line in f]
return r
def read_tobeadded(dir):
@ -3293,7 +3292,8 @@ def read_sizelimit(dir):
fname = os.path.join(dir, store, '_size_limit')
if os.path.exists(fname):
r = open(fname).readline().strip()
with open(fname) as f:
r = f.readline().strip()
if r is None or not r.isdigit():
return None
@ -3351,7 +3351,8 @@ def check_store_version(dir):
versionfile = os.path.join(dir, store, '_osclib_version')
try:
v = open(versionfile).read().strip()
with open(versionfile) as f:
v = f.read().strip()
except:
v = ''
@ -4741,7 +4742,8 @@ def binary(s):
def binary_file(fn):
"""read 4096 bytes from a file named fn, and call binary() on the data"""
return binary(open(fn, 'rb').read(4096))
with open(fn, 'rb') as f:
return binary(f.read(4096))
def get_source_file_diff(dir, filename, rev, oldfilename = None, olddir = None, origfilename = None):
@ -6507,7 +6509,8 @@ def store_read_project(dir):
global store
try:
p = open(os.path.join(dir, store, '_project')).readlines()[0].strip()
with open(os.path.join(dir, store, '_project')) as f:
p = f.readline().strip()
except OSError:
msg = 'Error: \'%s\' is not an osc project dir or working copy' % os.path.abspath(dir)
if os.path.exists(os.path.join(dir, '.svn')):
@ -6520,7 +6523,8 @@ def store_read_package(dir):
global store
try:
p = open(os.path.join(dir, store, '_package')).readlines()[0].strip()
with open(os.path.join(dir, store, '_package')) as f:
p = f.readline().strip()
except OSError:
msg = 'Error: \'%s\' is not an osc package working copy' % os.path.abspath(dir)
if os.path.exists(os.path.join(dir, '.svn')):
@ -6548,7 +6552,8 @@ def store_read_apiurl(dir, defaulturl=True):
fname = os.path.join(dir, store, '_apiurl')
try:
url = open(fname).readlines()[0].strip()
with open(fname) as f:
url = f.readlines()[0].strip()
# this is needed to get a proper apiurl
# (former osc versions may stored an apiurl with a trailing slash etc.)
apiurl = conf.urljoin(*conf.parse_apisrv_url(None, url))
@ -6619,8 +6624,8 @@ def store_read_file(dir, file):
global store
try:
content = open(os.path.join(dir, store, file)).read()
return content
with open(os.path.join(dir, store, file)) as f:
return f.read()
except:
return None

View File

@ -1,3 +1,49 @@
[metadata]
name = osc
version = attr: osc.__version__
description = openSUSE commander
long_description = Command-line client for the Open Build Service
keywords = openSUSE, SUSE, RPM, build, buildservice, command-line
license = GPLv2+
url = http://en.opensuse.org/openSUSE:OSC
download_url = https://github.com/openSUSE/osc
author = openSUSE project
author_email = opensuse-buildservice@opensuse.org
classifiers =
Development Status :: 5 - Production/Stable
Environment :: Console
Intended Audience :: Developers
Intended Audience :: Information Technology
Intended Audience :: System Administrators
License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)
Operating System :: MacOS :: MacOS X
Operating System :: POSIX :: BSD :: FreeBSD
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Topic :: Software Development :: Build Tools
Topic :: System :: Archiving :: Packaging
[options]
packages =
osc
osc.util
install_requires =
cryptography
# rpm is not available on pip, install a matching package manually prior installing osc
rpm
urllib3
[options.entry_points]
console_scripts =
osc = osc.babysitter:main
[flake8]
exclude = .git,__pycache__
max-line-length = 120

View File

@ -3,78 +3,6 @@
import setuptools
import osc.core
with open("README.md") as fh:
lines = fh.readlines()
while lines:
line = lines[0].strip()
if not line or line.startswith("["):
# skip leading empty lines
# skip leading lines with links to badges
lines.pop(0)
continue
break
long_description = "".join(lines)
cmdclass = {
}
# keep build deps minimal and be tolerant to missing sphinx
# that is not needed during package build
try:
import sphinx.setup_command
cmdclass['build_doc'] = sphinx.setup_command.BuildDoc
except ImportError:
pass
setuptools.setup(
name='osc',
version=osc.core.__version__,
description='openSUSE commander',
long_description=long_description,
long_description_content_type="text/plain",
author='openSUSE project',
author_email='opensuse-buildservice@opensuse.org',
license='GPLv2+',
platforms=['Linux', 'MacOS X', 'FreeBSD'],
keywords=['openSUSE', 'SUSE', 'RPM', 'build', 'buildservice'],
url='http://en.opensuse.org/openSUSE:OSC',
download_url='https://github.com/openSUSE/osc',
packages=['osc', 'osc.util'],
install_requires=['cryptography', 'urllib3'],
extras_require={
'RPM signature verification': ['rpm'],
},
entry_points={
'console_scripts': [
'osc=osc.babysitter:main'
],
},
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: BSD :: FreeBSD",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Software Development :: Build Tools",
"Topic :: System :: Archiving :: Packaging",
],
# Override certain command classes with our own ones
cmdclass=cmdclass,
test_suite="tests",
)
if __name__ == "__main__":
setuptools.setup()

View File

@ -11,6 +11,7 @@ from xml.etree import ElementTree as ET
import urllib3.response
import osc.conf
import osc.core
@ -201,7 +202,7 @@ class OscTestCase(unittest.TestCase):
EXPECTED_REQUESTS = []
os.chdir(os.path.dirname(__file__))
oscrc = os.path.join(self._get_fixtures_dir(), 'oscrc')
osc.core.conf.get_config(override_conffile=oscrc,
osc.conf.get_config(override_conffile=oscrc,
override_no_keyring=True, override_no_gnome_keyring=True)
os.environ['OSC_CONFIG'] = oscrc
@ -222,13 +223,17 @@ class OscTestCase(unittest.TestCase):
def _get_fixtures_dir(self):
raise NotImplementedError('subclasses should implement this method')
def _get_fixture(self, filename):
path = os.path.join(self._get_fixtures_dir(), filename)
with open(path) as f:
return f.read()
def _change_to_pkg(self, name):
os.chdir(os.path.join(self.tmpdir, 'osctest', name))
def _check_list(self, fname, exp):
fname = os.path.join('.osc', fname)
self.assertTrue(os.path.exists(fname))
self.assertEqual(open(fname).read(), exp)
self.assertFileContentEqual(fname, exp)
def _check_addlist(self, exp):
self._check_list('_to_be_added', exp)
@ -256,6 +261,22 @@ class OscTestCase(unittest.TestCase):
self.assertTrue(os.path.exists(os.path.join('.osc', i.get('name'))))
self.assertEqual(osc.core.dgst(os.path.join('.osc', i.get('name'))), i.get('md5'))
def assertFilesEqual(self, first, second):
self.assertTrue(os.path.exists(first))
self.assertTrue(os.path.exists(second))
with open(first) as f1, open(second) as f2:
self.assertEqual(f1.read(), f2.read())
def assertFileContentEqual(self, file_path, expected_content):
self.assertTrue(os.path.exists(file_path))
with open(file_path) as f:
self.assertEqual(f.read(), expected_content)
def assertFileContentNotEqual(self, file_path, expected_content):
self.assertTrue(os.path.exists(file_path))
with open(file_path) as f:
self.assertNotEqual(f.read(), expected_content)
def assertXMLEqual(self, act, exp):
if xml_equal(act, exp):
return

View File

@ -66,12 +66,12 @@ class TestAddFiles(OscTestCase):
"""replace a deleted file ('foo')"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
open('foo', 'w').write('replaced file\n')
with open('foo', 'w') as f:
f.write('replaced file\n')
p.addfile('foo')
exp = 'A foo\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
self.assertNotEqual(open(os.path.join('.osc', 'foo')).read(), 'replaced file\n')
self.assertFileContentNotEqual(os.path.join('.osc', 'foo'), 'replaced file\n')
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
self._check_status(p, 'foo', 'R')
self._check_addlist('foo\n')

View File

@ -40,7 +40,7 @@ class TestCommit(OscTestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testSimple_cfilesremote')
self.assertTrue(os.path.exists('nochange'))
self.assertEqual(open('nochange').read(), open(os.path.join('.osc', 'nochange')).read())
self.assertFilesEqual('nochange', os.path.join('.osc', 'nochange'))
self._check_status(p, 'nochange', ' ')
self._check_status(p, 'foo', ' ')
self._check_status(p, 'merge', ' ')
@ -64,7 +64,7 @@ class TestCommit(OscTestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testAddfile_cfilesremote')
self.assertTrue(os.path.exists('add'))
self.assertEqual(open('add').read(), open(os.path.join('.osc', 'add')).read())
self.assertFilesEqual('add', os.path.join('.osc', 'add'))
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
self._check_status(p, 'add', ' ')
self._check_status(p, 'foo', ' ')
@ -241,7 +241,7 @@ class TestCommit(OscTestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testAddfile_cfilesremote')
self.assertTrue(os.path.exists('add'))
self.assertEqual(open('add').read(), open(os.path.join('.osc', 'add')).read())
self.assertFilesEqual('add', os.path.join('.osc', 'add'))
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
self._check_status(p, 'add', ' ')
self._check_status(p, 'foo', ' ')
@ -341,7 +341,7 @@ class TestCommit(OscTestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testSimple_cfilesremote')
self.assertTrue(os.path.exists('nochange'))
self.assertEqual(open('nochange').read(), open(os.path.join('.osc', 'nochange')).read())
self.assertFilesEqual('nochange', os.path.join('.osc', 'nochange'))
self._check_status(p, 'nochange', ' ')
self._check_status(p, 'foo', ' ')
self._check_status(p, 'merge', ' ')

View File

@ -84,7 +84,8 @@ class TestInitPackage(OscTestCase):
"""initialize a package dir (dir is a file)"""
pac_dir = os.path.join(self.tmpdir, 'testpkg')
os.mkdir(pac_dir)
open(os.path.join(pac_dir, osc.core.store), 'w').write('foo\n')
with open(os.path.join(pac_dir, osc.core.store), 'w') as f:
f.write('foo\n')
self.assertRaises(osc.oscerr.OscIOError, osc.core.Package.init_package, 'http://localhost', 'osctest', 'testpkg', pac_dir)
if __name__ == '__main__':

View File

@ -192,7 +192,7 @@ class TestRepairWC(OscTestCase):
p = osc.core.Package('.', wc_check=False)
p.wc_repair('http://localhost')
self.assertTrue(os.path.exists(os.path.join('.osc', '_apiurl')))
self.assertEqual(open(os.path.join('.osc', '_apiurl')).read(), 'http://localhost\n')
self.assertFileContentEqual(os.path.join('.osc', '_apiurl'), 'http://localhost\n')
self.assertEqual(p.apiurl, 'http://localhost')
def test_invalidapiurl(self):
@ -201,7 +201,7 @@ class TestRepairWC(OscTestCase):
p = osc.core.Package('.', wc_check=False)
p.wc_repair('http://localhost')
self.assertTrue(os.path.exists(os.path.join('.osc', '_apiurl')))
self.assertEqual(open(os.path.join('.osc', '_apiurl')).read(), 'http://localhost\n')
self.assertFileContentEqual(os.path.join('.osc', '_apiurl'), 'http://localhost\n')
self.assertEqual(p.apiurl, 'http://localhost')
def test_noapiurlNotExistingApiurl(self):
@ -223,7 +223,7 @@ class TestRepairWC(OscTestCase):
prj.wc_repair('http://localhost')
self.assertTrue(os.path.exists(os.path.join(storedir, '_apiurl')))
self.assertTrue(os.path.exists(os.path.join(storedir, '_apiurl')))
self.assertEqual(open(os.path.join(storedir, '_apiurl')).read(), 'http://localhost\n')
self.assertFileContentEqual(os.path.join(storedir, '_apiurl'), 'http://localhost\n')
if __name__ == '__main__':

View File

@ -322,7 +322,7 @@ class TestRequest(OscTestCase):
def test_read_request1(self):
"""read in a request"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_read_request1.xml')).read().strip()
xml = self._get_fixture('test_read_request1.xml')
r = osc.core.Request()
r.read(ET.fromstring(xml))
self.assertEqual(r.reqid, '42')
@ -353,7 +353,7 @@ class TestRequest(OscTestCase):
def test_read_request2(self):
"""read in a request (with reviews)"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_read_request2.xml')).read().strip()
xml = self._get_fixture('test_read_request2.xml')
r = osc.core.Request()
r.read(ET.fromstring(xml))
self.assertEqual(r.reqid, '123')
@ -427,7 +427,7 @@ class TestRequest(OscTestCase):
def test_request_list_view1(self):
"""test the list_view method"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view1.xml')).read().strip()
xml = self._get_fixture('test_request_list_view1.xml')
exp = """\
62 State:new By:Admin When:2010-12-29T14:57:25
set_bugowner: buguser foo
@ -444,7 +444,7 @@ class TestRequest(OscTestCase):
def test_request_list_view2(self):
"""test the list_view method (with history elements and description)"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view2.xml')).read().strip()
xml = self._get_fixture('test_request_list_view2.xml')
r = osc.core.Request()
r.read(ET.fromstring(xml))
exp = """\
@ -458,7 +458,7 @@ class TestRequest(OscTestCase):
def test_request_str1(self):
"""test the __str__ method"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_str1.xml')).read().strip()
xml = self._get_fixture('test_request_str1.xml')
r = osc.core.Request()
r = osc.core.Request()
r.read(ET.fromstring(xml))
@ -555,7 +555,7 @@ Comment: <no comment>"""
def test_get_actions(self):
"""test get_actions method"""
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view1.xml')).read().strip()
xml = self._get_fixture('test_request_list_view1.xml')
r = osc.core.Request()
r.read(ET.fromstring(xml))
sr_actions = r.get_actions('submit')

View File

@ -28,9 +28,6 @@ class TestResults(OscTestCase):
cli.main(argv=argv)
return sys.stdout.getvalue()
def _get_fixture(self, filename):
return open(os.path.join(self._get_fixtures_dir(), filename)).read()
@GET('http://localhost/build/testproject/_result', file='result.xml')
def testPrjresults(self):
out = self._run_osc('prjresults', '--xml', 'testproject')

View File

@ -93,7 +93,7 @@ class TestRevertFiles(OscTestCase):
storefile = os.path.join('.osc', fname)
self.assertTrue(os.path.exists(fname))
self.assertTrue(os.path.exists(storefile))
self.assertEqual(open(fname).read(), open(storefile).read())
self.assertFilesEqual(fname, storefile)
if __name__ == '__main__':
import unittest

View File

@ -115,7 +115,7 @@ class TestUpdate(OscTestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_deletelist('foo\n')
self._check_conflictlist('merge\n')
self.assertEqual(open('foo').read(), open(os.path.join('.osc', 'foo')).read())
self.assertFilesEqual('foo', os.path.join('.osc', 'foo'))
self._check_digests('testUpdateLocalDeletions_files')
@GET('http://localhost/source/osctest/restore?rev=latest', file='testUpdateRestore_files')
@ -201,11 +201,9 @@ class TestUpdate(OscTestCase):
exp = 'A bigfile\nD _service:exists\nA _service:bar\nA _service:foo\nAt revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertFalse(os.path.exists(os.path.join('.osc', '_service:bar')))
self.assertTrue(os.path.exists('_service:bar'))
self.assertEqual(open('_service:bar').read(), 'another service\n')
self.assertFileContentEqual('_service:bar', 'another service\n')
self.assertFalse(os.path.exists(os.path.join('.osc', '_service:foo')))
self.assertTrue(os.path.exists('_service:foo'))
self.assertEqual(open('_service:foo').read(), 'small\n')
self.assertFileContentEqual('_service:foo', 'small\n')
self.assertTrue(os.path.exists('_service:exists'))
self._check_digests('testUpdateServiceFilesAddDelete_files', '_service:foo', '_service:bar')