Skip to content

Commit

Permalink
Address wntrblm#319: Give a create_tmp API
Browse files Browse the repository at this point in the history
  • Loading branch information
moshez committed May 3, 2020
1 parent b3c600c commit 45f3ff9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ def bin(self) -> Optional[str]:
"""The bin directory for the virtualenv."""
return self.virtualenv.bin

def create_tmp(self) -> Optional[str]:
bin = self.virtualenv.bin
if bin is None:
raise ValueError("Cannot have a tmp if no bin")
updir = os.path.dirname(bin)
tmpdir = os.path.join(updir, 'tmp')
if not os.path.exists(tmpdir):
os.mkdir(tmpdir)
return tmpdir

@property
def interactive(self) -> bool:
"""Returns True if Nox is being run in an interactive session or False otherwise."""
Expand Down
9 changes: 7 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import functools
import os

import nox
Expand Down Expand Up @@ -93,11 +94,14 @@ def lint(session):
@nox.session(python="3.8")
def docs(session):
"""Build the documentation."""
session.run("rm", "-rf", "docs/_build", external=True)
output_dir = os.path.join(session.create_tmp(), "output")
doctrees, html = map(functools.partial(os.path.join, output_dir),
["doctrees", "html"])
session.run("rm", "-rf", output_dir, external=True)
session.install("-r", "requirements-test.txt")
session.install(".")
session.cd("docs")
sphinx_args = ["-b", "html", "-W", "-d", "_build/doctrees", ".", "_build/html"]
sphinx_args = ["-b", "html", "-W", "-d", doctrees, ".", html]

if not session.interactive:
sphinx_cmd = "sphinx-build"
Expand All @@ -106,3 +110,4 @@ def docs(session):
sphinx_args.insert(0, "--open-browser")

session.run(sphinx_cmd, *sphinx_args)
session.create_tmp()

0 comments on commit 45f3ff9

Please sign in to comment.