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 tox configuration #4355

Merged
merged 5 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
python-version: 3.8

- name: Install dm-script dependencies
run: pip install packaging==20.3 click~=7.0 pyyaml~=5.1 toml
run: pip install packaging==20.3 click~=7.0 pyyaml~=5.1 tomlkit

- name: Check requirements files
id: check_reqs
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
python-version: 3.8

- name: Install dm-script dependencies
run: pip install packaging==20.3 click~=7.0 pyyaml~=5.1 toml
run: pip install packaging==20.3 click~=7.0 pyyaml~=5.1 tomlkit

- name: Validate
run: python ./utils/dependency_management.py validate-all
Expand Down Expand Up @@ -197,7 +197,7 @@ jobs:
python-version: 3.8

- name: Install dm-script dependencies
run: pip install packaging==20.3 click~=7.0 pyyaml~=5.1 toml
run: pip install packaging==20.3 click~=7.0 pyyaml~=5.1 tomlkit

- name: Check consistency of requirements/ files
id: check_reqs
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*.egg-info
.eggs
.vscode
.tox

# files created by coverage
.cache
Expand Down
44 changes: 43 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
[build-system]
requires = [ "setuptools>=40.8.0,<50", "wheel", "reentry~=1.3", "fastentrypoints~=0.12",]
requires = ["setuptools>=40.8.0,<50", "wheel", "reentry~=1.3", "fastentrypoints~=0.12"]
build-backend = "setuptools.build_meta:__legacy__"

[tool.tox]
# To use tox, see https://tox.readthedocs.io
# Simply pip or conda install tox
# If you use conda, you may also want to install tox-conda
# then run `tox` or `tox -e py37 -- {pytest args}`

# To ensure rebuild of the tox environment,
# either simple delete the .tox folder or use `tox -r`

legacy_tox_ini = """
[tox]
envlist = py37-django

[testenv:py{35,36,37,38}-{django,sqla}]
deps =
py35: -rrequirements/requirements-py-3.5.txt
py36: -rrequirements/requirements-py-3.6.txt
py37: -rrequirements/requirements-py-3.7.txt
py38: -rrequirements/requirements-py-3.8.txt
setenv =
django: AIIDA_TEST_BACKEND = django
sqla: AIIDA_TEST_BACKEND = sqlalchemy
commands = pytest {posargs}

[testenv:py{36,37,38}-docs-{clean,update}]
deps =
py36: -rrequirements/requirements-py-3.6.txt
py37: -rrequirements/requirements-py-3.7.txt
py38: -rrequirements/requirements-py-3.8.txt
setenv =
update: RUN_APIDOC = False
changedir = docs
whitelist_externals = make
commands =
clean: make clean
make debug

[testenv:py{36,37,38}-pre-commit]
extras = all
commands = pre-commit run {posargs}
"""
2 changes: 1 addition & 1 deletion setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"pre-commit~=2.2",
"pylint~=2.5.0",
"pylint-django~=2.0",
"toml~=0.10.0"
"tomlkit~=0.7.0"
],
"tests": [
"aiida-export-migration-tests==0.9.0",
Expand Down
47 changes: 25 additions & 22 deletions utils/dependency_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import click
import yaml
import toml
import tomlkit as toml

ROOT = Path(__file__).resolve().parent.parent # repository root

Expand Down Expand Up @@ -161,37 +161,43 @@ def generate_environment_yml():


@cli.command()
def generate_pyproject_toml():
def update_pyproject_toml():
"""Generate 'pyproject.toml' file."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adjust the doc-string as well to reflect the change in function.


# read the current file
toml_path = ROOT / 'pyproject.toml'
if toml_path.exists():
pyproject = toml.loads(toml_path.read_text(encoding='utf8'))
else:
pyproject = {}

# Read the requirements from 'setup.json'
setup_cfg = _load_setup_cfg()
install_requirements = [Requirement.parse(r) for r in setup_cfg['install_requires']]

for requirement in install_requirements:
if requirement.name == 'reentry':
reentry_requirement = requirement
break
else:
raise DependencySpecificationError("Failed to find reentry requirement in 'setup.json'.")

pyproject = {
'build-system': {
'requires': ['setuptools>=40.8.0,<50', 'wheel',
str(reentry_requirement), 'fastentrypoints~=0.12'],
'build-backend': 'setuptools.build_meta:__legacy__',
}
# update the build-system key
pyproject['build-system'] = {
'requires': ['setuptools>=40.8.0,<50', 'wheel',
str(reentry_requirement), 'fastentrypoints~=0.12'],
'build-backend': 'setuptools.build_meta:__legacy__',
}
with open(ROOT / 'pyproject.toml', 'w') as file:
toml.dump(pyproject, file)

# write the new file
toml_path.write_text(toml.dumps(pyproject), encoding='utf8')


@cli.command()
@click.pass_context
def generate_all(ctx):
"""Generate all dependent requirement files."""
ctx.invoke(generate_environment_yml)
ctx.invoke(generate_pyproject_toml)
ctx.invoke(update_pyproject_toml)


@cli.command('validate-environment-yml', help="Validate 'environment.yml'.")
Expand Down Expand Up @@ -281,18 +287,15 @@ def validate_pyproject_toml():
else:
raise DependencySpecificationError("Failed to find reentry requirement in 'setup.json'.")

try:
with open(ROOT / 'pyproject.toml') as file:
pyproject = toml.load(file)
pyproject_requires = [Requirement.parse(r) for r in pyproject['build-system']['requires']]
pyproject_file = ROOT / 'pyproject.toml'
if not pyproject_file.exists():
raise DependencySpecificationError("The 'pyproject.toml' file is missing!")

if reentry_requirement not in pyproject_requires:
raise DependencySpecificationError(
"Missing requirement '{}' in 'pyproject.toml'.".format(reentry_requirement)
)
pyproject = toml.loads(pyproject_file.read_text(encoding='utf8'))
pyproject_requires = [Requirement.parse(r) for r in pyproject['build-system']['requires']]

except FileNotFoundError:
raise DependencySpecificationError("The 'pyproject.toml' file is missing!")
if reentry_requirement not in pyproject_requires:
raise DependencySpecificationError("Missing requirement '{}' in 'pyproject.toml'.".format(reentry_requirement))

click.secho('Pyproject.toml dependency specification is consistent.', fg='green')

Expand Down