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 processing selectors and tests. #75

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9d600cb
Add processing selectors and tests.
allanleal Feb 13, 2019
8c6ecee
Fix mocking of python functions.
allanleal Feb 13, 2019
10512bd
Add back deleted key-value pairs by mistake.
allanleal Feb 13, 2019
4db7701
[skip ci] Delete a blank line.
allanleal Feb 13, 2019
e5fe7c5
Remove py py2k, py3k, and use mock with lambda.
allanleal Feb 13, 2019
751a31b
Add forgotten lambda functions!
allanleal Feb 13, 2019
bf1a366
Remove unused variable pyversion.
allanleal Feb 13, 2019
e5999d4
Fix lambda - need return of a tuple
allanleal Feb 13, 2019
ebb387f
Update usage docs.
allanleal Feb 13, 2019
20e1f8d
Further improvements.
allanleal Feb 13, 2019
87b3c0a
Remove command role.
allanleal Feb 13, 2019
ba1e330
Missing ``
allanleal Feb 13, 2019
9bdf187
Using table as in conda-build docs
allanleal Feb 13, 2019
14c495a
Add sphinx_rtd_theme dependency
allanleal Feb 13, 2019
9376f81
Set sphinx_rdt_theme as the theme for docs.
allanleal Feb 13, 2019
675d536
Add an overview of conda-devenv before contents section.
allanleal Feb 13, 2019
dad5aac
Adapt the existing example and add table with new variables.
allanleal Feb 13, 2019
8a29ad7
Revert back changes in theme made for local testing.
allanleal Feb 13, 2019
065e585
Remove some variables related to arm platforms.
allanleal Feb 13, 2019
135f528
Remove some variables related to arm platforms.
allanleal Feb 13, 2019
6d3fea2
Merge branch 'add-conda-build-preprocessing-selectors-support' of git…
allanleal Feb 13, 2019
d82c101
Remove non implemented tests.
allanleal Feb 14, 2019
3304d4a
Revert sphinx theme to sphinx
allanleal Feb 14, 2019
e393996
Fix pygments_style and html_theme back to original
allanleal Feb 14, 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
17 changes: 17 additions & 0 deletions conda_devenv/devenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,29 @@ def render_jinja(contents, filename, is_included):
import sys
import platform

iswin = sys.platform.startswith('win')
islinux = sys.platform.startswith('linux')
isosx = sys.platform.startswith('darwin')

is32bit = '32bit' == platform.architecture()[0]
is64bit = not is32bit

jinja_dict = {
"is_included": is_included,
"os": os,
"platform": platform,
"root": os.path.dirname(os.path.abspath(filename)),
"sys": sys,
"x86": 'x86' == platform.machine(),
"x86_64": 'x86_64' == platform.machine(),
"linux": islinux,
"linux32": islinux and is32bit,
"linux64": islinux and is64bit,
"osx": isosx,
"unix": islinux or isosx,
"win": iswin,
"win32": iswin and is32bit,
"win64": iswin and is64bit,
}

return jinja2.Template(contents).render(**jinja_dict)
Expand Down
58 changes: 58 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,65 @@
Welcome to conda-devenv's documentation!
========================================

Overview
--------

With ``conda-devenv``, we help you manage software dependencies across Linux, Windows, and macOS
operating systems using a *single conda dependency file* ``environment.devenv.yml``
instead of multiple ``environment.yml`` files.

See example below:

.. code-block:: yaml

name: mylib

dependencies:
- cmake
- eigen
- pip:
- sphinx
{% if linux %}
- gxx_linux-64=7.3.0
{% endif %}

{% if unix %}
- ccache
{% endif %}

{% if win %}
- clcache
{% endif %}

environment:
CPATH:
- $CONDA_PREFIX/include

LD_LIBRARY_PATH:
- $CONDA_PREFIX/lib

By executing:

.. code::

conda devenv

in the root of the project directory, an ``environment.yml`` file is produced.
We can now activate the conda environment ``mylib`` as follows:

.. code::

conda activate mylib

This will not only resolve the dependencies for the current operating system,
but also set environment variables ``CPATH`` and ``LD_LIBRARY_PATH`` to the
list of paths specified in the ``environment.devenv.yml`` file.

Continue reading to learn more about the full capabilities of ``conda-devenv``!


Contents:
---------

.. toctree::
:maxdepth: 2
Expand Down
49 changes: 44 additions & 5 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,56 @@ based python version, etc. For example:
name: web-ui-py{{ conda_py }}

dependencies:
{% if sys.platform.startswith('linux') %}
- boost
- cmake
{% if linux %}
- gcc
{% endif %}
{% if unix %}
- ccache
{% endif %}
{% if win %}
- clcache
{% endif %}

Note that in the example above, we are able to define dependency requirements
that are specific to Linux, macOS, and Windows (e.g., ``ccache`` is needed in
Linux and macOS, whereas ``clcache`` is needed in Windows). This is one of the
most useful capabilities of ``conda-devenv``.

The following variables are available in the Jira 2 namespace:

* ``root``: this is the full path to the directory containing the ``environment.devenv.yml`` file;
* ``os``: standard module;
* ``sys``: standard module;
* ``platform``: standard module;
.. list-table::
:widths: 20 80

* - ``root``
- The full path to the directory containing the ``environment.devenv.yml`` file.
* - ``os``
- The standard Python module object ``os`` obtained with ``import os``.
* - ``sys``
- The standard Python module object ``sys`` obtained with ``import sys``.
* - ``platform``
- The standard Python module object ``platform`` obtained with ``import platform``.
* - ``x86``
- True if the system architecture is x86, both 32-bit and 64-bit, for Intel or AMD chips.
* - ``x86_64``
- True if the system architecture is x86_64, which is 64-bit, for Intel or AMD chips.
* - ``linux``
- True if the platform is Linux.
* - ``linux32``
- True if the platform is Linux and the Python architecture is 32-bit.
* - ``linux64``
- True if the platform is Linux and the Python architecture is 64-bit.
* - ``osx``
- True if the platform is macOS.
* - ``unix``
- True if the platform is either macOS or Linux.
* - ``win``
- True if the platform is Windows.
* - ``win32``
- True if the platform is Windows and the Python architecture is 32-bit.
* - ``win64``
- True if the platform is Windows and the Python architecture is 64-bit.


Environment Variables
Expand Down
120 changes: 120 additions & 0 deletions tests/test_jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,126 @@ def test_jinja_platform(monkeypatch):
assert render_jinja(template, filename="", is_included=False) == platform.python_revision()


def test_jinja_x86(monkeypatch):
template = "{{ x86 }}"

monkeypatch.setattr(platform, 'machine', lambda: 'x86')
assert render_jinja(template, filename="", is_included=False) == 'True'

monkeypatch.setattr(platform, 'machine', lambda: 'x86_64')
assert render_jinja(template, filename="", is_included=False) == 'False'


def test_jinja_x86_64(monkeypatch):
template = "{{ x86_64 }}"

monkeypatch.setattr(platform, 'machine', lambda: 'x86')
assert render_jinja(template, filename="", is_included=False) == 'False'

monkeypatch.setattr(platform, 'machine', lambda: 'x86_64')
assert render_jinja(template, filename="", is_included=False) == 'True'


def test_jinja_linux(monkeypatch):
template = "{{ linux }}"

monkeypatch.setattr(sys, 'platform', 'linux')
assert render_jinja(template, filename="", is_included=False) == 'True'

monkeypatch.setattr(sys, 'platform', 'win')
assert render_jinja(template, filename="", is_included=False) == 'False'

monkeypatch.setattr(sys, 'platform', 'darwin')
assert render_jinja(template, filename="", is_included=False) == 'False'


def test_jinja_linux32(monkeypatch):
template = "{{ linux32 }}"

monkeypatch.setattr(sys, 'platform', 'linux')

monkeypatch.setattr(platform, 'architecture', lambda: ('32bit', ''))
assert render_jinja(template, filename="", is_included=False) == 'True'

monkeypatch.setattr(platform, 'architecture', lambda: ('64bit', ''))
assert render_jinja(template, filename="", is_included=False) == 'False'


def test_jinja_linux64(monkeypatch):
template = "{{ linux64 }}"

monkeypatch.setattr(sys, 'platform', 'linux')

monkeypatch.setattr(platform, 'architecture', lambda: ('32bit', ''))
assert render_jinja(template, filename="", is_included=False) == 'False'

monkeypatch.setattr(platform, 'architecture', lambda: ('64bit', ''))
assert render_jinja(template, filename="", is_included=False) == 'True'


def test_jinja_osx(monkeypatch):
template = "{{ osx }}"

monkeypatch.setattr(sys, 'platform', 'linux')
assert render_jinja(template, filename="", is_included=False) == 'False'

monkeypatch.setattr(sys, 'platform', 'win')
assert render_jinja(template, filename="", is_included=False) == 'False'

monkeypatch.setattr(sys, 'platform', 'darwin')
assert render_jinja(template, filename="", is_included=False) == 'True'


def test_jinja_unix(monkeypatch):
template = "{{ unix }}"

monkeypatch.setattr(sys, 'platform', 'linux')
assert render_jinja(template, filename="", is_included=False) == 'True'

monkeypatch.setattr(sys, 'platform', 'win')
assert render_jinja(template, filename="", is_included=False) == 'False'

monkeypatch.setattr(sys, 'platform', 'darwin')
assert render_jinja(template, filename="", is_included=False) == 'True'


def test_jinja_win(monkeypatch):
template = "{{ win }}"

monkeypatch.setattr(sys, 'platform', 'linux')
assert render_jinja(template, filename="", is_included=False) == 'False'

monkeypatch.setattr(sys, 'platform', 'win')
assert render_jinja(template, filename="", is_included=False) == 'True'

monkeypatch.setattr(sys, 'platform', 'darwin')
assert render_jinja(template, filename="", is_included=False) == 'False'


def test_jinja_win32(monkeypatch):
template = "{{ win32 }}"

monkeypatch.setattr(sys, 'platform', 'win')

monkeypatch.setattr(platform, 'architecture', lambda: ('32bit', ''))
assert render_jinja(template, filename="", is_included=False) == 'True'

monkeypatch.setattr(platform, 'architecture', lambda: ('64bit', ''))
assert render_jinja(template, filename="", is_included=False) == 'False'


def test_jinja_win64(monkeypatch):
template = "{{ win64 }}"

monkeypatch.setattr(sys, 'platform', 'win')

monkeypatch.setattr(platform, 'architecture', lambda: ('32bit', ''))
assert render_jinja(template, filename="", is_included=False) == 'False'

monkeypatch.setattr(platform, 'architecture', lambda: ('64bit', ''))
assert render_jinja(template, filename="", is_included=False) == 'True'


def test_jinja_invalid_template():
with pytest.raises(jinja2.exceptions.TemplateSyntaxError):
render_jinja(
Expand Down