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

Change osc.build module to use 'store' object instead of calling core.store_*() functions #1369

Merged
merged 1 commit into from
Jul 27, 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
25 changes: 13 additions & 12 deletions osc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from . import connection
from . import core
from . import oscerr
from .core import get_buildinfo, store_read_project, store_read_package, meta_exists, quote_plus, get_buildconfig, is_package_dir, dgst
from .core import get_buildinfo, meta_exists, quote_plus, get_buildconfig, dgst
from .core import get_binarylist, get_binary_file, run_external, return_external, raw_input
from .fetch import Fetcher, OscFileGrabber, verify_pacs
from .meter import create_text_meter
Expand Down Expand Up @@ -595,12 +595,13 @@
return kiwipath


def calculate_prj_pac(opts, descr):
project = opts.alternative_project or store_read_project('.')
def calculate_prj_pac(store, opts, descr):
project = opts.alternative_project or store.project

Check warning on line 599 in osc/build.py

View check run for this annotation

Codecov / codecov/patch

osc/build.py#L599

Added line #L599 was not covered by tests
if opts.local_package:
package = os.path.splitext(os.path.basename(descr))[0]
else:
package = store_read_package('.')
store.assert_is_package()
package = store.package

Check warning on line 604 in osc/build.py

View check run for this annotation

Codecov / codecov/patch

osc/build.py#L603-L604

Added lines #L603 - L604 were not covered by tests
return project, package


Expand Down Expand Up @@ -639,7 +640,7 @@
return run_external(cmd[0], *cmd[1:])


def main(apiurl, opts, argv):
def main(apiurl, store, opts, argv):

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.

repo = argv[0]
arch = argv[1]
Expand Down Expand Up @@ -768,11 +769,11 @@
prj = opts.alternative_project
pac = '_repository'
else:
prj = store_read_project(os.curdir)
prj = store.project

Check warning on line 772 in osc/build.py

View check run for this annotation

Codecov / codecov/patch

osc/build.py#L772

Added line #L772 was not covered by tests
if opts.local_package:
pac = '_repository'
else:
pac = store_read_package(os.curdir)
pac = store.package

Check warning on line 776 in osc/build.py

View check run for this annotation

Codecov / codecov/patch

osc/build.py#L776

Added line #L776 was not covered by tests
if opts.multibuild_package:
buildargs.append('--buildflavor=%s' % opts.multibuild_package)
pac = pac + ":" + opts.multibuild_package
Expand All @@ -797,7 +798,7 @@
if pacname == '_repository':
if not opts.local_package:
try:
pacname = store_read_package(os.curdir)
pacname = store.package

Check warning on line 801 in osc/build.py

View check run for this annotation

Codecov / codecov/patch

osc/build.py#L801

Added line #L801 was not covered by tests
except oscerr.NoWorkingCopy:
opts.local_package = True
if opts.local_package:
Expand Down Expand Up @@ -834,7 +835,7 @@
bc_file = None
bi_filename = '_buildinfo-%s-%s.xml' % (repo, arch)
bc_filename = '_buildconfig-%s-%s' % (repo, arch)
if is_package_dir('.') and os.access(core.store, os.W_OK):
if store.is_package and os.access(core.store, os.W_OK):

Check warning on line 838 in osc/build.py

View check run for this annotation

Codecov / codecov/patch

osc/build.py#L838

Added line #L838 was not covered by tests
bi_filename = os.path.join(os.getcwd(), core.store, bi_filename)
bc_filename = os.path.join(os.getcwd(), core.store, bc_filename)
elif not os.access('.', os.W_OK):
Expand All @@ -859,7 +860,7 @@
if opts.noinit:
buildargs.append('--noinit')

if not is_package_dir('.'):
if not store.is_package:

Check warning on line 863 in osc/build.py

View check run for this annotation

Codecov / codecov/patch

osc/build.py#L863

Added line #L863 was not covered by tests
opts.noservice = True

# check for source services
Expand Down Expand Up @@ -1481,8 +1482,8 @@
cmd = [change_personality[bi.buildarch]] + cmd

# record our settings for later builds
if is_package_dir(os.curdir):
core.store_write_last_buildroot(os.curdir, repo, arch, vm_type)
if store.is_package:
store.last_buildroot = repo, arch, vm_type

Check warning on line 1486 in osc/build.py

View check run for this annotation

Codecov / codecov/patch

osc/build.py#L1485-L1486

Added lines #L1485 - L1486 were not covered by tests

try:
rc = run_external(cmd[0], *cmd[1:])
Expand Down
34 changes: 13 additions & 21 deletions osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5267,8 +5267,8 @@
server_service_files=opts.server_side_source_service_files,
progress_obj=self.download_progress, size_limit=opts.limit_size,
meta=opts.meta, outdir=opts.output_dir)
if os.isatty(sys.stdout.fileno()):
print_request_list(apiurl, project, package)

Check warning on line 5271 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L5270-L5271

Added lines #L5270 - L5271 were not covered by tests

elif project:
sep = '/' if not opts.output_dir and conf.config['checkout_no_colon'] else conf.config['project_separator']
Expand Down Expand Up @@ -5329,8 +5329,8 @@
server_service_files=opts.server_side_source_service_files,
progress_obj=self.download_progress, size_limit=opts.limit_size,
meta=opts.meta)
if os.isatty(sys.stdout.fileno()):
print_request_list(apiurl, project)

Check warning on line 5333 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L5332-L5333

Added lines #L5332 - L5333 were not covered by tests

else:
self.argparse_error("Incorrect number of arguments.")
Expand Down Expand Up @@ -7199,25 +7199,17 @@
if len(args) > 3:
raise oscerr.WrongArgs('Too many arguments')

project = None
try:
project = store_read_project(Path.cwd())
if project == opts.alternative_project:
opts.alternative_project = None
except oscerr.NoWorkingCopy:
# This may be a project managed entirely via git?
if os.path.isdir(Path.cwd().parent / '.osc') and os.path.isdir(Path.cwd().parent / '.git'):
project = store_read_project(Path.cwd())
opts.alternative_project = project
pass
store = osc_store.Store(Path.cwd())
store.assert_is_package()

Check warning on line 7203 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L7202-L7203

Added lines #L7202 - L7203 were not covered by tests

if len(args) == 0 and is_package_dir(Path.cwd()):
if opts.alternative_project == store.project:
opts.alternative_project = None

Check warning on line 7206 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L7205-L7206

Added lines #L7205 - L7206 were not covered by tests

if len(args) == 0 and store.is_package and store.last_buildroot:

Check warning on line 7208 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L7208

Added line #L7208 was not covered by tests
# build env not specified, just read from last build attempt
lastbuildroot = store_read_last_buildroot(Path.cwd())
if lastbuildroot:
args = [lastbuildroot[0], lastbuildroot[1]]
if not opts.vm_type:
opts.vm_type = lastbuildroot[2]
args = [store.last_buildroot[0], store.last_buildroot[1]]
if not opts.vm_type:
opts.vm_type = store.last_buildroot[2]

Check warning on line 7212 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L7210-L7212

Added lines #L7210 - L7212 were not covered by tests

vm_chroot = opts.vm_type or conf.config['build-type']
if (subcmd in ('shell', 'chroot') or opts.shell or opts.wipe) and not vm_chroot:
Expand All @@ -7226,7 +7218,7 @@
else:
args = self.parse_repoarchdescr(args, opts.noinit or opts.offline, opts.alternative_project, False, opts.vm_type, opts.multibuild_package)
repo, arch, build_descr = args
prj, pac = osc_build.calculate_prj_pac(opts, build_descr)
prj, pac = osc_build.calculate_prj_pac(store, opts, build_descr)

Check warning on line 7221 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L7221

Added line #L7221 was not covered by tests
apihost = urlsplit(self.get_api_url())[1]
build_root = osc_build.calculate_build_root(apihost, prj, pac, repo,
arch)
Expand All @@ -7250,12 +7242,12 @@

if not opts.local_package:
try:
package = store_read_package(Path.cwd())
prj = Project(os.pardir, getPackageList=False, wc_check=False)
if prj.status(package) == 'A':
if prj.status(store.package) == "A":

Check warning on line 7246 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L7246

Added line #L7246 was not covered by tests
# a package with state 'A' most likely does not exist on
# the server - hence, treat it as a local package
opts.local_package = True
print("INFO: Building the package as a local package.", file=sys.stderr)

Check warning on line 7250 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L7250

Added line #L7250 was not covered by tests
except oscerr.NoWorkingCopy:
pass

Expand Down Expand Up @@ -7284,7 +7276,7 @@

print('Building %s for %s/%s' % (args[2], args[0], args[1]))
if not opts.host:
return osc_build.main(self.get_api_url(), opts, args)
return osc_build.main(self.get_api_url(), store, opts, args)

Check warning on line 7279 in osc/commandline.py

View check run for this annotation

Codecov / codecov/patch

osc/commandline.py#L7279

Added line #L7279 was not covered by tests
else:
return self._do_rbuild(subcmd, opts, *args)

Expand Down
Loading