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

Enable --only-deps with FLIT_ALLOW_INVALID #631

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
375b69a
Enable --only-deps with FLIT_ALLOW_INVALID
dciborow Mar 12, 2023
0abd802
undo black
dciborow Mar 12, 2023
7fa6cc0
undo black
dciborow Mar 12, 2023
09255a7
fix black
dciborow Mar 12, 2023
f4efdea
fix black
dciborow Mar 12, 2023
b2c311c
Delete pyproject.toml
dciborow Mar 12, 2023
b958dfb
fix black
dciborow Mar 12, 2023
8025d09
fix black
dciborow Mar 12, 2023
2a3dbe9
fix black
dciborow Mar 12, 2023
3d8820b
fix black
dciborow Mar 12, 2023
10156bf
fix error message
dciborow Mar 12, 2023
903b32e
unblack
dciborow Mar 12, 2023
e91b4d7
fix tests
dciborow Mar 12, 2023
9aabad5
Update test_install.py
dciborow Mar 12, 2023
7694731
Create
dciborow Mar 12, 2023
e90caf4
Update install.py
dciborow Mar 12, 2023
c1c3b50
Update test_install.py
dciborow Mar 12, 2023
757d675
Update install.py
dciborow Mar 12, 2023
4064a53
Update config.py
dciborow Mar 12, 2023
9b5ae82
Delete Dockerfile
dciborow Mar 12, 2023
3ce790e
Delete devcontainer.json
dciborow Mar 12, 2023
e1b2f71
Delete settings.json
dciborow Mar 12, 2023
68acc55
Update missing-description-file.toml
dciborow Mar 12, 2023
8f1192f
Delete only-deps.toml
dciborow Mar 12, 2023
d0828d7
Update test_install.py
dciborow Mar 12, 2023
9f94a37
simplify error catch
dciborow Mar 13, 2023
5e5ed22
fix quotes
dciborow Mar 13, 2023
c313a69
fix quotes
dciborow Mar 13, 2023
7aaee9a
Update flit_core/flit_core/config.py
dciborow Mar 13, 2023
8240510
Update common.py
dciborow Mar 13, 2023
75491ea
Update common.py
dciborow Mar 13, 2023
2d2d664
Update config.py
dciborow Mar 13, 2023
aa85c27
Update config.py
dciborow Mar 13, 2023
e232e55
Update common.py
dciborow Mar 13, 2023
c3cb99e
Update config.py
dciborow Mar 13, 2023
a953776
Update common.py
dciborow Mar 13, 2023
8aeb880
Update missing-module.toml
dciborow Mar 13, 2023
d55a4a6
Update test_install.py
dciborow Mar 13, 2023
dc80d69
Update tests/test_install.py
dciborow Mar 13, 2023
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
12 changes: 9 additions & 3 deletions flit_core/flit_core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ def __init__(self, name, directory=Path()):
.format(name, ", ".join([str(p) for p in sorted(existing)]))
)
elif not existing:
raise ValueError("No file/folder found for module {}".format(name))

self.source_dir = directory / self.prefix
if os.environ.get("FLIT_ALLOW_INVALID"):
log.warning(
"Allowing invalid data (FLIT_ALLOW_INVALID set). No file/folder found for module {}"
.format(name)
)
else:
raise ValueError("No file/folder found for module {}".format(name))
else:
self.source_dir = directory / self.prefix

if '.' in name:
self.namespace_package_name = name.rpartition('.')[0]
Expand Down
6 changes: 6 additions & 0 deletions flit_core/flit_core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ def description_from_file(rel_path: str, proj_dir: Path, guess_mimetype=True):
with desc_path.open('r', encoding='utf-8') as f:
raw_desc = f.read()
except IOError as e:
if os.environ.get('FLIT_ALLOW_INVALID'):
log.warning(
"Allowing invalid data (FLIT_ALLOW_INVALID set). Description file {} does not exist"
.format(desc_path)
)
return None, None
dciborow marked this conversation as resolved.
Show resolved Hide resolved
if e.errno == errno.ENOENT:
raise ConfigError(
"Description file {} does not exist".format(desc_path)
Expand Down
1 change: 1 addition & 0 deletions tests/samples/missing-description-file.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ author = "Sir Robin"
author-email = "[email protected]"
home-page = "http://github.com/sirrobin/missingdescriptionfile"
description-file = "definitely-missing.rst"
requires = ["requests"]
10 changes: 10 additions & 0 deletions tests/samples/missing-module.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build-system]
requires = ["flit"]

[tool.flit.metadata]
module = "definitelymissingmodule"
author = "Sir Robin"
author-email = "[email protected]"
home-page = "http://github.com/sirrobin/module1"
description-file = "EG_README.rst"
requires = ["requests"]
27 changes: 27 additions & 0 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from flit import install
from flit.install import Installer, _requires_dist_to_pip_requirement, DependencyError
from flit_core.config import ConfigError
import flit_core.tests

samples_dir = pathlib.Path(__file__).parent / 'samples'
Expand Down Expand Up @@ -278,6 +279,32 @@ def test_install_requires(self):
assert len(calls) == 1
assert calls[0]['argv'][1:5] == ['-m', 'pip', 'install', '-r']

def test_install_only_deps(self):
"""Test if we can install using --only-deps with the pyproject.toml, and without the README or module folder"""
os.environ.setdefault('FLIT_ALLOW_INVALID', '1')
try:
ins = Installer.from_ini_path(
samples_dir / 'missing-description-file.toml', user=False, python='mock_python'
)

with MockCommand('mock_python') as mockpy:
ins.install_requirements()
calls = mockpy.get_calls()
assert len(calls) == 1
assert calls[0]['argv'][1:5] == ['-m', 'pip', 'install', '-r']
finally:
del os.environ['FLIT_ALLOW_INVALID']

def test_install_only_deps_fail(self):
with pytest.raises(ConfigError, match=r"Description file .* does not exist"):
Installer.from_ini_path(
samples_dir / 'missing-description-file.toml', user=False, python='mock_python'
)
with pytest.raises(ValueError, match=r"No file/folder found for module definitelymissingmodule"):
Installer.from_ini_path(
samples_dir / 'missing-module.toml', user=False, python='mock_python'
)

def test_install_reqs_my_python_if_needed_pep621(self):
ins = Installer.from_ini_path(
core_samples_dir / 'pep621_nodynamic' / 'pyproject.toml',
Expand Down