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

Delay os.getcwd() call to function body #243

Merged
merged 13 commits into from
May 27, 2024
20 changes: 20 additions & 0 deletions news/205-getcwd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Enhancements

* <news item>

### Bug fixes

* Delay ``os.getcwd()`` call to body of ``CondaFormat_v2.create()`` when
``out_folder`` is not passed. (#205)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@ line-length = 99
[tool.isort]
profile = "black"
line_length = 99

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new hotness

[tool.pytest]
norecursedirs = [".*", "*.egg*", "build", "dist", "conda.recipe"]
addopts = [
"--junitxml=junit.xml",
"--ignore setup.py",
"--ignore run_test.py",
"--cov-report term-missing",
"--tb native",
"--strict-markers",
"--durations=20",
]
markers = ["serial: execute test serially (to avoid race conditions)"]
15 changes: 0 additions & 15 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,3 @@
max-line-length = 100
ignore = E122,E123,E126,E127,E128,E731,E722
exclude = build,src/conda_package_handling/_version.py,tests,conda.recipe,.git,versioneer.py,benchmarks,.asv,rever

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old n' busted

[tool:pytest]
norecursedirs= .* *.egg* build dist conda.recipe
addopts =
--junitxml=junit.xml
--ignore setup.py
--ignore run_test.py
--cov-report term-missing
--tb native
--strict-markers
--durations=20
env =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid pytest-env requirement

PYTHONHASHSEED=0
markers =
serial: execute test serially (to avoid race conditions)
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
python_requires=">=3.8",
install_requires=["conda-package-streaming >= 0.9.0"],
extras_require={
"docs": ["furo", "sphinx", "sphinx-argparse", "myst-parser", "mdit-py-plugins>=0.3.0"],
"docs": [
"furo",
"sphinx",
"sphinx-argparse",
"myst-parser",
"mdit-py-plugins>=0.3.0",
],
"test": ["mock", "pytest", "pytest-cov", "pytest-mock"],
},
)
4 changes: 3 additions & 1 deletion src/conda_package_handling/conda_fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ def create(
prefix,
file_list,
out_fn,
out_folder=os.getcwd(),
out_folder=None,
compressor: Callable[[], zstandard.ZstdCompressor] | None = None,
compression_tuple=(None, None, None),
):
if out_folder is None:
out_folder = os.getcwd()
if os.path.isabs(out_fn):
out_folder = os.path.dirname(out_fn)
out_fn = os.path.basename(out_fn)
Expand Down
5 changes: 3 additions & 2 deletions src/conda_package_handling/interface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import abc
import os


class AbstractBaseFormat(metaclass=abc.ABCMeta):
Expand All @@ -15,7 +16,7 @@ def extract(fn, dest_dir, **kw): # pragma: no cover

@staticmethod
@abc.abstractmethod
def create(prefix, file_list, out_fn, out_folder=os.getcwd(), **kw): # pragma: no cover
def create(prefix, file_list, out_fn, out_folder: str | None = None, **kw): # pragma: no cover
raise NotImplementedError

@staticmethod
Expand Down
4 changes: 3 additions & 1 deletion src/conda_package_handling/tarball.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def extract(fn, dest_dir, **kw):
streaming._extract(str(fn), str(dest_dir), components=["pkg"])

@staticmethod
def create(prefix, file_list, out_fn, out_folder=os.getcwd(), **kw):
def create(prefix, file_list, out_fn, out_folder=None, **kw):
if out_folder is None:
out_folder = os.getcwd()
if os.path.isabs(out_fn):
out_folder = os.path.dirname(out_fn)
out_file = create_compressed_tarball(
Expand Down
32 changes: 28 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ def test_cli(tmpdir, mocker):
Code coverage for the cli.
"""
for command in [
["x", str(Path(data_dir, test_package_name + ".tar.bz2")), f"--prefix={tmpdir}"],
[
"x",
str(Path(data_dir, test_package_name + ".tar.bz2")),
f"--prefix={tmpdir}",
],
[
"x",
str(Path(data_dir, test_package_name + ".conda")),
"--info",
f"--prefix={tmpdir}",
],
["c", str(Path(tmpdir, test_package_name)), ".tar.bz2", f"--out-folder={tmpdir}"],
[
"c",
str(Path(tmpdir, test_package_name)),
".tar.bz2",
f"--out-folder={tmpdir}",
],
]:
cli.main(args=command)

Expand All @@ -29,7 +38,8 @@ def test_cli(tmpdir, mocker):
# returning errors. Designed for .tar.bz2 -> .conda conversions that somehow
# omit files?
mocker.patch(
"conda_package_handling.api.transmute", return_value=set("that is why you fail".split())
"conda_package_handling.api.transmute",
return_value=set("that is why you fail".split()),
)
with pytest.raises(SystemExit):
command = [
Expand All @@ -55,6 +65,20 @@ def test_import_main():
)
def test_list(artifact, n_files, capsys):
"Integration test to ensure `cph list` works correctly."
cli.main(["list", os.path.join(data_dir, artifact)])
cli.main(["list", os.path.relpath(os.path.join(data_dir, artifact), os.getcwd())])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code coverage for "is path relative? call abspath()" in list code

stdout, stderr = capsys.readouterr()
assert n_files == sum(bool(line.strip()) for line in stdout.splitlines())

# test verbose flag
cli.main(
[
"list",
"--verbose",
os.path.join(data_dir, artifact),
]
)
stdout, stderr = capsys.readouterr()
assert n_files == sum(bool(line.strip()) for line in stdout.splitlines())

with pytest.raises(ValueError):
cli.main(["list", "setup.py"])
Loading