Esempio n. 1
0
def do_lock():
    """Executes the freeze functionality."""

    # Purge the virtualenv download dir, for development dependencies.
    do_purge(downloads=True, bare=True)

    click.echo(crayons.yellow('Locking {0} dependencies...'.format(crayons.red('[dev-packages]'))))

    with spinner():
        # Install only development dependencies.
        names_map = do_download_dependencies(dev=True, only=True, bare=True)

    # Load the Pipfile and generate a lockfile.
    p = pipfile.load(project.pipfile_location)
    lockfile = json.loads(p.lock())

    # Pip freeze development dependencies.
    with spinner():
        results = get_downloads_info(names_map, 'dev-packages')

    # Clear generated lockfile before updating.
    lockfile['develop'] = {}

    # Add Development dependencies to lockfile.
    for dep in results:
        if dep:
            lockfile['develop'].update({dep['name']: {'hash': dep['hash'], 'version': '=={0}'.format(dep['version'])}})

    with spinner():
        # Purge the virtualenv download dir, for default dependencies.
        do_purge(downloads=True, bare=True)

    click.echo(crayons.yellow('Locking {0} dependencies...'.format(crayons.red('[packages]'))))

    with spinner():
        # Install only development dependencies.
        names_map = do_download_dependencies(bare=True)

    # Pip freeze default dependencies.
    results = get_downloads_info(names_map, 'packages')

    # Clear generated lockfile before updating.
    lockfile['default'] = {}

    # Add default dependencies to lockfile.
    for dep in results:
        if dep:
            lockfile['default'].update({dep['name']: {'hash': dep['hash'], 'version': '=={0}'.format(dep['version'])}})

    # Write out lockfile.
    with open(project.lockfile_location, 'w') as f:
        f.write(json.dumps(lockfile, indent=4, separators=(',', ': ')))

    # Purge the virtualenv download dir, for next time.
    with spinner():
        do_purge(downloads=True, bare=True)

    click.echo('{0} Pipfile.lock{1}'.format(crayons.yellow('Updated'), crayons.yellow('!')))
Esempio n. 2
0
def do_init(dev=False,
            requirements=False,
            allow_global=False,
            ignore_hashes=False,
            no_hashes=True,
            ignore_pipfile=False,
            skip_lock=False):
    """Executes the init functionality."""

    ensure_pipfile()

    # Display where the Project is established.
    if not requirements:
        do_where(bare=False)

    if not project.virtualenv_exists:
        try:
            do_create_virtualenv()
        except KeyboardInterrupt:
            cleanup_virtualenv(bare=False)
            sys.exit(1)

    # Write out the lockfile if it doesn't exist, but not if the Pipfile is being ignored
    if (project.lockfile_exists and not ignore_pipfile) and not skip_lock:

        # Open the lockfile.
        with codecs.open(project.lockfile_location, 'r') as f:
            lockfile = json.load(f)

        # Update the lockfile if it is out-of-date.
        p = pipfile.load(project.pipfile_location)

        # Check that the hash of the Lockfile matches the lockfile's hash.
        if not lockfile['_meta'].get('hash', {}).get('sha256') == p.hash:
            click.echo(crayons.red('Pipfile.lock out of date, updating...'),
                       err=True)

            do_lock(no_hashes=no_hashes)

    # Write out the lockfile if it doesn't exist.
    if not project.lockfile_exists and not skip_lock:
        click.echo(crayons.yellow('Pipfile.lock not found, creating...'),
                   err=True)
        do_lock(no_hashes=no_hashes)

    # Override default `ignore_hashes` value if `no_hashes` set.
    ignore_hashes = ignore_hashes or no_hashes

    do_install_dependencies(dev=dev,
                            requirements=requirements,
                            allow_global=allow_global,
                            ignore_hashes=ignore_hashes,
                            skip_lock=skip_lock)

    # Activate virtualenv instructions.
    if not allow_global:
        do_activate_virtualenv()
Esempio n. 3
0
def do_install_dependencies(dev=False,
                            only=False,
                            bare=False,
                            requirements=False,
                            allow_global=False):
    """"Executes the install functionality."""

    if requirements:
        bare = True

    # Load the Pipfile.
    p = pipfile.load(project.pipfile_location)

    # Load the lockfile if it exists, or if only is being used (e.g. lock is being used).
    if only or not project.lockfile_exists:
        if not bare:
            click.echo(
                crayons.yellow('Installing dependencies from Pipfile...'))
            lockfile = json.loads(p.lock())
    else:
        if not bare:
            click.echo(
                crayons.yellow('Installing dependencies from Pipfile.lock...'))
        with open(project.lockfile_location) as f:
            lockfile = json.load(f)

    # Install default dependencies, always.
    deps = lockfile['default'] if not only else {}

    # Add development deps if --dev was passed.
    if dev:
        deps.update(lockfile['develop'])

    # Convert the deps to pip-compatible arguments.
    deps_path = convert_deps_to_pip(deps)

    # --requirements was passed.
    if requirements:
        with open(deps_path) as f:
            click.echo(f.read())
            sys.exit(0)

    # pip install:
    with spinner():
        c = pip_install(r=deps_path, allow_global=allow_global)

    if c.return_code != 0:
        click.echo(crayons.red('An error occured while installing!'))
        click.echo(crayons.blue(format_pip_error(c.err)))
        sys.exit(c.return_code)

    if not bare:
        click.echo(crayons.blue(format_pip_output(c.out, r=deps_path)))

    # Cleanup the temp requirements file.
    if requirements:
        os.remove(deps_path)
Esempio n. 4
0
 def _lockfile(self):
     """Pipfile.lock divided by PyPI and external dependencies."""
     pfile = pipfile.load(self.pipfile_location, inject_env=False)
     lockfile = json.loads(pfile.lock())
     for section in ("default", "develop"):
         lock_section = lockfile.get(section, {})
         for key in list(lock_section.keys()):
             norm_key = pep423_name(key)
             lockfile[section][norm_key] = lock_section.pop(key)
     return lockfile
Esempio n. 5
0
 def _get_pipfile(self, ctx):
     if 'pipfile' not in ctx.state:
         pipfile_path = ctx.root_path / 'Pipfile'
         if pipfile_path.is_file():
             import pipfile
             pf = pipfile.load(str(pipfile_path))
         else:
             pf = None
         ctx.state['pipfile'] = pf
     return ctx.state['pipfile']
Esempio n. 6
0
 def _lockfile(self):
     """Pipfile.lock divided by PyPI and external dependencies."""
     pfile = pipfile.load(self.pipfile_location, inject_env=False)
     lockfile = json.loads(pfile.lock())
     for section in ('default', 'develop'):
         lock_section = lockfile.get(section, {})
         for key in list(lock_section.keys()):
             norm_key = pep423_name(key)
             lockfile[section][norm_key] = lock_section.pop(key)
     return lockfile
Esempio n. 7
0
 def _extract_packages_from_pipfile(self) -> List[str]:
     packages = []
     pip_file = pipfile.load(os.path.join(self._path, "Pipfile"))
     data = pip_file.data
     if len(data["default"]) > 0:
         for key, _ in data["default"].items():
             packages.append(key)
     if len(data["develop"]) > 0:
         for key, _ in data["develop"].items():
             packages.append(key)
     return packages
Esempio n. 8
0
def do_install_dependencies(dev=False, only=False, bare=False, requirements=False, allow_global=False):
    """"Executes the install functionality."""

    if requirements:
        bare = True

    # Load the Pipfile.
    p = pipfile.load(project.pipfile_location)

    # Load the lockfile if it exists, or if only is being used (e.g. lock is being used).
    if only or not project.lockfile_exists:
        if not bare:
            click.echo(crayons.yellow('Installing dependencies from Pipfile...'))
            lockfile = json.loads(p.lock())
    else:
        if not bare:
            click.echo(crayons.yellow('Installing dependencies from Pipfile.lock...'))
        with open(project.lockfile_location) as f:
            lockfile = json.load(f)

    # Install default dependencies, always.
    deps = lockfile['default'] if not only else {}

    # Add development deps if --dev was passed.
    if dev:
        deps.update(lockfile['develop'])

    # Convert the deps to pip-compatible arguments.
    deps_path = convert_deps_to_pip(deps)

    # --requirements was passed.
    if requirements:
        with open(deps_path) as f:
            click.echo(f.read())
            sys.exit(0)

    # pip install:
    with spinner():
        c = pip_install(r=deps_path, allow_global=allow_global)

    if c.return_code != 0:
        click.echo(crayons.red('An error occured while installing!'))
        click.echo(crayons.blue(format_pip_error(c.err)))
        sys.exit(c.return_code)

    if not bare:
        click.echo(crayons.blue(format_pip_output(c.out, r=deps_path)))

    # Cleanup the temp requirements file.
    if requirements:
        os.remove(deps_path)
Esempio n. 9
0
def do_lock():
    """Executes the freeze functionality."""

    # Purge the virtualenv download dir, for development dependencies.
    do_purge(downloads=True, bare=True)

    click.echo(crayons.yellow('Locking {0} dependencies...'.format(crayons.red('[dev-packages]'))))

    # Install only development dependencies.
    names_map = do_download_dependencies(dev=True, only=True, bare=True)

    # Load the Pipfile and generate a lockfile.
    p = pipfile.load(project.pipfile_location)
    lockfile = json.loads(p.lock())

    # Pip freeze development dependencies.
    results = get_downloads_info(names_map, 'dev-packages')

    # Clear generated lockfile before updating.
    lockfile['develop'] = {}

    # Add Development dependencies to lockfile.
    for dep in results:
        if dep:
            lockfile['develop'].update({dep['name']: {'hash': dep['hash'], 'version': '=={0}'.format(dep['version'])}})

    # Purge the virtualenv download dir, for default dependencies.
    do_purge(downloads=True, bare=True)

    click.echo(crayons.yellow('Locking {0} dependencies...'.format(crayons.red('[packages]'))))

    # Install only development dependencies.
    names_map = do_download_dependencies(bare=True)

    # Pip freeze default dependencies.
    results = get_downloads_info(names_map, 'packages')

    # Clear generated lockfile before updating.
    lockfile['default'] = {}

    # Add default dependencies to lockfile.
    for dep in results:
        if dep:
            lockfile['default'].update({dep['name']: {'hash': dep['hash'], 'version': '=={0}'.format(dep['version'])}})

    # Write out lockfile.
    with open(project.lockfile_location, 'w') as f:
        f.write(json.dumps(lockfile, indent=4, separators=(',', ': ')))

    # Purge the virtualenv download dir, for next time.
    do_purge(downloads=True, bare=True)
Esempio n. 10
0
def test_python_version():
    project_dir = os.path.join(os.path.dirname(__file__), '..')

    with open(os.path.join(project_dir, '.travis.yml')) as f:
        travis_py_version = yaml.safe_load(f)['python'][0]

    pipfile_data = pipfile.load(os.path.join(project_dir, 'Pipfile')).data
    pipfile_py_version = pipfile_data['_meta']['requires']['python_version']

    with open(os.path.join(project_dir, 'README.md')) as f:
        readme = f.read()

    assert travis_py_version == pipfile_py_version
    assert f'Python {travis_py_version}' in readme
Esempio n. 11
0
def test_python_version_is_consistent_accross_all_configuration_and_readme():
    project_dir = Path(__file__).parent.parent

    ci_config_file = project_dir / '.circleci' / 'config.yml'
    ci_config = yaml.safe_load(ci_config_file.read_text())
    ci_docker_image = ci_config['jobs']['build']['docker'][0]['image']
    ci_py_version = ci_docker_image.replace('circleci/python:', '')

    pipfile_data = pipfile.load(os.path.join(project_dir, 'Pipfile')).data
    pipfile_py_version = pipfile_data['_meta']['requires']['python_version']

    readme = (project_dir / 'README.md').read_text()

    assert ci_py_version == pipfile_py_version
    assert f'Python {ci_py_version}' in readme
def get_default_packages(
    pipfile_path,
):  # type: (Path) -> Tuple[Dict[str, PipfileConfig], Dict[str, PipfileConfig]]
    """
    return local packages and remote packages in default packages (not dev)
    """
    local_packages = {}  # type: Dict[str, PipfileConfig]
    remote_packages = {}  # type: Dict[str, PipfileConfig]
    for package_name, config in pipfile.load(
            str(pipfile_path)).data["default"].items():
        if is_remote_package(config):
            remote_packages[package_name] = config
        else:
            local_packages[package_name] = config
    return local_packages, remote_packages
Esempio n. 13
0
def do_init(dev=False,
            requirements=False,
            skip_virtualenv=False,
            allow_global=False,
            ignore_hashes=False,
            no_hashes=False):
    """Executes the init functionality."""

    ensure_pipfile()

    # Display where the Project is established.
    if not requirements:
        do_where(bare=False)

    if not project.virtualenv_exists:
        do_create_virtualenv()

    # Write out the lockfile if it doesn't exist.
    if project.lockfile_exists:

        # Open the lockfile.
        with codecs.open(project.lockfile_location, 'r') as f:
            lockfile = json.load(f)

        # Update the lockfile if it is out-of-date.
        p = pipfile.load(project.pipfile_location)

        # Check that the hash of the Lockfile matches the lockfile's hash.
        if not lockfile['_meta'].get('hash', {}).get('sha256') == p.hash:
            click.echo(crayons.red('Pipfile.lock out of date, updating...'),
                       err=True)

            do_lock(no_hashes=no_hashes)

    # Write out the lockfile if it doesn't exist.
    if not project.lockfile_exists:
        click.echo(crayons.yellow('Pipfile.lock not found, creating...'),
                   err=True)
        do_lock(no_hashes=no_hashes)

    do_install_dependencies(dev=dev,
                            requirements=requirements,
                            allow_global=allow_global,
                            ignore_hashes=ignore_hashes)

    # Activate virtualenv instructions.
    do_activate_virtualenv()
Esempio n. 14
0
def test_python_version_is_consistent_accross_all_configuration_and_readme():
    project_dir = Path(__file__).parent.parent

    ci_config_file = project_dir / '.github/workflows/main.yml'
    ci_config = yaml.safe_load(ci_config_file.read_text())
    ci_steps = ci_config['jobs']['build']['steps']
    ci_py_version = None
    for step in ci_steps:
        if step['uses'].startswith('actions/setup-python'):
            ci_py_version = step['with']['python-version']
            ci_py_name_version = step['name'].split(' ')[-1]
            break

    pipfile_data = pipfile.load(os.path.join(project_dir, 'Pipfile')).data
    pipfile_py_version = pipfile_data['_meta']['requires']['python_version']

    readme = (project_dir / 'README.md').read_text()

    assert str(ci_py_version) == str(pipfile_py_version) == ci_py_name_version
    assert f'Python {ci_py_version}' in readme
Esempio n. 15
0
def do_download_dependencies(dev=False, only=False, bare=False):
    """"Executes the download functionality."""

    # Load the Pipfile.
    p = pipfile.load(project.pipfile_location)

    # Load the Pipfile.
    if not bare:
        click.echo(crayons.yellow('Downloading dependencies from Pipfile...'))
    lockfile = json.loads(p.lock())

    # Install default dependencies, always.
    deps = lockfile['default'] if not only else {}

    # Add development deps if --dev was passed.
    if dev:
        deps.update(lockfile['develop'])

    # Convert the deps to pip-compatible arguments.
    deps = convert_deps_to_pip(deps, r=False)

    # Actually install each dependency into the virtualenv.
    name_map = {}
    for package_name in deps:

        if not bare:
            click.echo('Downloading {0}...'.format(
                crayons.green(package_name)))

        # pip install:
        c = pip_download(package_name)

        if not bare:
            click.echo(crayons.blue(c.out))

        parsed_output = parse_install_output(c.out)
        for filename, name in parsed_output:
            name_map[filename] = name

    return name_map
Esempio n. 16
0
def do_download_dependencies(dev=False, only=False, bare=False):
    """"Executes the download functionality."""

    # Load the Pipfile.
    p = pipfile.load(project.pipfile_location)

    # Load the Pipfile.
    if not bare:
        click.echo(crayons.yellow('Downloading dependencies from Pipfile...'))
    lockfile = json.loads(p.lock())

    # Install default dependencies, always.
    deps = lockfile['default'] if not only else {}

    # Add development deps if --dev was passed.
    if dev:
        deps.update(lockfile['develop'])

    # Convert the deps to pip-compatible arguments.
    deps = convert_deps_to_pip(deps, r=False)

    # Actually install each dependency into the virtualenv.
    name_map = {}
    for package_name in deps:

        if not bare:
            click.echo('Downloading {0}...'.format(crayons.green(package_name)))

        # pip install:
        c = pip_download(package_name)

        if not bare:
            click.echo(crayons.blue(c.out))

        parsed_output = parse_install_output(c.out)
        for filename, name in parsed_output:
            name_map[filename] = name

    return name_map
Esempio n. 17
0
def do_init(dev=False, requirements=False, skip_virtualenv=False, allow_global=False):
    """Executes the init functionality."""

    ensure_pipfile()

    # Display where the Project is established.
    if not requirements:
        do_where(bare=False)

    if not project.virtualenv_exists:
        do_create_virtualenv()

    # Write out the lockfile if it doesn't exist.
    if project.lockfile_exists:

        # Open the lockfile.
        with codecs.open(project.lockfile_location, 'r') as f:
            lockfile = json.load(f)

        # Update the lockfile if it is out-of-date.
        p = pipfile.load(project.pipfile_location)

        # Check that the hash of the Lockfile matches the lockfile's hash.
        if not lockfile['_meta'].get('hash', {}).get('sha256') == p.hash:
            click.echo(crayons.red('Pipfile.lock out of date, updating...'), err=True)

            do_lock()

    # Write out the lockfile if it doesn't exist.
    if not project.lockfile_exists:
        click.echo(crayons.yellow('Pipfile.lock not found, creating...'), err=True)
        do_lock()

    do_install_dependencies(dev=dev, requirements=requirements, allow_global=allow_global)

    # Activate virtualenv instructions.
    do_activate_virtualenv()
Esempio n. 18
0
 def calculate_pipfile_hash(self):
     # Update the lockfile if it is out-of-date.
     p = pipfile.load(self.pipfile_location, inject_env=False)
     return p.hash
Esempio n. 19
0
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

import setuptools
import pipfile

with open("README.rst", "r") as fh:
    long_description = fh.read()

install_requires = []
pf = pipfile.load('Pipfile').data['default']
for key, value in pf.items():
    temp = str(key) + '==' + str(value)
    # temp = [str(key), str(value)]
    # temp = str(key)
    install_requires.append(temp)
print(install_requires)

exec(open('pyiets/version.py').read())
setuptools.setup(
    name='pyiets',
    version=__version__,
    author=('Benjamin Bolbrinker, Michael Deffner, ' +
            'Martin Zoellner, Carmen Herrmann'),
    author_email='*****@*****.**',
    description='A tool for calculating inelastic tunneling spectra',
Esempio n. 20
0
def get_pipfile_hash(directory):
    p = pipfile.load(directory + '/Pipfile')

    return json.dumps({"result": p.hash})
Esempio n. 21
0
		#Parse the version from the text of __init__.py because
		#importing it directly before setup can cause problems
		#with the setup itself
		r'__version__\s*=\s*[\'"](\d+\.\d+\.\d+)[\'"]',
		open(join(dirname(__file__), 'qcrit', '__init__.py'), mode='r').read()
	).group(1),
	author='Tim Gianitsos',
	author_email='*****@*****.**',
	description=(
		'Easily extract features from texts, and run machine learning algorithms '
		'on them. Write your own features, use ours, or do both!'
	),
	long_description=open(join(dirname(__file__), 'README.md'), mode='r').read(),
	long_description_content_type='text/markdown',
	url='https://www.qcrit.org',
	project_urls={'Source Code': 'https://github.com/QuantitativeCriticismLab/qcrit'},
	packages=setuptools.find_packages(),
	classifiers=[
		'Programming Language :: Python :: 3.6',
		'Programming Language :: Python :: 3.7',
		'License :: OSI Approved :: MIT License',
		'Operating System :: OS Independent',
	],
	install_requires=[
		#Use the [packages] section from the Pipfile to determine required dependencies
		#The [dev-packages] section is not included
		pkg + (version if version != '*' else '')
		for pkg, version in pipfile.load(join(dirname(__file__), 'Pipfile')).data['default'].items()
	],
)
Esempio n. 22
0
def read_python_version() -> str:
    return pipfile.load().data['_meta']['requires']['python_version']
Esempio n. 23
0
def load_requirements() -> List[str]:
    # return read_file('requirements.txt').splitlines()
    return [
        f'{package}{version}'
        for package, version in pipfile.load().data['default'].items()
    ]
 def load_vector_pipfile(name):
     pipfile_location = os.path.join(VECTORS_FOLDER, name)
     pfile = pipfile.load(pipfile_location)
     pipfile_json = json.loads(pfile.lock())
     return pipfile_json
Esempio n. 25
0
import codecs
import os
import re

from setuptools import setup

from pipfile import load  # isort:skip

here = os.path.abspath(os.path.dirname(__file__))
requires = load("Pipfile").data["default"]


def read(*parts):
    with codecs.open(os.path.join(here, *parts), "r") as fp:
        return fp.read()


def find_version(*file_paths):
    version_file = read(*file_paths)
    version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M)
    if version_match:
        return version_match.group(1)
    raise RuntimeError("Unable to find version string.")


setup(
    name="plcx",
    version=find_version("plcx", "__init__.py"),
    description="async PLC communication",
    long_description="",
    classifiers=[
Esempio n. 26
0
 def calculate_pipfile_hash(self):
     # Update the lockfile if it is out-of-date.
     p = pipfile.load(self.pipfile_location, inject_env=False)
     return p.hash
Esempio n. 27
0
def get_requirements():
    pip_file = pipfile.load()
    return os.linesep.join([
        package_name
        for package_name, package_version in pip_file.data['default'].items()])
Esempio n. 28
0
def parse_pipfile(package):
    pf = pipfile.load('Pipfile')
    return [f'{pack}{version}' for pack, version in pf.data[package].items()]
Esempio n. 29
0
#!/usr/bin/env python3
"""Setup file to package imu_generator."""

import pipfile
from setuptools import find_packages, setup

# pipfile: when using pipenv, get the dependencies listed in Pipfile
PF = pipfile.load('Pipfile')
PFLIST = [('{}{}'.format(pkg_name, version) if version != '*' else pkg_name)
          for pkg_name, version in PF.data['default'].items()]

setup(
    name='imu_generator',
    description='Python program for me',
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Environment :: Macos',
        'Intended Audience :: Developers',
        'Natural Language :: English, French',
        'Programming Language :: Python 3',
    ],
    author='Thibaut Grall',
    author_email='_',
    url='_',
    #
    # Find_packages helps finding (python) files and packages to include,
    # provided __init__.py files are present in the directories.
    # cf. https://setuptools.readthedocs.io/en/latest/setuptools.html#using-find-packages
    packages=find_packages(),
    # External packages required by the project
    # Either use an explicit list, or rely on pipfile package