Commit 12fd6175 authored by Godefroid Chapelle's avatar Godefroid Chapelle

Problem: default.cfg tests broken under Windows

Solution: pass environment properly, pass USERPROFILE
parent 58346265
...@@ -22,6 +22,11 @@ jobs: ...@@ -22,6 +22,11 @@ jobs:
uses: actions/setup-python@v2 uses: actions/setup-python@v2
with: with:
python_version: ${{ matrix.python_version }} python_version: ${{ matrix.python_version }}
- name: Cache eggs
uses: actions/cache@v1.2.0
with:
path: eggs
key: ${{ matrix.os }}-{{ matrix.python_version }}-eggs
- name: Install dev environment - name: Install dev environment
run: | run: |
python dev.py python dev.py
......
...@@ -1130,6 +1130,26 @@ allow us to see interactions with the buildout:: ...@@ -1130,6 +1130,26 @@ allow us to see interactions with the buildout::
... update = install ... update = install
... """) ... """)
>>> write(sample_buildout, 'recipes', 'environ.py',
... """
... import sys
... import os
... class Environ:
...
... def __init__(self, buildout, name, options):
... self.buildout = buildout
... self.options = options
...
... def install(self):
... _ = self.options['name']
... sys.stdout.write('HOME %s\\n' % os.environ['HOME'])
... sys.stdout.write('USERPROFILE %s\\n' % os.environ['USERPROFILE'])
... sys.stdout.write('expanduser %s\\n' % os.path.expanduser('~'))
... return ()
...
... update = install
... """)
This recipe doesn't actually create anything. The install method This recipe doesn't actually create anything. The install method
doesn't return anything, because it didn't create any files or doesn't return anything, because it didn't create any files or
directories. directories.
...@@ -1144,6 +1164,7 @@ We also have to update our setup script:: ...@@ -1144,6 +1164,7 @@ We also have to update our setup script::
... [zc.buildout] ... [zc.buildout]
... mkdir = mkdir:Mkdir ... mkdir = mkdir:Mkdir
... debug = debug:Debug ... debug = debug:Debug
... environ = environ:Environ
... ''') ... ''')
... setup(name="recipes", entry_points=entry_points) ... setup(name="recipes", entry_points=entry_points)
... """) ... """)
...@@ -1846,6 +1867,10 @@ Here is a more elaborate example:: ...@@ -1846,6 +1867,10 @@ Here is a more elaborate example::
... [debug] ... [debug]
... recipe = recipes:debug ... recipe = recipes:debug
... name = base ... name = base
...
... [environ]
... recipe = recipes:environ
... name = base
... """) ... """)
>>> print_(system(buildout), end='') >>> print_(system(buildout), end='')
...@@ -1971,18 +1996,18 @@ reading the configuration file. (``$HOME`` is the value of the ``HOME`` ...@@ -1971,18 +1996,18 @@ reading the configuration file. (``$HOME`` is the value of the ``HOME``
environment variable. The ``/`` is replaced by the operating system file environment variable. The ``/`` is replaced by the operating system file
delimiter.):: delimiter.)::
>>> old_home = os.environ['HOME']
>>> home = tmpdir('home') >>> home = tmpdir('home')
>>> mkdir(home, '.buildout') >>> mkdir(home, '.buildout')
>>> write(home, '.buildout', 'default.cfg', >>> default_cfg = join(home, '.buildout', 'default.cfg')
>>> write(default_cfg,
... """ ... """
... [debug] ... [debug]
... op1 = 1 ... op1 = 1
... op7 = 7 ... op7 = 7
... """) ... """)
>>> os.environ['HOME'] = home >>> env = dict(HOME=home, USERPROFILE=home)
>>> print_(system(buildout), end='') >>> print_(system(buildout, env=env), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Installing debug. Installing debug.
...@@ -1999,7 +2024,7 @@ delimiter.):: ...@@ -1999,7 +2024,7 @@ delimiter.)::
A buildout command-line argument, ``-U``, can be used to suppress reading A buildout command-line argument, ``-U``, can be used to suppress reading
user defaults:: user defaults::
>>> print_(system(buildout + ' -U'), end='') >>> print_(system(buildout + ' -U', env=env), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Installing debug. Installing debug.
...@@ -2026,8 +2051,8 @@ appropriate set of defaults:: ...@@ -2026,8 +2051,8 @@ appropriate set of defaults::
... op8 = eight! ... op8 = eight!
... """) ... """)
>>> os.environ['BUILDOUT_HOME'] = alterhome >>> env['BUILDOUT_HOME'] = alterhome
>>> print_(system(buildout), end='') >>> print_(system(buildout, env=env), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Installing debug. Installing debug.
...@@ -2045,7 +2070,7 @@ appropriate set of defaults:: ...@@ -2045,7 +2070,7 @@ appropriate set of defaults::
The ``-U`` argument still suppresses reading of the ``default.cfg`` file from The ``-U`` argument still suppresses reading of the ``default.cfg`` file from
``BUILDOUT_HOME``:: ``BUILDOUT_HOME``::
>>> print_(system(buildout + ' -U'), end='') >>> print_(system(buildout + ' -U', env=env), end='')
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling debug. Uninstalling debug.
Installing debug. Installing debug.
...@@ -2058,9 +2083,6 @@ The ``-U`` argument still suppresses reading of the ``default.cfg`` file from ...@@ -2058,9 +2083,6 @@ The ``-U`` argument still suppresses reading of the ``default.cfg`` file from
op5 b3base 5 op5 b3base 5
recipe recipes:debug recipe recipes:debug
>>> os.environ['HOME'] = old_home
>>> del os.environ['BUILDOUT_HOME']
Log level Log level
--------- ---------
......
...@@ -174,7 +174,10 @@ bases, using different caches: ...@@ -174,7 +174,10 @@ bases, using different caches:
>>> mkdir('home', '.buildout') >>> mkdir('home', '.buildout')
>>> mkdir('cache') >>> mkdir('cache')
>>> mkdir('user-cache') >>> mkdir('user-cache')
>>> os.environ['HOME'] = join(sample_buildout, 'home') >>> home=join(sample_buildout, 'home')
>>> env=dict(HOME=home, USERPROFILE=home)
>>> import functools
>>> system = functools.partial(system, env=env)
>>> write('home', '.buildout', 'default.cfg', """\ >>> write('home', '.buildout', 'default.cfg', """\
... [buildout] ... [buildout]
... extends = fancy_default.cfg ... extends = fancy_default.cfg
......
...@@ -125,12 +125,14 @@ def clean_up_pyc(*path): ...@@ -125,12 +125,14 @@ def clean_up_pyc(*path):
## FIXME - check for other platforms ## FIXME - check for other platforms
MUST_CLOSE_FDS = not sys.platform.startswith('win') MUST_CLOSE_FDS = not sys.platform.startswith('win')
def system(command, input='', with_exit_code=False): def system(command, input='', with_exit_code=False, env=None):
# Some TERMinals, especially xterm and its variants, add invisible control # Some TERMinals, especially xterm and its variants, add invisible control
# characters, which we do not want as they mess up doctests. See: # characters, which we do not want as they mess up doctests. See:
# https://github.com/buildout/buildout/pull/311 # https://github.com/buildout/buildout/pull/311
# http://bugs.python.org/issue19884 # http://bugs.python.org/issue19884
env = dict(os.environ, TERM='dumb') sub_env = dict(os.environ, TERM='dumb')
if env is not None:
sub_env.update(env)
p = subprocess.Popen(command, p = subprocess.Popen(command,
shell=True, shell=True,
...@@ -138,7 +140,7 @@ def system(command, input='', with_exit_code=False): ...@@ -138,7 +140,7 @@ def system(command, input='', with_exit_code=False):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
close_fds=MUST_CLOSE_FDS, close_fds=MUST_CLOSE_FDS,
env=env) env=sub_env)
i, o, e = (p.stdin, p.stdout, p.stderr) i, o, e = (p.stdin, p.stdout, p.stderr)
if input: if input:
i.write(input.encode()) i.write(input.encode())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment