Skip to content

Strange Issue with ctx.cd (possibly within my env?) #577

@haydenflinner

Description

@haydenflinner

Hey, loving the library so far. Very handy and all it's missing to me is make-like dependency refresh recognition, which I might get around to working on eventually if there's any interest.

Had a script that was working, then stopped working after I poked around reading the source. Here's the traceback

Traceback (most recent call last):
  File "/spare/local/hflinner/venv-infra/bin/invoke", line 11, in <module>
	sys.exit(program.run())
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/program.py", line 363, in run
	self.execute()
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/program.py", line 532, in execute
	executor.execute(*self.tasks)
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/executor.py", line 129, in execute
	result = call.task(*args, **call.kwargs)
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/tasks.py", line 128, in call
	result = self.body(*args, **kwargs)
  File "/spare/local/hflinner/invoke/myproj/tools/tests/tasks.py", line 23, in build1
	ctx.run(release_cmd)
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/context.py", line 94, in run
	return self._run(runner, command, **kwargs)
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/context.py", line 100, in _run
	command = self._prefix_commands(command)Had a script that was working, then stopped working after I poked around reading 
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/context.py", line 242, in _prefix_commands
	current_directory = self.cwd
  File "/spare/local/hflinner/venv-infra/lib/python2.7/site-packages/invoke/config.py", line 125, in getattr
	raise AttributeError(err)
AttributeError: No attribute or config key found for 'cwd'

Valid keys: ['Path', 'debug', 'find_config', 'find_here', 'lazy', 'listen', 'log_dir', 'make',  'market', 'mytarget', 'run', 'runners', 'server', 'set_paths', 'sudo', 'super_repo_root', 'task', 'tasks', 'workspace']

Valid real attributes: ['cd', 'clear', 'config', 'cwd', 'from_data', 'pop', 'popitem', 'prefix', 'run', 'setdefault', 'sudo', 'update']

Notice that the error is that cwd isn't found but cwd is a valid real attribute. This happened after I poked around in the source a bit, so I suspected it was my fault for accidentally changing something. So I rm -rf invoke* 'd in my site-packages directory and reinstalled, but the problem persists. There's nothing that seems suspicious to me in my config. I'm executing invoke build1 mytarget where build1 looks like this

@task
def build1(ctx, target):
   logging.info("Releasing {} to {}"
                .format(target, ctx.make.release_dir))
   cfg = ctx[target]
   with ctx.cd(ctx.server.repo_root):
       print(ctx)
       ctx.run(release_cmd)

Where the traceback is erroring out on the ctx.run. Adding a cwd field to my invoke.py "fixes" the issue. But this function used to work!

Note: Fixed my error, turned out to be something that I think could be handled better?
with ctx.cd(str(ctx.server.repo_root)):
Where repo_root is a pathlib2 Path obj, not a string (my invoke.py is somewhat large and involved).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions