Fork of pathlib aiming to support the full stdlib Python API.

Overview

pathlib2

Jazzband github codecov

Fork of pathlib aiming to support the full stdlib Python API.

The old pathlib module on bitbucket is in bugfix-only mode. The goal of pathlib2 is to provide a backport of standard pathlib module which tracks the standard library module, so all the newest features of the standard pathlib can be used also on older Python versions.

Download

Standalone releases are available on PyPI: http://pypi.python.org/pypi/pathlib2/

Development

The main development takes place in the Python standard library: see the Python developer's guide. In particular, new features should be submitted to the Python bug tracker.

Issues that occur in this backport, but that do not occur not in the standard Python pathlib module can be submitted on the pathlib2 bug tracker.

Documentation

Refer to the standard pathlib documentation.

Known Issues

For historic reasons, pathlib2 still uses bytes to represent file paths internally. Unfortunately, on Windows with Python 2.7, the file system encoder (mcbs) has only poor support for non-ascii characters, and can silently replace non-ascii characters without warning. For example, u'тест'.encode(sys.getfilesystemencoding()) results in ???? which is obviously completely useless.

Therefore, on Windows with Python 2.7, until this problem is fixed upstream, unfortunately you cannot rely on pathlib2 to support the full unicode range for filenames. See issue #56 for more details.

Comments
  • Release 2.3.7 has fragile six dependency

    Release 2.3.7 has fragile six dependency

    The new 2.3.7 release depends on six.moves.collections_abc, which was introduced in six 1.13.0, but setup.py does not specify that that the six dependency must be >=1.13.0. This can result in failures if projects depend on pathlib2 without manually specifying a newer six version themselves.

    opened by ThrawnCA 36
  • Unusable on Windows/Python2.7 with unicode paths

    Unusable on Windows/Python2.7 with unicode paths

    The issue is that sys.getfilesystemencoding() == "mcbs" on Windows/Python 2.7, which is lossy. So one looses info when passes path as unicode to Path.

    opened by Suor 12
  • UnicodeEncodeError in Path() for a path with non-ASCII characters

    UnicodeEncodeError in Path() for a path with non-ASCII characters

    >>> pathlib2.Path(u'/c/Documents and Settings/User/\u041c\u043e\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b/.ipython/profile_default/db')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.7/site-packages/pathlib2.py", line 1095, in __new__
        self = cls._from_parts(args, init=False)
      File "/usr/lib/python2.7/site-packages/pathlib2.py", line 760, in _from_parts
        drv, root, parts = self._parse_args(args)
      File "/usr/lib/python2.7/site-packages/pathlib2.py", line 748, in _parse_args
        parts.append(str(a))
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 31-33: ordinal not in range(128)
    

    As you may have guessed, this appears when starting ipython in Cygwin if Cygwin's home dir is a junction to the Windows one.

    Since str is Unicode in Python 3, I believe the error is specific to the backport.

    opened by native-api 8
  • use “pathlib” as module name

    use “pathlib” as module name

    i want to use

    from pathlib import Path
    Path('foo').mkdir(exist_ok=True)
    

    instead of

    try:
        from pathlib import Path
    except ImportError:
        from pathlib2 import Path
    Path('foo').mkdir(exist_ok=True)
    

    this should be no problem since the stdlib pathlib should be backwards compatible.

    in order to make the change backwards compatible, you could make setup.py create both pathlib.py and a symlink named pathlib2.py

    opened by flying-sheep 7
  • fix for Python Numpy 1.10 fromfile()

    fix for Python Numpy 1.10 fromfile()

    numpy.fromfile() is a critically important function for loading raw binary data in a very fast manner.

    Python 2.x with Numpy 1.10 requires NOT to have io.BufferedReader. This patch makes pathlib2 return a traditional file handle for the .open() method on Python 2.x.

    Astropy had to do this too, see lines 387-414 of https://github.com/astropy/astropy/blob/master/astropy/io/fits/util.py

    This is not a problem for Python 3.4-3.5 with Numpy 1.10, so I left as is.

    After future testing I realize this causes an issue with encoding/writing files. Perhaps you have more experience in this area, I didn't want to layer on hacks.

    Perhaps for now I will just put in my own user code a if PY2: then open() etc. instead of messing with pathlib2, as Python<3.4 is an edge case for me.

    opened by drhirsch 7
  • need py3.5 pathlib .expanduser method

    need py3.5 pathlib .expanduser method

    In Python 3.5.0:

      from pathlib import Path
      f = Path('~')
      f.expanduser()
    

    gives the home directory full path.

    In Python 3.4.3 with pathlib2 2.0.1:

      from pathlib2 import Path
      f = Path('~')
      f.expanduser()
    

    gives AttributeError: 'PosixPath' object has no attribute 'expanduser'

    opened by drhirsch 7
  • os.compat (clbarnes remix)

    os.compat (clbarnes remix)

    WIP

    • Drop support for python versions which are EOL (i.e. 2.6 and 3.<4)
    • Use tox to control testing
    • Switch from the unicode compile script to just copying the test file with from __future__ import unicode_literals at the top
    • Include a Makefile which controls the above and the testing
    • context.py still exists but doesn't do the path mangling: make test ensures that pathlib2 is installed (in develop/ editable mode)
    opened by clbarnes 6
  • `os.path.join` compatibility

    `os.path.join` compatibility

    In python 3, os.path.join(pathlib.Path('my/path'), 'my.file') returns a string, my/path/my.file.

    However, os.path.join(pathlib2.Path('my/path'), 'my.file') raises an AttributeError:

         68         if b.startswith('/'):
         69             path = b
    ---> 70         elif path == '' or path.endswith('/'):
         71             path +=  b
         72         else:
    
    AttributeError: 'PosixPath' object has no attribute 'endswith'
    

    This is an issue for someone trying to gradually port a large codebase over to using Paths

    While strictly speaking, this may be due to py2's implementation of os.path.join rather than pathlib2's implementation of PurePath, it may be useful to reverse engineer compatibility for such a common path operation.

    Usually, this would require implementing startswith, endswith, and __iadd__ on PurePath. However, giving pathlib2.PurePath a significant amount of behaviour not seen in the 'real' PurePath doesn't seem like a good idea. Is there another way round it? Is it possible for importing pathlib2 to insert a shim into os.path?

    opened by clbarnes 6
  • Prepare release 2.3.7

    Prepare release 2.3.7

    @graingert Anything else needed that you can think of? Can you think of any good upstream projects or high profile users which need this package that might be interested to help testing this?

    opened by mcmtroffaes 5
  • Refactoring functions and Fix Code Expression

    Refactoring functions and Fix Code Expression

    Hello @mcmtroffaes 👋🏻 I just refactor some functions in the code itself and edit the test relate to testing the pathlib.

    • Replace range(0, x) with range(x).
    • Replace unneeded comprehension with generator.
    opened by yezz123 5
  • getfilesystemencoding can be None, causing error

    getfilesystemencoding can be None, causing error

    In Python before 3.2, it's possible to get None from this. However AWS Codebuild is setting things up, this causes pathlib2 to explode:

    ...
      File "/codebuild/output/src991325250/src/github.com/.../ve-web/local/lib/python2.7/site-packages/pathlib2/__init__.py", line 928, in _make_child 
        drv, root, parts = self._parse_args(args) 
      File "/codebuild/output/src991325250/src/github.com/.../ve-web/local/lib/python2.7/site-packages/pathlib2/__init__.py", line 885, in _parse_args 
        parts.append(a.encode(sys.getfilesystemencoding())) 
    TypeError: encode() argument 1 must be string, not None 
    
    opened by wryun 5
  • maintainership & project lead

    maintainership & project lead

    Follow up from #66.

    The main activity for pathlib2 is to backport any updates from cpython into this repository, typically a few times a year, with the main development of pathlib happening in upstream cpython. As stated, in the long term, I really would like to stand down as lead maintainer. I'm happy to keep helping along in the background e.g. reviewing PRs and submitting trivial patches if need be.

    Is someone interested (e.g. someone who uses pathlib2 in their work) to take on the lead responsibility for this package?

    opened by mcmtroffaes 4
  • Implement Jazzband guidelines for pathlib2

    Implement Jazzband guidelines for pathlib2

    This issue tracks the implementation of the Jazzband guidelines for the project pathlib2

    It was initiated by @mcmtroffaes who was automatically assigned in addition to the Jazzband roadies.

    See the TODO list below for the generally required tasks, but feel free to update it in case the project requires it.

    Feel free to ping a Jazzband roadie if you have any question.

    TODOs

    • [x] Fix all links in the docs (and README file etc) from old to new repo
    • [x] Add the Jazzband badge to the README file
    • [x] Add the Jazzband contributing guideline to the CONTRIBUTING.md or CONTRIBUTING.rst file
    • [x] Check if continuous testing works with GitHub Actions
    • [x] Check if test coverage is tracked with Codecov
    • [x] Add jazzband account to PyPI project as maintainer role (e.g. URL: https://pypi.org/manage/project/pathlib2/collaboration/)
    • [x] Add jazzband-bot as maintainer to the Read the Docs project (e.g. URL: https://readthedocs.org/dashboard/pathlib2/users/)
    • [x] Add incoming GitHub webhook integration to Read the Docs project (e.g. URL: https://readthedocs.org/dashboard/pathlib2/integrations/) https://github.com/jazzband/pathlib2/issues/72
    • [x] Fix project URL in GitHub project description
    • [x] Review project if other services are used and port them to Jazzband
    • [ ] Decide who is project lead for the project (if at all) https://github.com/jazzband/pathlib2/issues/70
    • [x] https://github.com/jazzband/pathlib2/issues/68
    • [x] https://github.com/jazzband/pathlib2/pull/69

    Project details

    Description Backport of pathlib aiming to support the full stdlib Python API. As of January 1 2020, this repository will no longer receive any further feature updates, as Python 2 is no longer supported.
    Homepage
    Stargazers 64
    Open issues 0
    Forks 18
    Default branch develop
    Is a fork False
    Has Wiki False
    Has Pages False
    opened by jazzband-bot 10
Owner
Jazzband
We are all part of this
Jazzband
CBLang is a programming language aiming to fix most of my problems with Python

CBLang A bad programming language made in Python. CBLang is a programming language aiming to fix most of my problems with Python (this means that you

Chadderbox 43 Dec 22, 2022
A redesign of our previous Python World Cup, aiming to simulate the 2022 World Cup all the way from the qualifiers

A redesign of our previous Python World Cup, aiming to simulate the 2022 World Cup all the way from the qualifiers. This new version is designed to be more compact and more efficient and will reflect the improvements in our programming ability.

Sam Counsell 1 Jan 7, 2022
YunoHost is an operating system aiming to simplify as much as possible the administration of a server.

YunoHost is an operating system aiming to simplify as much as possible the administration of a server. This repository corresponds to the core code, written mostly in Python and Bash.

YunoHost 1.5k Jan 9, 2023
This is a library which aiming to save all my code about cpp. It will help me to code conveniently.

This is a library which aiming to save all my code about cpp. It will help me to code conveniently.

Paul Leo 21 Dec 6, 2021
A collection of existing KGQA datasets in the form of the huggingface datasets library, aiming to provide an easy-to-use access to them.

KGQA Datasets Brief Introduction This repository is a collection of existing KGQA datasets in the form of the huggingface datasets library, aiming to

Semantic Systems research group 21 Jan 6, 2023
chiarose(XCR) based on chia(XCH) source code fork, open source public chain

chia-rosechain 一个无耻的小活动 | A shameless little event 如果您喜欢这个项目,请点击star 将赠送您520朵玫瑰,可以去 facebook 留下您的(xcr)地址,和github用户名。 If you like this project, please

ddou123 376 Dec 14, 2022
This is the community maintained fork of ungleich's cdist (after f061fb1).

cdist This is the community maintained fork of ungleich's cdist (after f061fb1). Work is split between three repositories: cdist - implementation of t

cdist community edition 0 Aug 2, 2022
This is a fork of the BakeTool with some improvements that I did to have better workflow.

blender-bake-tool This is a fork of the BakeTool with some improvements that I did to have better workflow. 99.99% of work was done by BakeTool team.

Acvarium 3 Oct 4, 2022
A full-featured, hackable tiling window manager written and configured in Python

A full-featured, hackable tiling window manager written and configured in Python Features Simple, small and extensible. It's easy to write your own la

Qtile 3.8k Dec 31, 2022
PDX Code Guild Full Stack Python Bootcamp starting 2022/02/28

Class Liger Rough Timeline Weeks 1, 2, 3, 4: Python Weeks 5, 6, 7, 8: HTML/CSS/Flask Weeks 9, 10, 11: Javascript Weeks 12, 13, 14, 15: Django Weeks 16

PDX Code Guild 5 Jul 5, 2022
A collection of full-stack resources for programmers.

A collection of full-stack resources for programmers.

Charles-Axel Dein 22.3k Dec 30, 2022
Cloud Native sample microservices showcasing Full Stack Observability using AppDynamics and ThousandEyes

Cloud Native Sample Bookinfo App Observability Bookinfo is a sample application composed of four Microservices written in different languages.

Cisco DevNet 13 Jul 21, 2022
Waydroid is a container-based approach to boot a full Android system on a regular GNU/Linux system like Ubuntu.

Waydroid is a container-based approach to boot a full Android system on a regular GNU/Linux system like Ubuntu.

WayDroid 4.7k Jan 8, 2023
4Geeks Academy Full-Stack Developer program final project.

Final Project Chavi, Clara y Pablo 4Geeks Academy Full-Stack Developer program final project. Authors Javier Manteca - Coding - chavisam Clara Rojano

null 1 Feb 5, 2022
Chemical Analysis Calculator, with full solution display.

Chemicology Chemical Analysis Calculator, to solve problems efficiently by displaying whole solution. Go to releases for downloading .exe, .dmg, Linux

Muhammad Moazzam 2 Aug 6, 2022
Cylinder volume calculator features the calculations of the volume of a Right /oblique full cylinder

Cylinder-Volume-Calculator Cylinder volume calculator features the calculations of the volume of a Right /oblique full cylinder. Size : 10.5 mb compat

Abhijeet 4 Nov 7, 2022
pgvector support for Python

pgvector-python pgvector support for Python Great for online recommendations ?? Supports Django, SQLAlchemy, Psycopg 2, Psycopg 3, and asyncpg Install

Andrew Kane 37 Dec 20, 2022
IOP Support for Python (Experimental)

TAGS Experimental IOP Framework for Python WARNING: Currently, this project has NO EXCEPTION HANDLING. USE AT YOUR OWN RISK! I. Introduction to Interf

null 1 Oct 22, 2021
Null safe support for Python

Null Safe Python Null safe support for Python. Installation pip install nullsafe Quick Start Dummy Class class Dummy: pass Normal Python code: o =

Paaksing 13 Nov 17, 2022