From 8c4683637fcf3645e10d1c26d3b35b9b51422200 Mon Sep 17 00:00:00 2001 From: Simon Kallfass Date: Sat, 28 Sep 2019 10:31:13 +0200 Subject: [PATCH] added new rule to define the python version inside the extra section of a meta.yaml --- README.rst | 14 +++++++++++-- cenv_tool/schemata.py | 5 +++++ cenv_tool/utils.py | 13 ++++++++++++ docs/index.rst | 1 + docs/usage.rst | 2 ++ pyproject.toml | 11 +++++----- setup.py | 28 ++++++++++++------------- tests/testproject/conda-build/meta.yaml | 1 + tests/utils_test.py | 3 ++- 9 files changed, 55 insertions(+), 23 deletions(-) diff --git a/README.rst b/README.rst index 2385a15..12cb862 100644 --- a/README.rst +++ b/README.rst @@ -46,6 +46,7 @@ the only relevant file and to create and update conda-environment from the definition inside this ``meta.yaml``. The name of the conda-environment to create / update is defined in the section ``extra`` and the variable ``env_name`` inside the ``meta.yaml``. +The python version must be defined in ``extra`` inside the key ``python``. The steps run by cenv: @@ -69,12 +70,14 @@ The usage of cenv reduces the conda commands to use to the following: * ``conda remove -n ... --all`` to remove an environment * ``cenv`` to create / update an environment + Documentation ------------- For complete documentation see `readthedocs `_. + Installation ------------ @@ -87,12 +90,14 @@ Install ``cenv`` using pip: Now run ``init_cenv`` to create the relevant config-files and add the autoactivate- and autoupdate-shell-function to your ``.bashrc`` / ``.zshrc``. + autoactivate and autoupdate ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Per default these features are deactivated, even if added to your shell by running ``init_cenv``. + autoactivate-feature ~~~~~~~~~~~~~~~~~~~~ @@ -105,6 +110,7 @@ To activate the autoactivate-features run: autoactivate_toggle + autoupdate-feature ~~~~~~~~~~~~~~~~~~ @@ -118,6 +124,7 @@ For the autoupdate-feature run: autoupdate_toggle + Usage ----- @@ -153,12 +160,14 @@ The required information about the projects conda environment are extracted from the meta.yaml. This meta.yaml should be located inside the project folder at ``./conda-build/meta.yaml``. -The project-configuration is defined in the ``extra`` section of the ``meta.yaml``. +The project-configuration is defined in the ``extra`` section of the +``meta.yaml``. There you can define the name of the projects conda-environment at ``env_name``. +The python version has to be defined here at ``python``, too. Also you can define requirements only needed during development but not to be included into the resulting conda package. -These requirements have to be defined in the ``dev_requirements``\ -section. +These requirements have to be defined in the ``dev_requirements`` -section. All other parts of the ``meta.yaml`` have to be defined as default. @@ -200,6 +209,7 @@ A meta.yaml valid for cenv should look like the following: extra: env_name: example + python: 3.6 dev_requirements: - ipython >=7.2.0 diff --git a/cenv_tool/schemata.py b/cenv_tool/schemata.py index fd55d13..80c8b03 100644 --- a/cenv_tool/schemata.py +++ b/cenv_tool/schemata.py @@ -92,6 +92,11 @@ class SNExtra(Schema): validate=lambda x: ' ' not in x, ) + python = fields.String( + strict=True, + required=True + ) + dev_requirements = fields.List( fields.String( strict=True, diff --git a/cenv_tool/utils.py b/cenv_tool/utils.py index 7106911..d2dd245 100644 --- a/cenv_tool/utils.py +++ b/cenv_tool/utils.py @@ -123,8 +123,21 @@ def extract_dependencies_from_meta_yaml(meta_yaml_content: dict) -> List[str]: """ # extract the dependencies defined the the requirements-run-section dependencies = meta_yaml_content['requirements']['run'] + + # remove the python version definition. The version will be extracted + # from the extra-python section + dependencies = list( + filter( + lambda x: x.split(' ')[0] != 'python', + dependencies + ) + ) + if meta_yaml_content['extra'].get('dev_requirements'): dependencies.extend(meta_yaml_content['extra']['dev_requirements']) + + # append the python version to use in the conda environment + dependencies.append(f'python {meta_yaml_content["extra"]["python"]}') return dependencies diff --git a/docs/index.rst b/docs/index.rst index 468d32c..06049cd 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -27,6 +27,7 @@ definition inside this ``meta.yaml``. The name of the conda-environment to create / update is defined in the section ``extra`` and the variable ``env_name`` inside the ``meta.yaml`` (at ``conda-build/meta.yaml``). +The python version must be defined in ``extra`` inside the key ``python``. The steps run by cenv: diff --git a/docs/usage.rst b/docs/usage.rst index 004ed8f..cea6122 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -49,6 +49,7 @@ The project-configuration is defined in the ``extra`` section of the ``meta.yaml``. There you can define the name of the projects conda-environment at ``extra:env_name``. +The python version has to be defined here at ``extra:python``, too. Also you can define requirements only needed during development but not to be included into the resulting conda package. These requirements have to be defined in the @@ -92,6 +93,7 @@ A meta.yaml valid for cenv should look like the following: extra: env_name: example + python: 3.6 dev_requirements: - ipython >=7 diff --git a/pyproject.toml b/pyproject.toml index 95181cc..04e1e9d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cenv_tool" -version = "1.1.2" +version = "2.0.0" description = "conda environment creation and update from meta.yaml" license = "MIT" authors = ["Simon Kallfass "] @@ -28,13 +28,13 @@ marshmallow = ">=2.19,<3" coverage = ">=4" coverage-badge = ">=1" ipython = ">=7" -pylint = "==2.*,<2.4" +pylint = "<2.4,==2.*" pytest = "==5.*,>=5.0.0" pytest-cov = ">=2" pytest-datafiles = ">=2" yapf = ">=0" sphinx = "==2.*,>=2.0.0" -sphinx-autodoc-typehints = "==1.*,<1.8.0" +sphinx-autodoc-typehints = "<1.8.0,==1.*" sphinx_rtd_theme = ">=0" @@ -44,8 +44,9 @@ init_cenv = "cenv_tool.init_cenv:main" [tool.poetry.extras] -docs = ["sphinx", "sphinx-autodoc-typehints", "sphinx_rtd_theme"] -tests = ["pytest", "pytest-cov", "pytest-datafiles", "coverage-badge", "coverage"] +docs = ["sphinx", "sphinx-autodoc-typehints", "sphinx-rtd-theme"] +tests = ["coverage", "coverage-badge", "pytest", "pytest-cov", "pytest-datafiles"] + [tool.dephell.main] diff --git a/setup.py b/setup.py index f74bf0e..881d713 100644 --- a/setup.py +++ b/setup.py @@ -21,9 +21,9 @@ setup( long_description=readme, name='cenv_tool', - version='1.1.2', + version='2.0.0', description='conda environment creation and update from meta.yaml', - python_requires='==3.*,>=3.7.0', + python_requires='==3.*,>=3.7', project_urls={ 'homepage': 'https://www.cenv.ouroboros.info', 'repository': 'https://github.com/skallfass/cenv_tool' @@ -45,23 +45,21 @@ packages=['cenv_tool'], package_data={'cenv_tool': ['*.sh', '*.yml']}, install_requires=[ - 'attrs==19.*,>=19.0.0', 'jinja2>=2', 'marshmallow<3,>=2.19', + 'attrs==19.*,>=19.0', 'jinja2>=2', 'marshmallow<3,>=2.19', 'pyyaml==5.*,>=5.0.0', 'six>=1.12' ], extras_require={ - 'dev': [ - 'coverage-badge==1.*,>=1.0.0', 'ipython>=7', 'monkeytype>=19', - 'pylint>=2', 'pytest==5.*,>=5.0.0', 'pytest-cov==2.*,>=2.0.0', - 'pytest-datafiles==2.*,>=2.0.0', 'sphinx==2.*,>=2.0.0', - 'sphinx-autodoc-typehints==1.*,>=1.0.0', - 'sphinx-rtd-theme==0.*,>=0.0.0', 'yapf>=0' - ], 'tests': [ - 'pytest==5.*,>=5.0.0', 'pytest-cov==2.*,>=2.0.0', - 'pytest-datafiles==2.*,>=2.0.0' + 'coverage>=4', 'coverage-badge>=1', 'pytest==5.*,>=5.0.0', + 'pytest-cov>=2', 'pytest-datafiles>=2' ], - 'docs': [ - 'sphinx==2.*,>=2.0.0', 'sphinx-autodoc-typehints==1.*,>=1.0.0' - ] + 'dev': [ + 'coverage>=4', 'coverage-badge>=1', 'ipython>=7', + 'pylint<2.4,==2.*', 'pytest==5.*,>=5.0.0', 'pytest-cov>=2', + 'pytest-datafiles>=2', 'sphinx==2.*,>=2.0.0', + 'sphinx-autodoc-typehints<1.8.0,==1.*', 'sphinx-rtd-theme>=0', + 'yapf>=0' + ], + 'docs': ['sphinx==2.*,>=2.0.0', 'sphinx-autodoc-typehints<1.8.0,==1.*'] }, ) diff --git a/tests/testproject/conda-build/meta.yaml b/tests/testproject/conda-build/meta.yaml index b2e2778..f264ea2 100644 --- a/tests/testproject/conda-build/meta.yaml +++ b/tests/testproject/conda-build/meta.yaml @@ -35,5 +35,6 @@ test: extra: env_name: "cenv_testing_project0001" + python: 3.7.3 dev_requirements: - pylint >=2.2.2 diff --git a/tests/utils_test.py b/tests/utils_test.py index d177935..1ab7b48 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -30,6 +30,7 @@ }, 'extra': { 'dev_requirements': ['pylint >=2.2.2'], + 'python': '3.7.3', 'env_name': 'cenv_testing_project0001', }, 'source': { @@ -90,7 +91,7 @@ def test_extract_dependencies_from_meta_yaml( """Test if the read_meta_yaml function works as expected.""" meta_yaml_content = read_meta_yaml(path=meta_yaml_path) dependencies = extract_dependencies_from_meta_yaml(meta_yaml_content) - assert expected_dependencies == dependencies + assert list(sorted(expected_dependencies)) == list(sorted(dependencies))