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

Add a check for the resolvability of dependencies version requirements #5

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
713a739
Start revamp, atm only take npf(s) and unwraps them
melis-m Jun 20, 2019
ea2baec
Add log functions (from nbuild + qlog)
melis-m Jun 20, 2019
22be1a1
Remove Kind enum
melis-m Jun 20, 2019
388406f
Add tarball/npf wrap function, no updates of the manifest.toml yet
melis-m Jun 20, 2019
fdb3be8
Remove args.{output,backup}, as they're not used yet
melis-m Jun 24, 2019
8c5ff82
Add function to refresh date of manifest wrap_date
melis-m Jun 24, 2019
4e39c71
Add log to data.tar.gz creation and manifest.toml
melis-m Jun 24, 2019
230cd2f
Add options to args to choose from fix/edit/diff
melis-m Jun 28, 2019
a90ad70
Add .gitignore
melis-m Jun 28, 2019
f2adf6e
Add .gitignore and definition of core.pushd
melis-m Jun 28, 2019
8409633
Add basis for checks
melis-m Jun 28, 2019
0c0740c
Add executable checks on shlibs/binaries
melis-m Jun 28, 2019
9ba0e49
Merge branch 'master' of github.com:raven-os/npf-checker into checks
melis-m Jul 5, 2019
02c7e30
npf-checker now only takes one .npf
melis-m Jul 17, 2019
d9d7e42
Add base class for checks modifying manifest.toml
melis-m Jul 17, 2019
0c4c80f
Fix utils.ask_yne default (when pressing enter directly)
melis-m Jul 17, 2019
3fdc2d5
Add some log.push and use of colored_path in tar creation logs
melis-m Jul 17, 2019
0599448
Reintroduce pkg to check_package, and to checks with manifest.toml
melis-m Jul 17, 2019
b8fe5f7
Add checks on manifest.toml's description
melis-m Jul 17, 2019
d82214b
Remove self.manifest{,path} from CheckWithManifest, now use self.pkg
melis-m Jul 17, 2019
fb7bff4
add correct caps formatting to default option to utils.ask_yne
melis-m Jul 17, 2019
f2f3c47
Add check for resolvability of version reqs of deps
melis-m Jul 21, 2019
9624071
Add log when running DescCheck's run function
melis-m Jul 23, 2019
6444c74
Add spacing in the sentences of utils.ask_yn{,e}
melis-m Jul 23, 2019
f3cad7d
Fix pkg.show_manifest, version is now displayed properly
melis-m Jul 23, 2019
3ea5ee2
Change version_reqs_solv.fix to propose the highest version when pkg …
melis-m Jul 26, 2019
e4480ea
Add rewrite of the pkg manifest after auto fix
melis-m Jul 26, 2019
a87a832
Add /{,s}bin/ and /lib{,32,64}/ and /usr/lib/ to Exec Checks
melis-m Aug 12, 2019
75791b3
Add help section to --action argument
melis-m Aug 12, 2019
58afa1d
Merge branch 'master' of github.com:raven-os/npf-checker into checks
melis-m Sep 3, 2019
46b2a8d
Merge branch 'checks' into version_reqs_resolvability
melis-m Sep 3, 2019
40c448d
Move the run log message to run function instead of ctor
melis-m Sep 3, 2019
6593347
Merge branch 'master' of github.com:raven-os/npf-checker
melis-m Sep 22, 2019
a635d43
Merge branch 'master' into checks
melis-m Sep 22, 2019
8c1d77e
Add a way to load and get a Config.toml file with a list of repositories
melis-m Sep 22, 2019
4ffa22c
Merge branch 'config_file' into version_reqs_resolvability
melis-m Sep 22, 2019
c071d3d
Add a check on Config.toml, every repo must have a url
melis-m Sep 22, 2019
2268951
Merge branch 'config_file' into version_reqs_resolvability
melis-m Sep 22, 2019
cf76102
Change version_reqs_res to use config file's repos
melis-m Sep 22, 2019
bc21fe3
Add an example Config.toml
melis-m Sep 25, 2019
05d51bc
Add an explanation as to how to use and configure Config.toml
melis-m Sep 25, 2019
bf4f90c
Add help section to --config arg
melis-m Sep 25, 2019
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
11 changes: 11 additions & 0 deletions Config.toml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Repository list to be used for the different checks
# The order in which the repositories are tested will be the same as the order here

[repositories.stable]
url = "https://stable.raven-os.org"

[repositories.beta]
url = "https://beta.raven-os.org"

[repositories.unstable]
url = "https://unstable.raven-os.org"
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# NPF Checker

A checker that ensure the validity and conformance of a NPF


## Config.toml
This file is used to provide additional configuration. It is by default `Config.toml`, but can be changed through `--config`, however only [TOML](https://github.com/toml-lang/toml) is supported.

Currently, it is only used to provide the list of repositories through which `npf-checker` will go when running checks which require repositories.

The order in which the repositories are listed in this config file will also be the order in which they will be used in the checks.

An entry needs only a `url` key and its associated value.


##### Example:

```toml
[repositories.thenameofmyrepository]
url = "https://my-repository.com"

```

If we were to take the repository from the package `beta::kernel/linux`, the name of the repository would be `beta`, and the url would be https://raven-os.org

9 changes: 9 additions & 0 deletions core/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ def parse_args():
action='store_true',
help="Try to use more visual tools (only makes sense with --action=edit, which is the default)"
)
_parser.add_argument(
'--config',
default=os.path.join(
os.getcwd(),
os.path.dirname(sys.argv[0]),
'Config.toml',
),
help="The location of the configuration file. Default: Config.toml",
)
_args = _parser.parse_args()


Expand Down
2 changes: 2 additions & 0 deletions core/check.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import core.checks.executable as exe
import core.checks.syntax_check as stx
import core.checks.version_reqs_resolvability as verreqsolv
import core.checks.version_validity as version


def check_package(pkg):
exe.ExecCheck().run()
stx.DescriptionCheck(pkg).run()
verreqsolv.VersionReqsResolvabilityCheck(pkg).run()
version.VersionValidityCheck(pkg).run()
79 changes: 79 additions & 0 deletions core/checks/version_reqs_resolvability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import json
import requests
import semver
import core.log as log
import core.checks.base as base
import core.config
import core.args


class VersionReqsResolvabilityCheck(base.CheckWithManifest):
def __init__(self, pkg):
super().__init__(pkg, list(pkg.manifest['dependencies'].items()))
self.highest_version = ""
self.repo_error = False
self.pkg_error = False
self.version_error = False
self.repos = core.config.get()['repositories']

def run(self):
log.s("Checking the version requirement solvability of dependencies")
super().run()

def validate(self, item):
self.repo_error = False
self.pkg_error = False
self.version_error = False
full_name, version_req = item
log.i(f"Checking {full_name}#{version_req}")
try:
repo_url, category, name = self.split_pkg_name(full_name)
except KeyError:
self.repo_error = True
return False
resp = requests.get(f'{repo_url}/api/p/{category}/{name}')
if resp.ok:
content = json.loads(resp.content)
match = semver.max_satisfying(
content['versions'],
version_req,
)
if match is None:
self.version_error = True
self.highest_version = semver.max_satisfying(
content['versions'],
'*',
)
return False
return True
else:
self.pkg_error = True
return False

def split_pkg_name(self, pkg_name):
repository, rest = pkg_name.split('::')
category, name = rest.split('/')
repo_url = self.repos[repository]['url']
return repo_url, category, name

def show(self, item):
full_name, version_req = item
if self.pkg_error:
log.e(f"Package wasn't found")
elif self.version_error:
log.e(f"No version was found for requirement {version_req}")
elif self.repo_error:
log.e(f"The repository for {item} isn't defined in {core.args.get_args().config}")

def diff(self, item):
if self.pkg_error or self.repo_error:
log.i(f"Dependency would be removed")
elif self.version_error:
log.i(f"The version would be changed to the highest available: '{self.highest_version}'")

def fix(self, item):
if self.pkg_error or self.repo_error:
del self.pkg.manifest['dependencies'][item[0]]
elif self.version_error:
self.pkg.manifest['dependencies'][item[0]] = self.highest_version
self.write_pkg_manifest()
27 changes: 27 additions & 0 deletions core/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys
import toml
import core.args
import core.log as log

global _config


def load():
global _config
_config = toml.load(core.args.get_args().config)
_check_file()


def _check_file():
error = False
for repo_name in _config['repositories']:
repo = _config['repositories'][repo_name]
if 'url' not in repo:
log.e(f"A 'url' field is missing in Config.toml for repository '{repo_name}'")
error = True
if error:
sys.exit(1)


def get():
return _config
4 changes: 4 additions & 0 deletions npf-checker.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#!/usr/bin/env python3

import core.args
import core.config
import core.package
import core.log as log
import core.checks.base as base


def main():
core.args.parse_args()
core.config.load()

args = core.args.get_args()
base.Check.global_state = base.Type.from_string(core.args.get_args().action)
f = args.npf
pkg = core.package.Package(f)

log.s(f"Unwrapping {f}")
pkg.unwrap()
log.s(f"Checking {f}")
Expand Down